aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/mygram/droid/Api.java
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-22 17:52:23 +0200
committerDanilo M. <danix@danix.xyz>2026-10-22 17:52:23 +0200
commitb35ce9ed6eb66cef1578bf141cd382f17a541566 (patch)
treea5c539a13f587ecbe55ead4a74d8100745366279 /app/src/main/java/mygram/droid/Api.java
parent9fba091bb394e8e4c7e8ccd0702081bd1a939047 (diff)
downloadmygram-droid-b35ce9ed6eb66cef1578bf141cd382f17a541566.tar.gz
mygram-droid-b35ce9ed6eb66cef1578bf141cd382f17a541566.zip
Folder grid order toggle: random, by date, by nameHEADmaster
A button at the top right of the folder header cycles the grid order and reloads it; the choice is saved for every folder. Foldergram has no per-request sort, so "by date" is the server's order (the instance's default folder order) and "by name" fetches every page and sorts by file name on the device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'app/src/main/java/mygram/droid/Api.java')
-rw-r--r--app/src/main/java/mygram/droid/Api.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/app/src/main/java/mygram/droid/Api.java b/app/src/main/java/mygram/droid/Api.java
index c7d08eb..6e4ce74 100644
--- a/app/src/main/java/mygram/droid/Api.java
+++ b/app/src/main/java/mygram/droid/Api.java
@@ -172,25 +172,36 @@ final class Api {
return out;
}
- /** Pager over a folder: each call returns the next page, shuffled; empty once all pages are used. */
- // ponytail: random page order plus in-page shuffle, not a full shuffle; neighbours within a page stay together; upgrade: fetch all ids once if that ever matters.
+ /** Folder orders: RANDOM shuffles, DATE keeps the server's order, NAME sorts by file name. */
+ static final int RANDOM = 0, DATE = 1, NAME = 2;
+
static Callable<List<Post>> folderPages(String slug, int count) {
+ return folderPages(slug, count, RANDOM);
+ }
+
+ /** Pager over a folder: each call returns the next page; empty once all pages are used. */
+ // ponytail: random page order plus in-page shuffle, not a full shuffle; neighbours within a page stay together; upgrade: fetch all ids once if that ever matters.
+ // ponytail: NAME fetches every page in its first call, since the server cannot sort by name; slow on folders of thousands.
+ // DATE is the server's order: newest first unless the instance's default folder order says oldest.
+ static Callable<List<Post>> folderPages(String slug, int count, int order) {
List<Integer> pages = new ArrayList<>();
for (int p = 1; p <= (count + PAGE - 1) / PAGE; p++)
pages.add(p);
- Collections.shuffle(pages);
+ if (order == RANDOM)
+ Collections.shuffle(pages);
String path = "/folders/" + Uri.encode(slug) + "/images?limit=" + PAGE + "&page=";
int[] next = {0};
return () -> {
synchronized (next) {
- while (next[0] < pages.size()) { // imageCount counts carousel slides, so later pages may be empty
- List<Post> posts = Post.list(call("GET", path + pages.get(next[0]++)), Prefs.server());
- if (!posts.isEmpty()) {
- Collections.shuffle(posts);
- return posts;
- }
- }
- return new ArrayList<>();
+ List<Post> out = new ArrayList<>();
+ // imageCount counts carousel slides, so later pages may be empty
+ while (next[0] < pages.size() && (order == NAME || out.isEmpty()))
+ out.addAll(Post.list(call("GET", path + pages.get(next[0]++)), Prefs.server()));
+ if (order == RANDOM)
+ Collections.shuffle(out);
+ else if (order == NAME)
+ out.sort((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(a.filename, b.filename));
+ return out;
}
};
}