Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.
Update dialog: show New:, Fixed: and Improved: in bold
jesse-agent-3620396b145b6f1
diff --git a/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt b/app/src/main/java/app/tellyscope/ui/UpdateDialog.ktindex fa9a472..cd13537 100644--- a/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt+++ b/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt@@ -14,6 +14,11 @@ import androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifier+import androidx.compose.ui.text.AnnotatedString+import androidx.compose.ui.text.SpanStyle+import androidx.compose.ui.text.buildAnnotatedString+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.withStyleimport androidx.compose.ui.unit.dpimport app.tellyscope.data.Update@@ -25,7 +30,7 @@ fun UpdateDialog(update: Update, onGet: () -> Unit, onLater: () -> Unit, onSkip:title = { Text("Tellyscope ${update.version} is out") },text = {Column(Modifier.heightIn(max = 320.dp).verticalScroll(rememberScrollState())) {- Text(dialogNotes(update.notes).ifEmpty { "No release notes." }, style = MaterialTheme.typography.bodyMedium)+ Text(boldSpans(dialogNotes(update.notes).ifEmpty { "No release notes." }), style = MaterialTheme.typography.bodyMedium)}},confirmButton = { Button(onClick = onGet) { Text("Get it") } },@@ -40,13 +45,22 @@ fun UpdateDialog(update: Update, onGet: () -> Unit, onLater: () -> Unit, onSkip:/*** release.yml's body as plain lines: the CHANGELOG part (prod) or the alpha line, without the- * commit list, Markdown emphasis, code ticks or the trailing PR links, capped at [max] lines.+ * commit list, code ticks or the trailing PR links, capped at [max] lines. `**` stays for [boldSpans].*/internal fun dialogNotes(body: String, max: Int = 12): String {val lines = body.substringBefore("### Commits").lines()- .map { it.replace("**", "").replace("`", "").replace(PR_LINK, "").trimEnd() }+ .map { it.replace("`", "").replace(PR_LINK, "").trimEnd() }.filter { it.isNotBlank() }return (if (lines.size > max) lines.take(max) + "…and more on GitHub" else lines).joinToString("\n")}private val PR_LINK = Regex("""\s*\[#\d+]\([^)]*\)\s*$""")++/** Each `**…**` pair becomes bold, stars removed; an unmatched `**` is dropped. */+internal fun boldSpans(text: String): AnnotatedString = buildAnnotatedString {+ val parts = text.split("**")+ parts.forEachIndexed { i, part ->+ // Odd parts sit inside a pair, unless the last one, whose opening `**` has no partner.+ if (i % 2 == 1 && i < parts.lastIndex) withStyle(SpanStyle(fontWeight = FontWeight.Bold)) { append(part) } else append(part)+ }+}diff --git a/app/src/test/java/app/tellyscope/UpdateCheckTest.kt b/app/src/test/java/app/tellyscope/UpdateCheckTest.ktindex b7fd730..0cac1b1 100644--- a/app/src/test/java/app/tellyscope/UpdateCheckTest.kt+++ b/app/src/test/java/app/tellyscope/UpdateCheckTest.kt@@ -2,9 +2,11 @@package app.tellyscope+import androidx.compose.ui.text.font.FontWeightimport app.tellyscope.data.UpdateCheckimport app.tellyscope.data.compareVersionsimport app.tellyscope.data.newest+import app.tellyscope.ui.boldSpansimport app.tellyscope.ui.dialogNotesimport kotlinx.coroutines.test.runTestimport org.junit.Assert.assertEquals@@ -158,9 +160,9 @@ class UpdateCheckTest {@Test fun `prod notes keep the changelog lines, plain, capped at twelve`() {val lines = dialogNotes(prodBody).lines()assertEquals(13, lines.size)- assertEquals("- New: A new app icon: a telescope with a TV screen for a lens.", lines.first())+ assertEquals("- **New:** A new app icon: a telescope with a TV screen for a lens.", lines.first())assertEquals("…and more on GitHub", lines.last())- assertTrue(lines.none { "**" in it || "](" in it || "Commits" in it })+ assertTrue(lines.none { "](" in it || "Commits" in it })}@Test fun `alpha notes are just the alpha line`() {@@ -171,6 +173,21 @@ class UpdateCheckTest {}@Test fun `short notes are not cut`() {- assertEquals("- Fixed: one thing.", dialogNotes("- **Fixed:** one thing. [#9](../../pull/9)\n\n### Commits since v1\n\n- x (abc)"))+ assertEquals("- **Fixed:** one thing.", dialogNotes("- **Fixed:** one thing. [#9](../../pull/9)\n\n### Commits since v1\n\n- x (abc)"))+ }++ @Test fun `New is bold with the stars gone`() {+ val first = boldSpans(dialogNotes(prodBody)).let { it.subSequence(0, it.text.indexOf('\n')) }+ assertEquals("- New: A new app icon: a telescope with a TV screen for a lens.", first.text)+ assertFalse('*' in boldSpans(dialogNotes(prodBody)).text)+ val bold = first.spanStyles.single()+ assertEquals(FontWeight.Bold, bold.item.fontWeight)+ assertEquals("New:", first.text.substring(bold.start, bold.end))+ }++ @Test fun `an unmatched pair of stars is dropped`() {+ val s = boldSpans("a **b** c ** d")+ assertEquals("a b c d", s.text)+ assertEquals("b", s.spanStyles.single().let { s.text.substring(it.start, it.end) })}}