diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-22 11:11:41 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-22 11:11:41 +0200 |
| commit | c222cb8e784d65f17ac29433fe51cd4c56e1b261 (patch) | |
| tree | 3bb8e0133dc6757bed1a42f65a0110a67592f9c4 /app/src/main/java/mygram/droid/Likes.java | |
| parent | 324b600f5795735c74eae81a27beb4953f40653e (diff) | |
| download | mygram-droid-c222cb8e784d65f17ac29433fe51cd4c56e1b261.tar.gz mygram-droid-c222cb8e784d65f17ac29433fe51cd4c56e1b261.zip | |
Add Foldergram API client, likes set and playlist hand-off
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'app/src/main/java/mygram/droid/Likes.java')
| -rw-r--r-- | app/src/main/java/mygram/droid/Likes.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/src/main/java/mygram/droid/Likes.java b/app/src/main/java/mygram/droid/Likes.java new file mode 100644 index 0000000..bbe2d51 --- /dev/null +++ b/app/src/main/java/mygram/droid/Likes.java @@ -0,0 +1,48 @@ +/* + * mygram-droid: Android TV client for Foldergram. + * Copyright (C) 2026 Danilo M. <danix@danix.xyz> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package mygram.droid; + +import org.json.JSONException; + +import java.io.IOException; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** Liked post IDs. Feed items carry no liked flag, so this set drives every heart. */ +final class Likes { + private static final Set<Integer> ids = ConcurrentHashMap.newKeySet(); + + private Likes() { + } + + static void load() throws IOException, JSONException { + Set<Integer> fresh = ConcurrentHashMap.newKeySet(); + for (Post p : Api.likes()) + fresh.add(p.id); + ids.retainAll(fresh); + ids.addAll(fresh); + } + + static boolean has(int postId) { + return ids.contains(postId); + } + + static void set(int postId, boolean liked) { + if (liked) + ids.add(postId); + else + ids.remove(postId); + } +} |
