Modern Apps git

← Modern-Apps.git

unblockjam: (refactor) replace hardcoded strings with string resources this will make localization much easier in future

Commit
98147cddaea5ec03f89216e04d187ae8c1645480
Author
Anonymous <[email protected]>
When
2026-03-16 10:52 UTC (8 months ago)
Parents
2b846dc

Diff

games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.ktindex 88ac4e376d..ddad070b67 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt@@ -48,6 +48,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.painterResource+import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp@@ -108,7 +109,7 @@ fun Navigation(completedLevelsRepository: CompletedLevelsRepository) { fun LevelScreen(backStack: NavBackStack<Route>, completedLevelsRepository: CompletedLevelsRepository) {     val levelStats = completedLevelsRepository.getLevelStats()     Scaffold(topBar = {-        TopAppBar({Text("Level Selector")})+        TopAppBar({Text(stringResource(R.string.level_selector))})     }) { paddingValues ->         LazyVerticalGrid(             GridCells.Adaptive(80.dp),@@ -233,7 +234,7 @@ fun GameScreen(backStack: NavBackStack<Route>, completedLevelsRepository: Comple                         },                         enabled = history.isNotEmpty() && !isLevelWon                     ) {-                        Text("Undo")+                        Text(stringResource(R.string.undo))                     }                     Button(onClick = {                         history.clear()@@ -241,7 +242,7 @@ fun GameScreen(backStack: NavBackStack<Route>, completedLevelsRepository: Comple                         isLevelWon = false                     },                         enabled = history.isNotEmpty() && !isLevelWon) {-                        Text("Restart")+                        Text(stringResource(R.string.restart))                     }                 }             }@@ -251,7 +252,7 @@ fun GameScreen(backStack: NavBackStack<Route>, completedLevelsRepository: Comple  @Composable fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Boolean, maxLevelIndex: Int) {-    InfoBox(title = "Puzzle") {+    InfoBox(title = stringResource(R.string.level)) {         Row(             verticalAlignment = Alignment.CenterVertically,             horizontalArrangement = Arrangement.SpaceBetween,@@ -263,7 +264,7 @@ fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Bo             ) {                 Icon(                     painterResource(R.drawable.arrow_back_24px),-                    contentDescription = "Previous Level",+                    contentDescription = stringResource(R.string.previous_level),                 )             }             Column(horizontalAlignment = Alignment.CenterHorizontally) {@@ -279,13 +280,13 @@ fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Bo             ) {                 Icon(                     painterResource(R.drawable.arrow_forward_24px),-                    contentDescription = "Next Level",+                    contentDescription = stringResource(R.string.next_level),                 )             }         }         if (isCompleted) {             Text(-                text = "Completed",+                text = stringResource(R.string.completed),                 color = MaterialTheme.colorScheme.error,                 fontSize = 12.sp,                 fontWeight = FontWeight.Bold@@ -296,7 +297,7 @@ fun PuzzleInfoBox(levelIndex: Int, onLevelChange: (Int) -> Unit, isCompleted: Bo  @Composable fun MovesInfoBox(moves: Int, bestScore: Int?, optimalMoves: Int) {-    InfoBox(title = "Moves") {+    InfoBox(title = stringResource(R.string.moves)) {         Column(horizontalAlignment = Alignment.CenterHorizontally) {             Text(                 text = "$moves",
games/unblockjam/src/main/res/values/strings.xml
diff --git a/games/unblockjam/src/main/res/values/strings.xml b/games/unblockjam/src/main/res/values/strings.xmlindex 9ab8062cc1..87b9c809ef 100644--- a/games/unblockjam/src/main/res/values/strings.xml+++ b/games/unblockjam/src/main/res/values/strings.xml@@ -1,3 +1,11 @@ <resources>     <string name="app_name">Unblock Jam</string>+    <string name="level">Puzzle</string>+    <string name="level_selector">Puzzle Select</string>+    <string name="undo">Undo</string>+    <string name="restart">Restart</string>+    <string name="previous_level">Previous Puzzle</string>+    <string name="next_level">Next Puzzle</string>+    <string name="completed">Completed</string>+    <string name="moves">Moves</string> </resources>\ No newline at end of file