diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-28 16:27:35 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-28 16:27:35 +0000 |
commit | e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95 (patch) | |
tree | 358bb6b80ed5b15760889b6be199bdbcc5b2d2e8 /app/src/main | |
parent | 776f0aa01f7387a6d7a03fb9d965af969800799f (diff) | |
download | infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar.gz infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar.bz2 infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar.lz infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar.xz infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.tar.zst infinity-for-reddit-e0cbdcbcc0bfd48e9e1ae70193cb37e2143dbf95.zip |
Refresh CommentsListingRecyclerViewAdapter after network changes. Fix wrong post opens after on click performed on ImageAndGifBlock.
Diffstat (limited to 'app/src/main')
2 files changed, 19 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 5e52b063..df672f19 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -563,7 +563,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } if (canStartActivity) { canStartActivity = false; - itemView.callOnClick(); + itemView.performClick(); } }); commentMarkdownView.setAdapter(markwonAdapter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index b41b2908..2c5090c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -433,7 +433,25 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) { mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR); + refreshAdapter(mCommentRecyclerView, mAdapter); } } } + + private void refreshAdapter(RecyclerView recyclerView, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) { + int previousPosition = -1; + if (recyclerView.getLayoutManager() != null) { + previousPosition = ((LinearLayoutManagerBugFixed) recyclerView.getLayoutManager()).findFirstVisibleItemPosition(); + } + + RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); + recyclerView.setAdapter(null); + recyclerView.setLayoutManager(null); + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(layoutManager); + + if (previousPosition > 0) { + recyclerView.scrollToPosition(previousPosition); + } + } } |