Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Nov 23, 2019
1 parent b9ebfc1 commit 348bbe1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import android.widget.SectionIndexer;
import java.util.List;

/**
Expand Down Expand Up @@ -54,8 +52,8 @@ public ExpandableStickyListHeadersAdapter getAdapter() {

@Override
public void setAdapter(StickyListHeadersAdapter adapter) {
mExpandableStickyListHeadersAdapter = (adapter instanceof SectionIndexer) ?
new SectionIndexingExpandableStickyListHeadersAdapter(adapter) :
mExpandableStickyListHeadersAdapter = (adapter instanceof SectionIndexingStickyListHeadersAdapter) ?
new SectionIndexingExpandableStickyListHeadersAdapter(((SectionIndexingStickyListHeadersAdapter) adapter)) :
new ExpandableStickyListHeadersAdapter(adapter);
super.setAdapter(mExpandableStickyListHeadersAdapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@

public class SectionIndexingExpandableStickyListHeadersAdapter extends ExpandableStickyListHeadersAdapter implements SectionIndexer {

SectionIndexingExpandableStickyListHeadersAdapter(StickyListHeadersAdapter innerAdapter) {
SectionIndexingExpandableStickyListHeadersAdapter(SectionIndexingStickyListHeadersAdapter innerAdapter) {
super(innerAdapter);
if (!(innerAdapter instanceof SectionIndexer)) throw new IllegalArgumentException("Wrapped adapter must implement SectionIndexer");
}

@Override
public Object[] getSections() {
return ((SectionIndexer) mInnerAdapter).getSections();
return getAdapter().getSections();
}

@Override
public int getPositionForSection(int sectionIndex) {
return ((SectionIndexer) mInnerAdapter).getPositionForSection(sectionIndex);
return getAdapter().getPositionForSection(sectionIndex);
}

@Override
public int getSectionForPosition(int position) {
return ((SectionIndexer) mInnerAdapter).getSectionForPosition(position);
return getAdapter().getSectionForPosition(position);
}

private SectionIndexingStickyListHeadersAdapter getAdapter() {
return ((SectionIndexingStickyListHeadersAdapter) mInnerAdapter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package se.emilsjolander.stickylistheaders;

import android.widget.SectionIndexer;

public interface SectionIndexingStickyListHeadersAdapter extends StickyListHeadersAdapter, SectionIndexer {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;

import java.util.ArrayList;
import se.emilsjolander.stickylistheaders.SectionIndexingStickyListHeadersAdapter;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

public class TestBaseAdapter extends BaseAdapter implements
StickyListHeadersAdapter, SectionIndexer {
public class TestBaseAdapter extends BaseAdapter implements SectionIndexingStickyListHeadersAdapter {

private final Context mContext;
private String[] mCountries;
Expand Down

0 comments on commit 348bbe1

Please sign in to comment.