aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/mygram/droid/ViewerActivity.java
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-22 11:39:34 +0200
committerDanilo M. <danix@danix.xyz>2026-10-22 11:39:34 +0200
commit1ffa52946d8de76806b0b467ccd60f4b2fe57683 (patch)
tree52892e10f178225edd51bdd3b5c174c7e3de2513 /app/src/main/java/mygram/droid/ViewerActivity.java
parent40b12e5b4cd6a4352e37cd1b6e85b1da10624436 (diff)
downloadmygram-droid-1ffa52946d8de76806b0b467ccd60f4b2fe57683.tar.gz
mygram-droid-1ffa52946d8de76806b0b467ccd60f4b2fe57683.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'app/src/main/java/mygram/droid/ViewerActivity.java')
-rw-r--r--app/src/main/java/mygram/droid/ViewerActivity.java22
1 files changed, 10 insertions, 12 deletions
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<Post> 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();
});