Fix recyclerview not scroll to correct last place after changing orientation.

This commit is contained in:
Alex Ning 2021-05-15 14:16:20 +08:00
parent bb36cc79fd
commit fe192131d8

View File

@ -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) {