blob: bbe2d51b3e91901d78b8647ad222e54ee6950d73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}
}
|