v0.2.0: bubble for Android 0.2.0 — chat search, swipe for unread, faster chat opening
Desktop: - Search lists chats whose own name matches first, so a named group isn't pushed out of the top 8 by chats that merely include a member. Android (Rabbit R1) app, 0.2.0: - Pull the chat list past its top for a search box (name, person, number, then group members; archived chats too; Back clears it). - Swipe right to left marks a chat unread / read over a magenta band; left to right still archives (SwipeActions replaces SwipeArchive). - Google Voice chats don't offer voice notes in the paperclip bubble. - Chats open with their newest 60 messages, then the full history; marking read (and the Google Voice network call) waits until they're on screen. Cached pictures show at once, and one slow download no longer blocks the other images. Fixed a contacts reload race. - Sandbox data gains filler chats, a named group and a 4,000-message chat. Also: the Android app, Google Voice support, media, export, emoji and the other work since the first commit, and a CLAUDE.md carrying the privacy rule.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package me.teafry.voipmessages;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
/**
|
||||
* Chat names and read/unread/archived state, kept in step with the desktop.
|
||||
* Changes here are written to files/state.json; the desktop's "Sync to
|
||||
* Rabbit" reads that, merges it with its own (newest change wins), and leaves
|
||||
* the result in files/state-in.json, applied here on the next start or check.
|
||||
*/
|
||||
final class StateSync {
|
||||
private StateSync() {}
|
||||
|
||||
/** Write files/state.json; call after any rename or read/unread/archive change. */
|
||||
static void export(Context c) {
|
||||
try {
|
||||
Store store = Store.get(c);
|
||||
JSONObject state = new JSONObject().put("names", store.namesExport()).put("read", store.readStateExport());
|
||||
File tmp = new File(c.getFilesDir(), "state.json.tmp");
|
||||
try (FileOutputStream out = new FileOutputStream(tmp)) {
|
||||
out.write(state.toString().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
tmp.renameTo(new File(c.getFilesDir(), "state.json"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
static void importPending(Context c) {
|
||||
File in = new File(c.getFilesDir(), "state-in.json");
|
||||
if (!in.exists()) return;
|
||||
try {
|
||||
JSONObject state = new JSONObject(new String(Files.readAllBytes(in.toPath()), StandardCharsets.UTF_8));
|
||||
Store store = Store.get(c);
|
||||
JSONArray names = state.optJSONArray("names");
|
||||
JSONArray read = state.optJSONArray("read");
|
||||
if (names != null) store.namesImport(names);
|
||||
if (read != null) store.readStateImport(read);
|
||||
in.delete();
|
||||
export(c);
|
||||
Notifier.sweep(c);
|
||||
Sync.changed();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
static void rename(Context c, String did, String contact, String name) {
|
||||
Store.get(c).setName(did, contact, name, System.currentTimeMillis());
|
||||
export(c);
|
||||
Sync.changed();
|
||||
}
|
||||
|
||||
static void markRead(Context c, String did, String contact) {
|
||||
Store.get(c).markRead(did, contact);
|
||||
export(c);
|
||||
Notifier.sweep(c);
|
||||
}
|
||||
|
||||
static void markUnread(Context c, String did, String contact) {
|
||||
Store.get(c).markUnread(did, contact);
|
||||
export(c);
|
||||
}
|
||||
|
||||
static void setArchived(Context c, String did, String contact, boolean archived) {
|
||||
Store.get(c).setArchived(did, contact, archived);
|
||||
export(c);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user