Crash fix

This commit is contained in:
Grishka 2022-02-18 00:16:06 +03:00
parent 8b8dc4fbf9
commit 371faf9bb2
3 changed files with 11 additions and 5 deletions

View File

@ -99,7 +99,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
displayItems.clear();
}
protected void prependItems(List<T> items){
protected void prependItems(List<T> items, boolean notify){
data.addAll(0, items);
int offset=0;
for(T s:items){
@ -110,6 +110,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
displayItems.addAll(offset, toAdd);
offset+=toAdd.size();
}
if(notify)
adapter.notifyItemRangeInserted(0, offset);
}

View File

@ -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){

View File

@ -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);
}
})