From fe192131d835e909ae2c2604f97ade479b934e71 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 15 May 2021 14:16:20 +0800 Subject: [PATCH] Fix recyclerview not scroll to correct last place after changing orientation. --- .../infinityforreddit/fragments/PostFragment.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 19bfaeb5..a1edea83 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -374,12 +374,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); mSwipeRefreshLayout.setOnRefreshListener(this::refresh); + int recyclerViewPosition = 0; int hideReadPostsIndex = 0; if (savedInstanceState != null) { - int recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE); - if (recyclerViewPosition > 0) { - mPostRecyclerView.scrollToPosition(recyclerViewPosition); - } + recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE); isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE); readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE); @@ -855,6 +853,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { windowWidth /= 2; } + if (recyclerViewPosition > 0) { + mPostRecyclerView.scrollToPosition(recyclerViewPosition); + } + mAdapter.setHideReadPostsIndex(hideReadPostsIndex); if (activity instanceof ActivityToolbarInterface) {