aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
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
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')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java12
-rw-r--r--app/src/main/res/layout/item_post_detail_gallery.xml1
2 files changed, 12 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);
}
diff --git a/app/src/main/res/layout/item_post_detail_gallery.xml b/app/src/main/res/layout/item_post_detail_gallery.xml
index 7944c5c8..712a7725 100644
--- a/app/src/main/res/layout/item_post_detail_gallery.xml
+++ b/app/src/main/res/layout/item_post_detail_gallery.xml
@@ -224,6 +224,7 @@
android:layout_height="36dp"
android:layout_margin="16dp"
android:layout_gravity="start"
+ android:scaleType="center"
android:background="@drawable/play_button_round_background"
android:src="@drawable/ic_gallery_reverse_color_24dp" />