diff options
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java | 12 |
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); } |