diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-23 04:30:13 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-23 04:30:13 +0000 |
commit | c88ceb737be67e0240f5eff51a5570a038bd27c7 (patch) | |
tree | a2a83dc312fe4cade0620c7337fad2ab86e98606 /app/src/main/java | |
parent | 6747efbccb05e48f4d7759c923755287fedabbf3 (diff) | |
download | infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar.gz infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar.bz2 infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar.lz infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar.xz infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.tar.zst infinity-for-reddit-c88ceb737be67e0240f5eff51a5570a038bd27c7.zip |
Save PostFilter during Fragment recreation in PostFragment.
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java | 21 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java | 4 |
2 files changed, 11 insertions, 14 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 4418cc43..96b04e23 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -138,6 +138,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private static final String READ_POST_LIST_STATE = "RPLS"; private static final String SUBREDDIT_FILTER_LIST_STATE = "SFLS"; private static final String HIDE_READ_POSTS_INDEX_STATE = "HRPIS"; + private static final String POST_FILTER_STATE = "PFS"; @BindView(R.id.swipe_refresh_layout_post_fragment) SwipeRefreshLayout mSwipeRefreshLayout; @@ -385,6 +386,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator { readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE); subredditFilterList = savedInstanceState.getParcelableArrayList(SUBREDDIT_FILTER_LIST_STATE); hideReadPostsIndex = savedInstanceState.getInt(HIDE_READ_POSTS_INDEX_STATE, 0); + postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE); + } else { + //TODO: Initialize PostFilter + postFilter = getArguments().getParcelable(EXTRA_FILTER); + if (postFilter == null) { + postFilter = new PostFilter(); + } } mPostRecyclerView.setOnTouchListener((view, motionEvent) -> { @@ -442,12 +450,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { postType = getArguments().getInt(EXTRA_POST_TYPE); - //TODO: Initialize PostFilter - postFilter = getArguments().getParcelable(EXTRA_FILTER); - if (postFilter == null) { - postFilter = new PostFilter(); - } - String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); @@ -1081,6 +1083,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { outState.putInt(RECYCLER_VIEW_POSITION_STATE, mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]); } + outState.putParcelable(POST_FILTER_STATE, postFilter); } @Override @@ -1252,6 +1255,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void changePostFilter(PostFilter postFilter) { + this.postFilter = postFilter; if (mPostViewModel != null) { mPostViewModel.changePostFilter(postFilter); } @@ -1259,10 +1263,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public PostFilter getPostFilter() { - if (mPostViewModel != null) { - return mPostViewModel.getPostFilter(); - } - return null; + return postFilter; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index 83ffcd43..716eabaf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -200,10 +200,6 @@ public class PostViewModel extends ViewModel { postFilterLiveData.postValue(postFilter); } - public PostFilter getPostFilter() { - return postFilterLiveData.getValue(); - } - public static class Factory extends ViewModelProvider.NewInstanceFactory { private Retrofit retrofit; private String accessToken; |