From a2c8ab25f6f5a8f7d79bb419e442b6cb8bc65a55 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 24 Apr 2023 10:36:59 -0500 Subject: [PATCH] Better tab title --- build.gradle | 1 + .../java/com/cheogram/android/WebxdcPage.java | 20 ++++++++++++++++++- .../com/cheogram/android/WebxdcUpdate.java | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f7cfb9638efc014e9307acffc9747fa7cb273650..b8d1c9cb850cc95ad2e482677b2ba5a9094c2980 100644 --- a/build.gradle +++ b/build.gradle @@ -104,6 +104,7 @@ dependencies { implementation 'org.snikket:webrtc-android:107.0.0' implementation 'com.github.woltapp:blurhash:master' implementation 'com.caverock:androidsvg-aar:1.4' + implementation 'org.tomlj:tomlj:1.1.0' implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:4.1.2' // INSERT } diff --git a/src/cheogram/java/com/cheogram/android/WebxdcPage.java b/src/cheogram/java/com/cheogram/android/WebxdcPage.java index bc8f71b9e109f487637d52692a57b2735dd6c9d2..d44b4b4fd30f18591fdac893fae4d6e8d53ac827 100644 --- a/src/cheogram/java/com/cheogram/android/WebxdcPage.java +++ b/src/cheogram/java/com/cheogram/android/WebxdcPage.java @@ -40,6 +40,9 @@ import java.util.zip.ZipFile; import org.json.JSONObject; import org.json.JSONException; +import org.tomlj.Toml; +import org.tomlj.TomlTable; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.WebxdcPageBinding; @@ -56,8 +59,10 @@ public class WebxdcPage implements ConversationPage { protected XmppConnectionService xmppConnectionService; protected WebxdcPageBinding binding = null; protected ZipFile zip = null; + protected TomlTable manifest = null; protected String baseUrl; protected Message source; + protected WebxdcUpdate lastUpdate = null; public WebxdcPage(Cid cid, Message source, XmppConnectionService xmppConnectionService) { this.xmppConnectionService = xmppConnectionService; @@ -65,6 +70,10 @@ public class WebxdcPage implements ConversationPage { File f = xmppConnectionService.getFileForCid(cid); try { if (f != null) zip = new ZipFile(xmppConnectionService.getFileForCid(cid)); + final ZipEntry manifestEntry = zip.getEntry("manifest.toml"); + if (manifestEntry != null) { + manifest = Toml.parse(zip.getInputStream(manifestEntry)); + } } catch (final IOException e) { Log.w(Config.LOGTAG, "WebxdcPage: " + e); } @@ -77,7 +86,15 @@ public class WebxdcPage implements ConversationPage { } public String getTitle() { - return "WebXDC"; + String title = manifest == null ? null : manifest.getString("name"); + if (lastUpdate != null && lastUpdate.getDocument() != null) { + if (title == null) { + title = lastUpdate.getDocument(); + } else { + title += ": " + lastUpdate.getDocument(); + } + } + return title == null ? "ChatApp" : title; } public String getNode() { @@ -316,6 +333,7 @@ public class WebxdcPage implements ConversationPage { StringBuilder builder = new StringBuilder("["); String sep = ""; for (WebxdcUpdate update : xmppConnectionService.findWebxdcUpdates(source, lastKnownSerial)) { + lastUpdate = update; builder.append(sep); builder.append(update.toString()); sep = ","; diff --git a/src/cheogram/java/com/cheogram/android/WebxdcUpdate.java b/src/cheogram/java/com/cheogram/android/WebxdcUpdate.java index 0e2f8bea19adfc0655d80d560edf0fa3df69f17a..570b3a180cfa5b2c8aeea17efdfafdc6add671a9 100644 --- a/src/cheogram/java/com/cheogram/android/WebxdcUpdate.java +++ b/src/cheogram/java/com/cheogram/android/WebxdcUpdate.java @@ -55,6 +55,10 @@ public class WebxdcUpdate { return summary; } + public String getDocument() { + return document; + } + public ContentValues getContentValues() { ContentValues cv = new ContentValues(); cv.put(Message.CONVERSATION, conversationId);