aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-21 12:05:10 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-21 12:05:10 +0000
commiteaa24b48580cfc3a95c2ab7b5195961eecc0ac76 (patch)
tree602f0f6bb6949009f5f6cea5515a5e1a5842ff4e /app/src/main/java
parentf2df7e94b15f9b9fcdb903689816eaafaa782c5a (diff)
downloadinfinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar.gz
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar.bz2
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar.lz
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar.xz
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.tar.zst
infinity-for-reddit-eaa24b48580cfc3a95c2ab7b5195961eecc0ac76.zip
Fix RecyclerView go to top after changing post type.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java12
1 files changed, 11 insertions, 1 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 223dcf2b..49ce844e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -1460,6 +1460,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
break;
}
+ int previousPosition = -1;
+ if (mLinearLayoutManager != null) {
+ previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ } else if (mStaggeredGridLayoutManager != null) {
+ int[] into = new int[mStaggeredGridLayoutManager.getSpanCount()];
+ previousPosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0];
+ }
int nColumns = getNColumns(getResources());
if (nColumns == 1) {
mLinearLayoutManager = new LinearLayoutManager(activity);
@@ -1480,6 +1487,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mLinearLayoutManager = null;
}
+ if (previousPosition > 0) {
+ mPostRecyclerView.scrollToPosition(previousPosition);
+ }
+
if (mAdapter != null) {
mAdapter.setPostLayout(postLayout);
refreshAdapter();
@@ -1925,7 +1936,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostRecyclerView.setLayoutManager(null);
mPostRecyclerView.setAdapter(mAdapter);
mPostRecyclerView.setLayoutManager(layoutManager);
-
if (previousPosition > 0) {
mPostRecyclerView.scrollToPosition(previousPosition);
}