From eb45b59cacfd25f2709417369bdf572d207abc9b Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 29 Oct 2024 05:48:48 +0300 Subject: [PATCH] Fix gap loading for real this time --- .../fragments/HomeTimelineFragment.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) 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 aab0f096..ab981e64 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -33,10 +33,12 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import android.widget.Toolbar; import com.squareup.otto.Subscribe; +import org.joinmastodon.android.BuildConfig; import org.joinmastodon.android.E; import org.joinmastodon.android.R; import org.joinmastodon.android.api.MastodonAPIRequest; @@ -350,6 +352,10 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD state=updater.getState(); if(state!=GithubSelfUpdater.UpdateState.NO_UPDATE && state!=GithubSelfUpdater.UpdateState.CHECKING) getToolbar().getMenu().findItem(R.id.settings).setIcon(R.drawable.ic_settings_updateready_24px); + + if("debug".equals(BuildConfig.BUILD_TYPE)){ + menu.add(0, 1, 0, "Make a gap"); + } } @Override @@ -362,6 +368,17 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD }else if(id==R.id.edit_list){ args.putParcelable("list", Parcels.wrap(currentList)); Nav.go(getActivity(), EditListFragment.class, args); + }else if(id==1){ + if(data.size()<35){ + Toast.makeText(getActivity(), "Too few posts. Load at least 35", Toast.LENGTH_SHORT).show(); + return true; + } + Status gapStatus=data.get(1); + gapStatus.hasGapAfter=true; + onStatusUpdated(gapStatus); + for(Status s:new ArrayList<>(data.subList(2, 32))){ + removeStatus(s); + } } return true; } @@ -472,16 +489,16 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD dataLoading=true; boolean needCache=listMode==ListMode.FOLLOWING; boolean insertBelowGap=!gap.enteredFromTop; - String maxID, sinceID; + String maxID, minID; if(gap.enteredFromTop){ - maxID=item.getItemID(); - sinceID=null; - }else{ maxID=null; int gapPos=displayItems.indexOf(gap); - sinceID=displayItems.get(gapPos+1).parentID; + minID=displayItems.get(gapPos+1).parentID; + }else{ + maxID=item.getItemID(); + minID=null; } - loadAdditionalPosts(maxID, null, 20, sinceID, new Callback<>(){ + loadAdditionalPosts(maxID, minID, 20, null, new Callback<>(){ @Override public void onSuccess(List result){ @@ -582,6 +599,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD targetList.addAll(0, buildDisplayItems(s)); insertedPosts.add(0, s); } + int addedItemCount=targetList.size(); boolean gapRemoved=false; if(insertedPosts.size()