wordmaker: count bonus words in the dialog and on the button (#915)
- Commit
c929c4b50b1994ee37040a333313b15b76ab07cd- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 17:38 UTC (23 days ago)
- Parents
d7c7bea
Request: #915 asks for a counter of the bonus words found in the current puzzle, shown in the bonus words popup. Current state: the per-puzzle bonus set already exists (WordMakerViewModel picks the casual/daily/competitive set, reset per level in LevelDataStore), but BonusWordsDialog showed only the title "Bonus Words" and the list, and the bonus button gave no hint of how many there were. That button also drew its icon with a raw Icon(painterResource(R.drawable.outline_book_2_24)), which the root rules allow only inside library/ui Icons.kt. Changes: - BonusWordsDialog title is now a plurals resource with the count: "Bonus Word (1)" / "Bonus Words (3)". Only the found count is shown; no "n of m possible" is computed. - Bonus button: wrapped in library/ui BadgedBox with a Badge showing the count (capped at "99+"); no badge while the set is empty (the button is disabled then, as before). The shake animation and the position callback for the flying-letters animation stay on the outer box, unchanged. - Icon: new IconBook() helper in library/ui Icons.kt draws the same Material Symbols book_2 glyph from its path data (no drawable needed, takes an optional contentDescription). The button uses it with the existing, translated "Bonus Words" string as its spoken label (it had none before), and wordmaker's now unused outline_book_2_24 drawable is deleted. - Strings: new plurals in values/ only; translations fall back to English for the titled count. bonus_words keeps its translations as the button label. User-visible effect: the bonus words dialog title reads e.g. "Bonus Words (3)", and the book button in the corner carries a small badge with the same count, so progress is visible without opening it. TalkBack now announces the button as "Bonus Words". Not changed: the hint button next to it still uses a raw Icon(painterResource(android.R.drawable.ic_menu_help)); left for a separate change. Screenshots: the "1-puzzle" and "2-solved" store previews have four bonus words, so they now render a "4" badge on the bonus button. Store screenshots were not regenerated. Verification: new BonusWordsCounterTest (badge cap, singular and plural dialog titles, badge shown with the count and the button opening the dialog, no badge and disabled button when empty); WordMakerComposeTest's two bonus dialog tests now expect the counted titles. Container build: :games:wordmaker compileDevKotlin, testDevUnitTest and lint pass with no new findings; :library:ui compileDebugKotlin passes and detekt reports nothing in Icons.kt (its one finding, LargeClass on the untouched IconsSliceTest, is pre-existing on main).
Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.ktindex 09132cf20c..532f5688b0 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt@@ -29,10 +29,13 @@ import com.vayunmathur.games.wordmaker.platform.WordGameActions import com.vayunmathur.games.wordmaker.ui.components.CompetitiveStatusBar import com.vayunmathur.games.wordmaker.ui.components.DailyStatusBar import com.vayunmathur.games.wordmaker.ui.components.LetterChooser+import com.vayunmathur.library.ui.Badge+import com.vayunmathur.library.ui.BadgedBox import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.FilledIconButton import com.vayunmathur.library.ui.Icon+import com.vayunmathur.library.ui.IconBook import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.Text @@ -154,13 +157,20 @@ fun BoxScope.WordGameCornerButtons( translationX = bonusShake }, ) {- FilledIconButton(- onClick = onOpenBonusWords,- enabled = bonusWords.isNotEmpty()+ // Badge: how many bonus words this puzzle has so far (#915).+ BadgedBox(+ badge = {+ if (bonusWords.isNotEmpty()) {+ Badge { Text(bonusBadgeText(bonusWords.size)) }+ }+ }, ) {- Icon(- painterResource(R.drawable.outline_book_2_24), null- )+ FilledIconButton(+ onClick = onOpenBonusWords,+ enabled = bonusWords.isNotEmpty()+ ) {+ IconBook(contentDescription = stringResource(R.string.bonus_words))+ } } } @@ -191,3 +201,10 @@ fun BoxScope.WordGameCornerButtons( } } }++/** Most bonus words the badge spells out; beyond it shows "99+". */+private const val BONUS_BADGE_MAX = 99++/** Badge text for [count] bonus words: the number, capped at "99+". */+internal fun bonusBadgeText(count: Int): String =+ if (count > BONUS_BADGE_MAX) "$BONUS_BADGE_MAX+" else count.toString()
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.ktindex 7bafadb610..5d458a87fc 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt@@ -15,6 +15,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier+import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.games.wordmaker.R@@ -57,7 +58,8 @@ fun BonusWordsDialog( var definitionDialog by remember { mutableStateOf<Pair<String, List<String>>?>(null) } AlertDialog( onDismissRequest = onDismiss,- title = { Text(text = stringResource(R.string.bonus_words)) },+ // The count of this puzzle's bonus words found so far (#915).+ title = { Text(text = pluralStringResource(R.plurals.bonus_words_title, bonusWords.size, bonusWords.size)) }, text = { LazyColumn(modifier = Modifier.fillMaxWidth()) { items(bonusWords.toList().sorted()) { word ->
games/wordmaker/src/main/res/drawable/outline_book_2_24.xml
diff --git a/games/wordmaker/src/main/res/drawable/outline_book_2_24.xml b/games/wordmaker/src/main/res/drawable/outline_book_2_24.xmldeleted file mode 100644index f7c8d0ce87..0000000000--- a/games/wordmaker/src/main/res/drawable/outline_book_2_24.xml+++ /dev/null@@ -1,5 +0,0 @@-<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">- - <path android:fillColor="@android:color/white" android:pathData="M300,880Q242,880 201,839Q160,798 160,740L160,220Q160,162 201,121Q242,80 300,80L800,80L800,680Q775,680 757.5,697.5Q740,715 740,740Q740,765 757.5,782.5Q775,800 800,800L800,880L300,880ZM240,613Q254,606 269,603Q284,600 300,600L320,600L320,160L300,160Q275,160 257.5,177.5Q240,195 240,220L240,613ZM400,600L720,600L720,160L400,160L400,600ZM240,613Q240,613 240,613Q240,613 240,613L240,613L240,160L240,160Q240,160 240,160Q240,160 240,160L240,613ZM300,800L673,800Q667,786 663.5,771.5Q660,757 660,740Q660,724 663,709Q666,694 673,680L300,680Q274,680 257,697.5Q240,715 240,740Q240,766 257,783Q274,800 300,800Z"/>- -</vector>
games/wordmaker/src/main/res/values/strings.xml
diff --git a/games/wordmaker/src/main/res/values/strings.xml b/games/wordmaker/src/main/res/values/strings.xmlindex 12157d215e..9f36a7f056 100644--- a/games/wordmaker/src/main/res/values/strings.xml+++ b/games/wordmaker/src/main/res/values/strings.xml@@ -5,8 +5,13 @@ <string name="error_parse_level">Failed to parse level data.</string> <!-- WordMakerTopBar: Title in casual mode when level number present. %1$d = level number integer, e.g. 12. Noun phrase --> <string name="level_number">Level <xliff:g id="level" example="12">%1$d</xliff:g></string>- <!-- BonusWordsDialog: Title for dialog listing extra words not in puzzle. Noun phrase -->+ <!-- WordGameScreen: Accessibility label of the bonus words button (book icon, with a count badge) that opens the list of extra words found that are not in the puzzle. Noun phrase --> <string name="bonus_words">Bonus Words</string>+ <!-- BonusWordsDialog: Title of the dialog listing extra words found that are not in the puzzle; %1$d = how many have been found in this puzzle. Noun phrase -->+ <plurals name="bonus_words_title">+ <item quantity="one">Bonus Word (<xliff:g id="count" example="1">%1$d</xliff:g>)</item>+ <item quantity="other">Bonus Words (<xliff:g id="count" example="3">%1$d</xliff:g>)</item>+ </plurals> <!-- Settings: Toggle for tap-to-spell input mode. Label --> <string name="tap_to_spell">Tap to Spell</string> <!-- SettingsPage: Subtitle explaining tap-to-spell behavior. Sentence -->
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusWordsCounterTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusWordsCounterTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusWordsCounterTest.ktnew file mode 100644index 0000000000..c7bc5d9079--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusWordsCounterTest.kt@@ -0,0 +1,98 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.foundation.layout.Box+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.games.wordmaker.ui.dialogs.BonusWordsDialog+import com.vayunmathur.library.ui.DynamicTheme+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/** Bonus word count in the dialog title and on the bonus button (#915). */+@RunWith(RobolectricTestRunner::class)+class BonusWordsCounterTest {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun badgeTextCapsAtNinetyNine() {+ assertEquals("1", bonusBadgeText(1))+ assertEquals("12", bonusBadgeText(12))+ assertEquals("99", bonusBadgeText(99))+ assertEquals("99+", bonusBadgeText(100))+ }++ @Test+ fun dialogTitleCountsOneWord() {+ rule.setContent {+ DynamicTheme { BonusWordsDialog(bonusWords = setOf("OWL"), getDefinition = { emptyList() }, onDismiss = {}) }+ }+ rule.onNodeWithText("Bonus Word (1)").assertIsDisplayed()+ }++ @Test+ fun dialogTitleCountsSeveralWords() {+ rule.setContent {+ DynamicTheme {+ BonusWordsDialog(bonusWords = setOf("OWL", "COW", "LOW"), getDefinition = { emptyList() }, onDismiss = {})+ }+ }+ rule.onNodeWithText("Bonus Words (3)").assertIsDisplayed()+ }++ @Test+ fun bonusButtonShowsCountBadgeAndOpens() {+ var opened = false+ rule.setContent {+ DynamicTheme {+ Box {+ WordGameCornerButtons(+ isWon = false,+ isCompetitive = true,+ bonusWords = setOf("OWL", "COW"),+ bonusShake = 0f,+ onOpenBonusWords = { opened = true },+ onBonusButtonPositioned = {},+ remainingCooldownMs = 0L,+ onOpenHint = {},+ )+ }+ }+ }+ rule.onNodeWithText("2", useUnmergedTree = true).assertIsDisplayed()+ rule.onNodeWithContentDescription("Bonus Words").performClick()+ assertTrue(opened)+ }++ @Test+ fun bonusButtonWithoutWordsHasNoBadge() {+ rule.setContent {+ DynamicTheme {+ Box {+ WordGameCornerButtons(+ isWon = false,+ isCompetitive = true,+ bonusWords = emptySet(),+ bonusShake = 0f,+ onOpenBonusWords = {},+ onBonusButtonPositioned = {},+ remainingCooldownMs = 0L,+ onOpenHint = {},+ )+ }+ }+ }+ rule.onNodeWithContentDescription("Bonus Words").assertIsNotEnabled()+ assertTrue(rule.onAllNodesWithText("0", useUnmergedTree = true).fetchSemanticsNodes().isEmpty())+ }+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.ktindex f13924dc0a..5f2899206e 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt@@ -298,7 +298,7 @@ class WordMakerComposeTest { BonusWordsDialog(bonusWords = setOf("DOG", "CAT"), getDefinition = { listOf("def of $it") }, onDismiss = {}) } }- rule.onNodeWithText("Bonus Words").assertIsDisplayed()+ rule.onNodeWithText("Bonus Words (2)").assertIsDisplayed() rule.onNodeWithText("DOG").performClick() rule.onNodeWithText("def of DOG").assertIsDisplayed() }@@ -338,7 +338,7 @@ class WordMakerComposeTest { ) } }- rule.onNodeWithText("Bonus Words").assertIsDisplayed()+ rule.onNodeWithText("Bonus Word (1)").assertIsDisplayed() rule.onNodeWithText("DOG").assertIsDisplayed() } private val frameClock = object : androidx.compose.runtime.MonotonicFrameClock {
library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.ktindex 9025ef78ca..a88435b8a3 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt@@ -312,6 +312,7 @@ import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.graphics.StrokeJoin import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.PathBuilder+import androidx.compose.ui.graphics.vector.addPathNodes import androidx.compose.ui.graphics.vector.path import androidx.compose.ui.unit.dp import com.vayunmathur.library.util.NavBackStack@@ -837,6 +838,41 @@ fun IconDirectionsWalk(modifier: Modifier = Modifier, tint: Color = LocalContent fun IconMenuBook(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) = AppIcon(Icons.AutoMirrored.Filled.MenuBook, "Menu", modifier, tint) +/**+ * Material Symbols "book_2" (outlined), bundled as a vector so apps need no drawable+ * of their own. The word games use it for their bonus-words button.+ */+private const val BOOK_2_PATH =+ "M300,880Q242,880 201,839Q160,798 160,740L160,220Q160,162 201,121Q242,80 " ++ "300,80L800,80L800,680Q775,680 757.5,697.5Q740,715 740,740Q740,765 " ++ "757.5,782.5Q775,800 800,800L800,880L300,880Z" ++ "M240,613Q254,606 269,603Q284,600 300,600L320,600L320,160L300,160Q275,160 " ++ "257.5,177.5Q240,195 240,220L240,613Z" ++ "M400,600L720,600L720,160L400,160L400,600Z" ++ "M240,613Q240,613 240,613Q240,613 240,613L240,613L240,160L240,160Q240,160 " ++ "240,160Q240,160 240,160L240,613Z" ++ "M300,800L673,800Q667,786 663.5,771.5Q660,757 660,740Q660,724 663,709Q666,694 " ++ "673,680L300,680Q274,680 257,697.5Q240,715 240,740Q240,766 257,783Q274,800 " ++ "300,800Z"++private val Book2 by lazy {+ ImageVector.Builder(+ name = "Book2",+ defaultWidth = 24.dp,+ defaultHeight = 24.dp,+ viewportWidth = 960f,+ viewportHeight = 960f,+ ).addPath(pathData = addPathNodes(BOOK_2_PATH), fill = SolidColor(Color.Black)).build()+}++/** A closed book. [contentDescription] defaults to "Book"; pass the control's own label. */+@Composable+fun IconBook(+ modifier: Modifier = Modifier,+ tint: Color = LocalContentColor.current,+ contentDescription: String? = "Book",+) = AppIcon(Book2, contentDescription, modifier, tint)+ @Composable fun IconFuelPrice(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) = AppIcon(Icons.Filled.LocalGasStation, "Fuel price", modifier, tint)