Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
fix(ui): format the release notes in the update check (#70)
Durganshua22e28b07038
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 72b2eb5..913a127 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -207,6 +207,12 @@ All notable changes to Gotcha are documented here.the ball is on or off instead of only once it is already too late.### Fixed+- **Readable release notes in the update check** (#70). When Settings → About+ found a new version, its notes were shown as raw Markdown, with `###`, `**`+ and backticks spelled out and lines broken mid-sentence. They are now+ formatted like a chat reply, the Download button sits above them, and long+ notes open as a list of their headlines with "Show all release notes" for+ the rest.- **The context meter keeps up with the chat** (#71). The row of bars under achat's title, showing how much of the model's context the chat has used, onlymoved when you left the chat and came back; during a reply it stayed where itdiff --git a/app/src/main/java/com/gotcha/ui/AboutScreen.kt b/app/src/main/java/com/gotcha/ui/AboutScreen.ktindex a08827d..afba166 100644--- a/app/src/main/java/com/gotcha/ui/AboutScreen.kt+++ b/app/src/main/java/com/gotcha/ui/AboutScreen.kt@@ -210,12 +210,6 @@ fun AppUpdateSection() {style = MaterialTheme.typography.bodyMedium,color = MaterialTheme.colorScheme.primary)- if (currentStatus.info.releaseNotes.isNotEmpty()) {- Text(- text = currentStatus.info.releaseNotes,- style = MaterialTheme.typography.bodySmall- )- }Button(onClick = {if (busy) return@Buttonbusy = true@@ -240,6 +234,9 @@ fun AppUpdateSection() {}) {Text("Download Update")}+ if (currentStatus.info.releaseNotes.isNotEmpty()) {+ ReleaseNotes(currentStatus.info.releaseNotes)+ }}}is UpdateStatus.Downloading -> {diff --git a/app/src/main/java/com/gotcha/ui/CodeBox.kt b/app/src/main/java/com/gotcha/ui/CodeBox.ktindex 527eedb..7f531c3 100644--- a/app/src/main/java/com/gotcha/ui/CodeBox.kt+++ b/app/src/main/java/com/gotcha/ui/CodeBox.kt@@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dpimport com.gotcha.ui.theme.GotchaMonoimport com.gotcha.ui.theme.LocalSkinimport com.halilibo.richtext.markdown.Markdown+import com.halilibo.richtext.ui.RichTextStyleimport com.halilibo.richtext.ui.material3.Material3RichText/**@@ -35,11 +36,11 @@ import com.halilibo.richtext.ui.material3.Material3RichText* user has to run can be copied exactly (issue #109).*/@Composable-fun RichMarkdown(markdown: String, modifier: Modifier = Modifier) {+fun RichMarkdown(markdown: String, modifier: Modifier = Modifier, style: RichTextStyle? = null) {Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {splitFencedBlocks(markdown).forEach { segment ->when (segment) {- is MarkdownSegment.Prose -> Material3RichText { Markdown(segment.markdown) }+ is MarkdownSegment.Prose -> Material3RichText(style = style) { Markdown(segment.markdown) }is MarkdownSegment.Code -> CodeBox(code = segment.code, language = segment.language)}}diff --git a/app/src/main/java/com/gotcha/ui/ReleaseNotes.kt b/app/src/main/java/com/gotcha/ui/ReleaseNotes.ktnew file mode 100644index 0000000..513ba0b--- /dev/null+++ b/app/src/main/java/com/gotcha/ui/ReleaseNotes.kt@@ -0,0 +1,68 @@+package com.gotcha.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.ProvideTextStyle+import androidx.compose.material3.Text+import androidx.compose.material3.TextButton+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import com.halilibo.richtext.ui.RichTextStyle++private val LIST_ITEM = Regex("^[-*+] ")+private val BOLD_LEAD = Regex("^[-*+] (\\*\\*.+?\\*\\*)")++/**+ * The short form of a release's notes: every heading, and each top-level list+ * item cut down to its bold lead ("- **Podcast generation.**"), which is how+ * CHANGELOG.md entries are written. Returns null when the notes don't follow+ * that shape (an item with no bold lead, or no items at all) or when the short+ * form would hide nothing, so the caller shows them in full instead.+ */+internal fun releaseNotesHeadlines(markdown: String): String? {+ val kept = mutableListOf<String>()+ var hidden = false+ for (line in markdown.lines()) {+ when {+ line.startsWith("#") -> kept += line+ LIST_ITEM.containsMatchIn(line) -> {+ val lead = BOLD_LEAD.find(line) ?: return null+ kept += line.substring(0, 2) + lead.groupValues[1]+ if (line.length > lead.range.last + 1) hidden = true+ }+ line.isNotBlank() -> hidden = true+ }+ }+ if (kept.none { LIST_ITEM.containsMatchIn(it) } || !hidden) return null+ return kept.joinToString("\n")+}++/**+ * A release's notes as rendered Markdown (issue #70), sized to sit inside a+ * settings section: body text at bodySmall and headings no larger than+ * titleSmall. Long notes open as their headlines with a toggle for the rest.+ */+@Composable+fun ReleaseNotes(markdown: String, modifier: Modifier = Modifier) {+ val headlines = remember(markdown) { releaseNotesHeadlines(markdown) }+ var expanded by remember(markdown) { mutableStateOf(false) }+ val headingStyle = MaterialTheme.typography.titleSmall+ val style = remember(headingStyle) { RichTextStyle(headingStyle = { _, _ -> headingStyle }) }++ Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {+ ProvideTextStyle(MaterialTheme.typography.bodySmall) {+ RichMarkdown(if (expanded || headlines == null) markdown else headlines, style = style)+ }+ if (headlines != null) {+ TextButton(onClick = { expanded = !expanded }) {+ Text(if (expanded) "Show less" else "Show all release notes")+ }+ }+ }+}diff --git a/app/src/test/java/com/gotcha/ui/ReleaseNotesTest.kt b/app/src/test/java/com/gotcha/ui/ReleaseNotesTest.ktnew file mode 100644index 0000000..395820e--- /dev/null+++ b/app/src/test/java/com/gotcha/ui/ReleaseNotesTest.kt@@ -0,0 +1,47 @@+package com.gotcha.ui++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNull+import org.junit.Test++/** [releaseNotesHeadlines] is what the About screen shows before "Show all release notes" (issue #70). */+class ReleaseNotesTest {++ @Test+ fun `changelog notes shorten to headings and bold leads`() {+ val notes = """+ ### Added+ - **Podcast generation.** Gotcha can now turn text into listenable audio. Ask+ for a topic as a podcast (`synthesize_podcast`).+ - **PDF editing.** A new `pdf_edit` tool reshapes PDFs.+ ### Fixed+ - **Termux commands** run with Termux closed.+ """.trimIndent()+ assertEquals(+ """+ ### Added+ - **Podcast generation.**+ - **PDF editing.**+ ### Fixed+ - **Termux commands**+ """.trimIndent(),+ releaseNotesHeadlines(notes)+ )+ }++ @Test+ fun `an item without a bold lead keeps the notes whole`() {+ val notes = "### Added\n- **Podcasts.** Audio from text.\n- Faster startup."+ assertNull(releaseNotesHeadlines(notes))+ }++ @Test+ fun `notes with nothing to hide are not shortened`() {+ assertNull(releaseNotesHeadlines("### Fixed\n- **Crash on launch**\n- **Wrong date**"))+ }++ @Test+ fun `plain text notes are not shortened`() {+ assertNull(releaseNotesHeadlines("Bug fixes"))+ }+}