Skip to content

Commit

Permalink
use suppport libraries saved state that works below API 24
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed May 24, 2020
1 parent 9292210 commit 65e620a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'

dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:customview:28.0.0'
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package se.emilsjolander.stickylistheaders;

import android.content.Context;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.RequiresApi;
import android.support.v4.view.AbsSavedState;
import android.util.AttributeSet;
import android.view.View;
import java.util.ArrayList;
Expand Down Expand Up @@ -149,7 +148,7 @@ public void onRestoreInstanceState(Parcelable state) {
}
}

static class SavedState extends BaseSavedState {
static class SavedState extends AbsSavedState {
private List<Long> collapsedHeaderIds;

/**
Expand All @@ -160,20 +159,11 @@ static class SavedState extends BaseSavedState {
this.collapsedHeaderIds = collapsedHeaderIds;
}

/**
* Constructor called from {@link #CREATOR}
*/
private SavedState(Parcel in) {
super(in);
readValues(in, null);
}

private void readValues(Parcel in, ClassLoader loader) {
collapsedHeaderIds = new ArrayList<>();
in.readList(collapsedHeaderIds, loader);
}

@RequiresApi(24)
SavedState(Parcel in, ClassLoader loader) {
super(in, loader);
readValues(in, loader);
Expand All @@ -188,9 +178,7 @@ public void writeToParcel(Parcel out, int flags) {
public static final Creator<SavedState> CREATOR = new ClassLoaderCreator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel source, ClassLoader loader) {
return Build.VERSION.SDK_INT >= 24
? new SavedState(source, loader)
: new SavedState(source);
return new SavedState(source, loader);
}

@Override
Expand Down

0 comments on commit 65e620a

Please sign in to comment.