From 1ffa52946d8de76806b0b467ccd60f4b2fe57683 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 22 Oct 2026 11:39:34 +0200 Subject: Lazy-load folder content in random page order A folder with several thousand posts took ~10 s to open because FolderActivity and the Home row OK handler fetched every page before showing anything. Pages are now fetched one at a time in a shuffled page order (each page shuffled locally), the grid shows after the first page, and the viewer shares the list and pager so it keeps paging the folder. Reels use the same generic pager. Not a full shuffle: neighbours within a page stay together. Co-Authored-By: Claude Opus 5.5 --- app/src/main/java/mygram/droid/ViewerActivity.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'app/src/main/java/mygram/droid/ViewerActivity.java') diff --git a/app/src/main/java/mygram/droid/ViewerActivity.java b/app/src/main/java/mygram/droid/ViewerActivity.java index 59e6948..4845cbd 100644 --- a/app/src/main/java/mygram/droid/ViewerActivity.java +++ b/app/src/main/java/mygram/droid/ViewerActivity.java @@ -131,7 +131,7 @@ public final class ViewerActivity extends Activity { if (!Playlist.posts.isEmpty()) { show(Playlist.start); - } else if (Playlist.reelsSeed != 0) { + } else if (Playlist.more != null) { message.setText("Loading…"); maybeLoadMore(); } else { @@ -330,35 +330,33 @@ public final class ViewerActivity extends Activity { }); } - /** Reels only: fetches the next page when three posts remain. */ + /** Fetches the next page when three posts remain. */ private void maybeLoadMore() { - if (Playlist.reelsSeed == 0 || loadingMore || index < Playlist.posts.size() - 3) + if (Playlist.more == null || loadingMore || index < Playlist.posts.size() - 3) return; loadingMore = true; - int page = Playlist.reelsPage + 1; List list = Playlist.posts; - Api.async(() -> Api.reels(Playlist.reelsSeed, page), o -> { + Api.async(Playlist.more, page -> { if (isDestroyed() || Playlist.posts != list) return; loadingMore = false; - Playlist.reelsPage = page; boolean first = list.isEmpty(); int old = list.size(); - list.addAll(Post.list(o, Prefs.server())); - if (!o.optBoolean("hasMore")) - Playlist.reelsSeed = 0; + if (page.isEmpty()) + Playlist.more = null; + Playlist.append(page); if (first && !list.isEmpty()) show(0); else if (parkedAtEnd && index == old - 1 && list.size() > old) show(index + 1); - else if (list.isEmpty() && Playlist.reelsSeed == 0) - message.setText("No reels"); + else if (list.isEmpty() && Playlist.more == null) + message.setText("Nothing to show"); }, e -> { if (isDestroyed()) return; loadingMore = false; if (Playlist.posts.isEmpty()) - message.setText("Cannot load reels. Press Down to retry."); + message.setText("Cannot load posts. Press Down to retry."); else Toast.makeText(this, "Cannot load more: " + e.getMessage(), Toast.LENGTH_SHORT).show(); }); -- cgit v1.2.3