Skip to content

Commit

Permalink
allow to use section indexing together with expandable section headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Nov 23, 2019
1 parent 7ef4793 commit 7d5dd61
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 21 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:3.5.2'
}
}

Expand All @@ -16,6 +17,7 @@ allprojects {
group = GROUP

repositories {
google()
mavenCentral()
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
4 changes: 0 additions & 4 deletions library/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
android:versionCode="2"
android:versionName="2.0" >

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="22" />

</manifest>
5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion '25.0.3'

defaultConfig {
minSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class ExpandableStickyListHeadersAdapter extends BaseAdapter implements StickyListHeadersAdapter {

private final StickyListHeadersAdapter mInnerAdapter;
protected final StickyListHeadersAdapter mInnerAdapter;
DualHashMap<View,Long> mViewToItemIdMap = new DualHashMap<View, Long>();
DistinctMultiHashMap<Integer,View> mHeaderIdToViewMap = new DistinctMultiHashMap<Integer, View>();
List<Long> mCollapseHeaderIds = new ArrayList<Long>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.AttributeSet;
import android.view.View;

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

/**
Expand Down Expand Up @@ -53,7 +54,9 @@ public ExpandableStickyListHeadersAdapter getAdapter() {

@Override
public void setAdapter(StickyListHeadersAdapter adapter) {
mExpandableStickyListHeadersAdapter = new ExpandableStickyListHeadersAdapter(adapter);
mExpandableStickyListHeadersAdapter = (adapter instanceof SectionIndexer) ?
new SectionIndexingExpandableStickyListHeadersAdapter(adapter) :
new ExpandableStickyListHeadersAdapter(adapter);
super.setAdapter(mExpandableStickyListHeadersAdapter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package se.emilsjolander.stickylistheaders;

import android.widget.SectionIndexer;

public class SectionIndexingExpandableStickyListHeadersAdapter extends ExpandableStickyListHeadersAdapter implements SectionIndexer {

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

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

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

@Override
public int getSectionForPosition(int position) {
return ((SectionIndexer) mInnerAdapter).getSectionForPosition(position);
}
}
4 changes: 0 additions & 4 deletions sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
android:versionCode="2"
android:versionName="2.0">

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="22" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand Down
13 changes: 6 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ repositories {

dependencies {
compile project(':library')
compile 'com.android.support:appcompat-v7:22.0.+'
compile 'com.android.support:support-v4:22.0.+'
compile 'com.nineoldandroids:library:2.4.0+'
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.android.support:support-v4:28.0.0'
compile 'com.nineoldandroids:library:2.4.0'
}

android {
compileSdkVersion 22
buildToolsVersion '25.0.3'
compileSdkVersion 28

defaultConfig {
applicationId 'se.emilsjolander.stickylistheaders'
minSdkVersion 7
targetSdkVersion 22
minSdkVersion 14
targetSdkVersion 28
}

sourceSets {
Expand Down

0 comments on commit 7d5dd61

Please sign in to comment.