diff --git a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java index d2c6ae54b..ccc8a0d33 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java +++ b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java @@ -27,6 +27,7 @@ import java.util.List; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.exception.DBException; +import app.fedilab.android.helper.MastodonHelper; import app.fedilab.android.helper.SpannableHelper; import app.fedilab.android.sqlite.Sqlite; @@ -126,6 +127,7 @@ public class QuickLoad { quickLoad.slug = key; quickLoad.instance = MainActivity.currentInstance; quickLoad.user_id = MainActivity.currentUserID; + purge(quickLoad); try { insertOrUpdate(quickLoad); } catch (DBException e) { @@ -180,6 +182,21 @@ public class QuickLoad { return null; } + /** + * Purge the list to avoid long list of Statuses in db + * + * @param quickLoad - QuickLoad to purge + */ + private void purge(QuickLoad quickLoad) { + List statuses = quickLoad.statuses; + int position = quickLoad.position; + int limit = MastodonHelper.statusesPerCall(_mContext) + 10; + int startAt = Math.max(position - limit, 0); + int endAt = Math.min(position + limit, statuses.size()); + quickLoad.position = position - startAt; + quickLoad.statuses = statuses.subList(startAt, endAt); + } + /** * Update a QuickLoad in db * diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 429ad6ccc..58021a722 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -408,7 +408,7 @@ public class FragmentMastodonTimeline extends Fragment { new Thread(() -> { QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(timelineType, ident); - if (quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { + if (direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { Statuses statuses = new Statuses(); statuses.statuses = quickLoad.statuses; statuses.pagination = new Pagination();