v0.7.0: bubble for Android 0.7.0 — react to messages, reactions in other languages, and edits

Android, ported from the desktop's reactions.ts / edits.ts (same readings:
checked side by side on the same 32 cases):
- Long-press a message: the quick reaction row (yours lit, tap again to take
  it back), + for every emoji (EmojiPicker, the desktop's emoji list as
  res/raw/emoji_list.txt, minus any the font can't draw), and Copy text.
- Settings → Reactions → Quick reactions: pick a spot, then its emoji; Reset.
- Tapbacks in other languages fold like the desktop's; "Edited to “…”" edits
  its message, which says "Edited · time"; tap it for the earlier texts.
- Chat list and notifications preview an edit as "✏️ new text".
- push_sandbox.py has a Spanish tapback and an edit to try it on.

Desktop: version 0.7.0; gen-emoji also writes the Android list.
This commit is contained in:
2026-11-10 17:38:09 -08:00
parent fcabae81e5
commit 09a46aa35c
16 changed files with 2421 additions and 43 deletions
@@ -56,6 +56,7 @@ public final class ChatActivity extends BaseActivity {
private final List<Object> rows = new ArrayList<>(); // Long day-start or Store.Msg
private final List<Sender.Photo> photos = new ArrayList<>();
private java.util.Map<Long, List<Reactions.Reaction>> reactions = new java.util.HashMap<>();
private java.util.Map<Long, List<Edits.Version>> versions = new java.util.HashMap<>();
private Adapter adapter;
private boolean firstLoad = true;
/** How many messages to show first when a chat opens (a few screens' worth). */
@@ -278,12 +279,15 @@ public final class ChatActivity extends BaseActivity {
});
}
/** Off the main thread: fold the tapbacks, then show. */
/** Off the main thread: fold the edits and tapbacks, then show. */
private void post(List<Store.Msg> msgs, String name, boolean complete) {
// iPhone tapbacks ("Loved “…”") become reactions on the message they quote.
java.util.Map<Long, List<Reactions.Reaction>> folded = Reactions.fold(msgs);
// "Edited to “…”" edits the message it's about; iPhone tapbacks
// ("Loved “…”") become reactions on the message they quote.
java.util.Map<Long, List<Edits.Version>> edited = Edits.fold(msgs);
java.util.Map<Long, List<Reactions.Reaction>> folded = Reactions.fold(msgs, Edits.earlier(edited));
runOnUiThread(() -> {
reactions = folded;
versions = edited;
show(msgs, name, complete);
});
}
@@ -670,18 +674,19 @@ public final class ChatActivity extends BaseActivity {
rlp.rightMargin = Ui.dp(c, 16);
addView(reacts, rlp);
addView(failed);
// Long-press copies the text. The body has its own listener because
// autolinked text takes its own touches and the bubble never sees them.
View.OnLongClickListener copy = v -> {
// Long-press: react or copy, like Signal. The body has its own listener
// because autolinked text takes its own touches and the bubble never sees them.
View.OnLongClickListener hold = v -> {
if (m == null) return true;
if (!m.body.isEmpty()) copyText(m.body);
else if ("failed".equals(m.status)) failedMenu(m);
if ("failed".equals(m.status)) failedMenu(m);
else messageMenu(m);
return true;
};
bubble.setOnLongClickListener(copy);
body.setOnLongClickListener(copy);
bubble.setOnLongClickListener(hold);
body.setOnLongClickListener(hold);
bubble.setOnClickListener(v -> {
if (m != null && "failed".equals(m.status)) failedMenu(m);
else if (m != null && versions.containsKey(m.id)) showEdits(m);
});
}
@@ -700,7 +705,8 @@ public final class ChatActivity extends BaseActivity {
if (showSender) sender.setText(Contacts.name(c, msg.sender));
body.setText(msg.body);
body.setVisibility(msg.body.isEmpty() ? GONE : VISIBLE);
meta.setText(Ui.timeOfDay(c, msg.ts));
// "Edited" like Signal's; a tap on the bubble shows the earlier texts.
meta.setText((versions.containsKey(msg.id) ? "Edited · " : "") + Ui.timeOfDay(c, msg.ts));
meta.setTextColor(out ? 0xB3FFFFFF : Ui.MUTED);
Ui.glyph(meta, "pending".equals(msg.status) ? Glyph.Kind.CLOCK : null, true);
failed.setVisibility("failed".equals(msg.status) ? VISIBLE : GONE);
@@ -778,6 +784,75 @@ public final class ChatActivity extends BaseActivity {
new AlertDialog.Builder(this).setTitle("Reactions").setItems(lines, null).setPositiveButton("OK", null).show();
}
/**
* Long-press on a message: the quick reactions (yours lit; tap it again to
* take it back), + for every emoji, and Copy. A reaction goes out as a
* text worded like an iPhone's ("Loved “…”").
*/
private void messageMenu(Store.Msg m) {
Context c = this;
String mine = null;
List<Reactions.Reaction> rs = reactions.get(m.id);
if (rs != null) for (Reactions.Reaction r : rs) if ("me".equals(r.from)) mine = r.emoji;
boolean canReact = "delivered".equals(m.status) && (!m.body.trim().isEmpty() || m.mediaJson != null);
if (!canReact && m.body.isEmpty()) return;
LinearLayout box = new LinearLayout(c);
box.setOrientation(LinearLayout.VERTICAL);
box.setPadding(Ui.dp(c, 12), Ui.dp(c, 16), Ui.dp(c, 12), Ui.dp(c, 8));
AlertDialog[] d = new AlertDialog[1];
if (canReact) {
LinearLayout row = new LinearLayout(c);
row.setGravity(Gravity.CENTER);
String[] quick = Config.quickReactions(c);
String[] cells = java.util.Arrays.copyOf(quick, quick.length + 1);
cells[quick.length] = "+";
final String current = mine;
for (String e : cells) {
boolean more = e.equals("+");
TextView t = Ui.text(c, e, more ? Ui.T_NAME : Ui.T_TITLE, more ? Ui.MUTED : Ui.TEXT);
t.setGravity(Gravity.CENTER);
t.setMinHeight(Ui.dp(c, 76));
if (!more && Reactions.same(current, e)) t.setBackground(Ui.round(Ui.ROW_ACTIVE, Ui.dp(c, 38)));
t.setContentDescription(more ? "More emoji" : Reactions.same(current, e) ? "Take back " + e : "React " + e);
t.setOnClickListener(v -> {
d[0].dismiss();
if (more) EmojiPicker.show(c, "React with", pick -> react(m, pick, current));
else react(m, e, current);
});
row.addView(t, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
}
box.addView(row);
}
if (!m.body.isEmpty()) {
TextView copy = Ui.text(c, "Copy text", Ui.T_BODY, Ui.TEXT);
copy.setPadding(Ui.dp(c, 20), Ui.dp(c, 22), Ui.dp(c, 20), Ui.dp(c, 22));
copy.setOnClickListener(v -> {
d[0].dismiss();
copyText(m.body);
});
box.addView(copy);
}
d[0] = new AlertDialog.Builder(c).setView(box).show();
}
/** Sends `emoji` as a reaction to `m`, or takes it back if it's already yours. */
private void react(Store.Msg m, String emoji, String mine) {
Sender.send(this, did, contact, Reactions.text(emoji, m, Reactions.same(mine, emoji)), new ArrayList<>());
}
/** An edited message's texts, newest first, like Signal's edit history. */
private void showEdits(Store.Msg m) {
List<Edits.Version> vs = versions.get(m.id);
if (vs == null) return;
String[] lines = new String[vs.size()];
for (int i = 0; i < vs.size(); i++) {
Edits.Version v = vs.get(vs.size() - 1 - i);
String label = i == 0 ? "Now" : i == vs.size() - 1 ? "Original" : "Edited";
lines[i] = label + " · " + Ui.dayLabel(v.ts) + " " + Ui.timeOfDay(this, v.ts) + "\n" + v.body;
}
new AlertDialog.Builder(this).setTitle("Edit history").setItems(lines, null).setPositiveButton("OK", null).show();
}
/** Copies a message's text. Android 13 shows its own "copied" popup, so no toast of ours. */
private void copyText(String text) {
android.content.ClipboardManager cm = getSystemService(android.content.ClipboardManager.class);