From 371faf9bb219b31153a158ea40a93e78c54bbc0e Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 18 Feb 2022 00:16:06 +0300 Subject: [PATCH] Crash fix --- .../android/fragments/BaseStatusListFragment.java | 5 +++-- .../android/fragments/HomeTimelineFragment.java | 2 +- .../joinmastodon/android/fragments/ThreadFragment.java | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index f95ba5fa..5e3a12b4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -99,7 +99,7 @@ public abstract class BaseStatusListFragment exten displayItems.clear(); } - protected void prependItems(List items){ + protected void prependItems(List items, boolean notify){ data.addAll(0, items); int offset=0; for(T s:items){ @@ -110,7 +110,8 @@ public abstract class BaseStatusListFragment exten displayItems.addAll(offset, toAdd); offset+=toAdd.size(); } - adapter.notifyItemRangeInserted(0, offset); + if(notify) + adapter.notifyItemRangeInserted(0, offset); } protected String getMaxID(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 8ae782e2..76c87ce1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -90,7 +90,7 @@ public class HomeTimelineFragment extends StatusListFragment{ @Subscribe public void onStatusCreated(StatusCreatedEvent ev){ - prependItems(Collections.singletonList(ev.status)); + prependItems(Collections.singletonList(ev.status), true); } private void onFabClick(View v){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java index 8dc5ef0f..2e575e88 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -47,12 +47,17 @@ public class ThreadFragment extends StatusListFragment{ } footerProgress.setVisibility(View.GONE); data.addAll(result.descendants); + int prevCount=displayItems.size(); onAppendItems(result.descendants); int count=displayItems.size(); - prependItems(result.ancestors); + if(!refreshing) + adapter.notifyItemRangeInserted(prevCount, count-prevCount); + prependItems(result.ancestors, !refreshing); dataLoaded(); - if(refreshing) + if(refreshing){ refreshDone(); + adapter.notifyDataSetChanged(); + } list.scrollToPosition(displayItems.size()-count); } })