diff options
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); + } +} |
