Skip to content

Commit

Permalink
Fix a bug regarding restoring state on Lollipop APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mars885 committed Dec 8, 2019
1 parent 6d8aec8 commit ef21a76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.paulrybitskyi.persistentsearchview.utils.AnimationType;
import com.paulrybitskyi.persistentsearchview.utils.KeyboardManagingUtil;
import com.paulrybitskyi.persistentsearchview.utils.Preconditions;
import com.paulrybitskyi.persistentsearchview.utils.StateUtils;
import com.paulrybitskyi.persistentsearchview.utils.Utils;
import com.paulrybitskyi.persistentsearchview.utils.ViewUtils;
import com.paulrybitskyi.persistentsearchview.utils.VoiceRecognitionDelegate;
Expand Down Expand Up @@ -2835,9 +2836,9 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {

@Override
protected void onRestoreInstanceState(Parcelable state) {
final SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(StateUtils.fetchParentState(state));

super.onRestoreInstanceState(state);
final SavedState savedState = (SavedState) state;

// Restoring our state
setQueryInputHintColor(savedState.queryInputHintColor);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.paulrybitskyi.persistentsearchview.utils;

import android.os.Parcelable;
import android.view.View;

public class StateUtils {


public static Parcelable fetchParentState(Parcelable state) {
if(state == null) {
return null;
}

if(Utils.IS_AT_LEAST_MARSHMALLOW) {
return state;
} else {
return View.BaseSavedState.EMPTY_STATE;
}
}


}

0 comments on commit ef21a76

Please sign in to comment.