Modern Apps git

← Modern-Apps.git

voxels: track achievements per world alongside the app-level tier

Commit
21a910a83e7819f09357e9cf5b2afa457233ec37
Author
Vayun Mathur <[email protected]>
When
2026-08-05 19:11 UTC (4 months ago)
Parents
31f2e8e

Diff

games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.ktindex 4cf8675b6b..813b7f3b01 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt@@ -18,7 +18,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import com.vayunmathur.games.voxels.ui.*-import com.vayunmathur.games.voxels.util.VoxelsAchievementsManager+import com.vayunmathur.games.voxels.util.VoxelsAchievements import com.vayunmathur.games.voxels.util.VoxelsNative import com.vayunmathur.library.ui.* import com.vayunmathur.library.util.GameHubComposeHook@@ -33,6 +33,9 @@ class MainActivity : ComponentActivity() {         val worldDir = intent.getStringExtra("world_dir")             ?: java.io.File(filesDir, "worlds/default").apply { mkdirs() }.absolutePath         val worldSeed = intent.getIntExtra("world_seed", 0xB10CCA)+        // The world's directory name is its id (see WorldManager.createWorld). Deriving it here beats+        // widening the Intent contract MenuActivity already has.+        val worldId = java.io.File(worldDir).name         if (VoxelsNative.isAvailable) {             try { VoxelsNative.nativeInit(worldDir, worldSeed) } catch (e: Exception) {                 android.util.Log.e("VoxelsMain", "nativeInit failed", e)@@ -66,13 +69,13 @@ class MainActivity : ComponentActivity() {                 var tradesJson by remember { mutableStateOf("{}") }                 var tradeOpen by remember { mutableStateOf(false) }                 LaunchedEffect(Unit) { if (VoxelsNative.isAvailable) try { recipesJson = VoxelsNative.getRecipesJson(); smeltingJson = VoxelsNative.getSmeltingJson(); blessingCatalogJson = VoxelsNative.getBlessingCatalogJson(); cutsJson = VoxelsNative.getCutsJson() } catch (_: Exception) {} }-                var achievementsManager by remember { mutableStateOf<VoxelsAchievementsManager?>(null) }-                val newAchievement by (achievementsManager?.newAchievement?.collectAsState() ?: remember { mutableStateOf(null) })+                var achievements by remember { mutableStateOf<VoxelsAchievements?>(null) }+                val newAchievement by (achievements?.newAchievement?.collectAsState() ?: remember { mutableStateOf(null) })                  LaunchedEffect(Unit) {                     try {                         val json = assets.open("achievements.json").bufferedReader().readText()-                        achievementsManager = VoxelsAchievementsManager(this@MainActivity, json)+                        achievements = VoxelsAchievements(this@MainActivity, json, worldId)                     } catch (_: Exception) {}                 } @@ -126,36 +129,36 @@ class MainActivity : ComponentActivity() {                                     val placed = obj.optInt("placed", 0)                                     val broken = obj.optInt("broken", 0)                                     val walked = obj.optInt("walked", 0)-                                    achievementsManager?.let { mgr ->-                                        if (broken > 0) mgr.onAchievementUnlocked("first_block")-                                        if (placed > 0) mgr.onAchievementUnlocked("first_place")-                                        mgr.onProgressUpdated("builder_100", placed)-                                        mgr.onProgressUpdated("miner_100", broken)-                                        mgr.onProgressUpdated("explorer_100", walked)-                                        if (obj.optBoolean("night", false)) mgr.onAchievementUnlocked("night_survivor")-                                        if (obj.optInt("depth", 128) <= 8) mgr.onAchievementUnlocked("deep_diver")-                                        if (obj.optBoolean("silver", false)) mgr.onAchievementUnlocked("silver_tongue")-                                        if (obj.optBoolean("steel", false)) mgr.onAchievementUnlocked("steelworker")-                                        if (obj.optBoolean("adamant", false)) mgr.onAchievementUnlocked("alchemist")-                                        if (obj.optBoolean("blessing", false)) mgr.onAchievementUnlocked("blessed")-                                        if (obj.optBoolean("fullArmor", false)) mgr.onAchievementUnlocked("fully_armed")-                                        if (obj.optBoolean("nether", false)) mgr.onAchievementUnlocked("nether_bound")-                                        if (obj.optBoolean("end", false)) mgr.onAchievementUnlocked("the_end")-                                        if (obj.optBoolean("dragon", false)) mgr.onAchievementUnlocked("dragonslayer")-                                        if (obj.optBoolean("wither", false)) mgr.onAchievementUnlocked("withering")-                                        if (obj.optInt("beacon", 0) >= 4) mgr.onAchievementUnlocked("beacon_master")-                                        if (obj.optBoolean("elytra", false)) mgr.onAchievementUnlocked("sky_bound")-                                        if (obj.optBoolean("maxHearts", false)) mgr.onAchievementUnlocked("heart_of_gold")-                                        if (obj.optInt("attuned", 0) > 0) mgr.onAchievementUnlocked("attuned")-                                        if (obj.optInt("attuned", 0) >= 3) mgr.onAchievementUnlocked("pantheon")-                                        if (obj.optBoolean("traded", false)) mgr.onAchievementUnlocked("first_trade")-                                        if (obj.optBoolean("trader", false)) mgr.onAchievementUnlocked("master_trader")-                                        if (obj.optBoolean("sheared", false)) mgr.onAchievementUnlocked("first_shear")-                                        if (obj.optBoolean("fished", false)) mgr.onAchievementUnlocked("first_catch")-                                        if (obj.optBoolean("brushed", false)) mgr.onAchievementUnlocked("first_dig")-                                        if (obj.optBoolean("harvested", false)) mgr.onAchievementUnlocked("first_harvest")-                                        if (obj.optBoolean("rested", false)) mgr.onAchievementUnlocked("first_rest")-                                        mgr.onProgressUpdated("recipes_50", obj.optInt("recipes", 0))+                                    achievements?.let { mgr ->+                                        if (broken > 0) mgr.unlock("first_block")+                                        if (placed > 0) mgr.unlock("first_place")+                                        mgr.progress("builder_100", placed)+                                        mgr.progress("miner_100", broken)+                                        mgr.progress("explorer_100", walked)+                                        if (obj.optBoolean("night", false)) mgr.unlock("night_survivor")+                                        if (obj.optInt("depth", 128) <= 8) mgr.unlock("deep_diver")+                                        if (obj.optBoolean("silver", false)) mgr.unlock("silver_tongue")+                                        if (obj.optBoolean("steel", false)) mgr.unlock("steelworker")+                                        if (obj.optBoolean("adamant", false)) mgr.unlock("alchemist")+                                        if (obj.optBoolean("blessing", false)) mgr.unlock("blessed")+                                        if (obj.optBoolean("fullArmor", false)) mgr.unlock("fully_armed")+                                        if (obj.optBoolean("nether", false)) mgr.unlock("nether_bound")+                                        if (obj.optBoolean("end", false)) mgr.unlock("the_end")+                                        if (obj.optBoolean("dragon", false)) mgr.unlock("dragonslayer")+                                        if (obj.optBoolean("wither", false)) mgr.unlock("withering")+                                        if (obj.optInt("beacon", 0) >= 4) mgr.unlock("beacon_master")+                                        if (obj.optBoolean("elytra", false)) mgr.unlock("sky_bound")+                                        if (obj.optBoolean("maxHearts", false)) mgr.unlock("heart_of_gold")+                                        if (obj.optInt("attuned", 0) > 0) mgr.unlock("attuned")+                                        if (obj.optInt("attuned", 0) >= 3) mgr.unlock("pantheon")+                                        if (obj.optBoolean("traded", false)) mgr.unlock("first_trade")+                                        if (obj.optBoolean("trader", false)) mgr.unlock("master_trader")+                                        if (obj.optBoolean("sheared", false)) mgr.unlock("first_shear")+                                        if (obj.optBoolean("fished", false)) mgr.unlock("first_catch")+                                        if (obj.optBoolean("brushed", false)) mgr.unlock("first_dig")+                                        if (obj.optBoolean("harvested", false)) mgr.unlock("first_harvest")+                                        if (obj.optBoolean("rested", false)) mgr.unlock("first_rest")+                                        mgr.progress("recipes_50", obj.optInt("recipes", 0))                                     }                                 } catch (_: Exception) {}                             } catch (_: Exception) {}@@ -164,7 +167,9 @@ class MainActivity : ComponentActivity() {                     }                 } -                GameHubComposeHook("voxels", achievementsManager)+                // The Hub only ever sees the app-level tier: its contract is (gameId, achievementId)+                // with no room for a world.+                GameHubComposeHook("voxels", achievements?.app)                  Box(Modifier.fillMaxSize()) {                     if (VoxelsNative.isAvailable) {@@ -296,7 +301,7 @@ class MainActivity : ComponentActivity() {                      newAchievement?.let { ach ->                         Box(Modifier.align(Alignment.TopCenter).padding(top = 80.dp)) {-                            AchievementNotification(ach) { achievementsManager?.dismissNotification() }+                            AchievementNotification(ach) { achievements?.dismissNotification() }                         }                     } @@ -304,7 +309,8 @@ class MainActivity : ComponentActivity() {                         InventoryOverlay(                             inventoryJson = inventoryJson, recipesJson = recipesJson,                             blessingsJson = blessingsJson, blessingCatalogJson = blessingCatalogJson,-                            onClose = { inventoryOpen = false }, startTab = invStartTab+                            onClose = { inventoryOpen = false }, startTab = invStartTab,+                            worldAchievements = achievements?.world,                         )                     } 
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.ktindex 181e9d19d1..1f042a24b0 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/InventoryScreen.kt@@ -31,6 +31,7 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.games.voxels.util.VoxelsNative+import com.vayunmathur.library.util.AchievementsManager import com.vayunmathur.library.ui.Text import kotlinx.serialization.json.Json import kotlin.math.roundToInt@@ -41,12 +42,15 @@ private data class DragState(val from: Int, val pos: Offset, val id: Int, val co fun InventoryOverlay(     inventoryJson: String, recipesJson: String, blessingsJson: String, blessingCatalogJson: String,     onClose: () -> Unit, startTab: Int = 0,+    // This world's achievement tier. Null until the manager has loaded from assets.+    worldAchievements: AchievementsManager? = null, ) {     val inv = remember(inventoryJson) {         try { Json { ignoreUnknownKeys = true }.decodeFromString<InventoryState>(inventoryJson) } catch (_: Exception) { InventoryState() }     }     val slots = inv.slots-    var leftTab by remember { mutableStateOf(startTab) }   // 0 Inventory, 1 Outfit, 2 Crafting, 3 Blessings+    // 0 Inventory, 1 Outfit, 2 Crafting, 3 Blessings, 4 Achievements+    var leftTab by remember { mutableStateOf(startTab) }     var catTab by remember { mutableStateOf(0) }     val bounds = remember { mutableStateMapOf<Int, Rect>() }     var drag by remember { mutableStateOf<DragState?>(null) }@@ -67,6 +71,7 @@ fun InventoryOverlay(             Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {                 TabButton(stringResource(R.string.crafting), leftTab == 2) { leftTab = 2 }                 TabButton(stringResource(R.string.blessings), leftTab == 3) { leftTab = 3 }+                TabButton(stringResource(R.string.achievements), leftTab == 4) { leftTab = 4 }                 TabButton(stringResource(R.string.outfit), leftTab == 1) { leftTab = 1 }                 TabButton(stringResource(R.string.inventory), leftTab == 0) { leftTab = 0 }                 Spacer(Modifier.weight(1f))@@ -89,6 +94,7 @@ fun InventoryOverlay(                         }, onDragCancel = { drag = null })                     1 -> OutfitView(inv.armor)                     3 -> BlessingsView(blessingsJson, blessingCatalogJson, slots)+                    4 -> AchievementsView(worldAchievements)                     else -> CraftingTable(recipesJson)                 }             }@@ -442,3 +448,52 @@ private fun OutfitView(armor: List<InvSlot>) {         }     } }++/// This world's achievements. The app-level tier is what the Games Hub shows; this is the one that+/// starts at zero in a new world, which is the whole point of tracking both.+@Composable+private fun AchievementsView(manager: AchievementsManager?) {+    if (manager == null) {+        Text(stringResource(R.string.achievements_unavailable), color = Color.White.copy(0.6f), fontSize = 12.sp)+        return+    }+    val statuses by manager.getAchievementStatuses().collectAsState(initial = emptyList())+    // Earned first, then whatever is closest to being earned.+    val ordered = remember(statuses) {+        statuses.sortedWith(+            compareByDescending<com.vayunmathur.library.util.AchievementStatus> { it.isUnlocked }+                .thenByDescending { it.progress.toFloat() / it.achievement.targetProgress.coerceAtLeast(1) }+        )+    }+    val earned = ordered.count { it.isUnlocked }+    Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(6.dp)) {+        Text(+            stringResource(R.string.achievements_earned, earned, ordered.size),+            color = Color.White.copy(0.75f), fontSize = 13.sp, fontWeight = FontWeight.SemiBold,+        )+        Column(Modifier.fillMaxWidth().weight(1f).verticalScroll(rememberScrollState()),+               verticalArrangement = Arrangement.spacedBy(4.dp)) {+            for (st in ordered) {+                val done = st.isUnlocked+                Row(+                    Modifier.fillMaxWidth().clip(RoundedCornerShape(6.dp))+                        .background(if (done) Color(0xFF2C4A2C) else Color.White.copy(0.06f))+                        .padding(horizontal = 8.dp, vertical = 6.dp),+                    verticalAlignment = Alignment.CenterVertically,+                    horizontalArrangement = Arrangement.spacedBy(8.dp),+                ) {+                    Text(if (done) "\u2713" else "\u00b7", color = Color.White.copy(if (done) 0.9f else 0.35f), fontSize = 14.sp)+                    Column(Modifier.weight(1f)) {+                        Text(st.achievement.name, color = Color.White.copy(if (done) 0.95f else 0.6f), fontSize = 12.sp)+                        Text(st.achievement.description, color = Color.White.copy(0.45f), fontSize = 10.sp)+                    }+                    // Only the counting achievements have anything useful to show here.+                    if (!done && st.achievement.targetProgress > 1) {+                        Text("${st.progress}/${st.achievement.targetProgress}",+                             color = Color.White.copy(0.5f), fontSize = 10.sp)+                    }+                }+            }+        }+    }+}
games/voxels/src/main/java/com/vayunmathur/games/voxels/util/VoxelsAchievementsManager.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/VoxelsAchievementsManager.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/VoxelsAchievementsManager.ktindex f934f087dd..b2d4fe4526 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/VoxelsAchievementsManager.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/VoxelsAchievementsManager.kt@@ -3,6 +3,46 @@ package com.vayunmathur.games.voxels.util import android.content.Context import com.vayunmathur.library.util.AchievementsManager -class VoxelsAchievementsManager(context: Context, json: String) : AchievementsManager(context, json) {+/**+ * Achievements in Voxels exist at two tiers.+ *+ * The **world** tier tracks one save, so a fresh world starts at zero and its counters mean what they+ * say. The **app** tier is "ever, in any world" — that's the one the Games Hub mirrors, and its keys+ * are unprefixed so it is byte-for-byte what every earlier build wrote.+ *+ * Nothing calls the two managers directly; [VoxelsAchievements] forwards to both so the ~30 call+ * sites in MainActivity stay one line each.+ */+class VoxelsAchievementsManager(+    context: Context,+    json: String,+    keyPrefix: String = "",+) : AchievementsManager(context, json, keyPrefix) {     override fun checkExistingAchievements() {} }++class VoxelsAchievements(context: Context, json: String, worldId: String) {+    /** The tier the Games Hub sees. Unprefixed, and shared by every world. */+    val app = VoxelsAchievementsManager(context, json)++    /** This world's own progress, namespaced by its directory name. */+    val world = VoxelsAchievementsManager(context, json, "world_$worldId:")++    /** Toasts come from the world tier: earning something again in a new world is worth showing. */+    val newAchievement get() = world.newAchievement+    fun dismissNotification() = world.dismissNotification()++    fun unlock(id: String) {+        world.onAchievementUnlocked(id)+        app.onAchievementUnlocked(id)+    }++    /**+     * `progress` is stored monotonically, which is what both tiers want: the world tier's counters+     * only ever grow within that world, and the app tier ends up holding the best across all worlds.+     */+    fun progress(id: String, value: Int) {+        world.onProgressUpdated(id, value)+        app.onProgressUpdated(id, value)+    }+}
games/voxels/src/main/java/com/vayunmathur/games/voxels/util/WorldManager.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/WorldManager.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/WorldManager.ktindex 62caae9151..8a3914d681 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/WorldManager.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/util/WorldManager.kt@@ -1,6 +1,9 @@ package com.vayunmathur.games.voxels.util  import android.content.Context+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launch import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import java.io.File@@ -77,5 +80,10 @@ object WorldManager {      fun deleteWorld(ctx: Context, id: String) {         File(worldsRoot(ctx), id).deleteRecursively()+        // The world's achievement tier lives in the app-wide DataStore rather than in its directory,+        // so it has to be dropped by hand or it outlives the world forever.+        val json = ctx.assets.open("achievements.json").bufferedReader().use { it.readText() }+        val tier = VoxelsAchievementsManager(ctx, json, "world_$id:")+        CoroutineScope(Dispatchers.IO).launch { tier.forgetAll() }     } }
games/voxels/src/main/res/values/strings.xml
diff --git a/games/voxels/src/main/res/values/strings.xml b/games/voxels/src/main/res/values/strings.xmlindex 0fe6675f62..1b40f9ecc5 100644--- a/games/voxels/src/main/res/values/strings.xml+++ b/games/voxels/src/main/res/values/strings.xml@@ -26,6 +26,9 @@     <string name="villager_tier">Tier %1$d</string>     <string name="recipes_show_locked">Show locked</string>     <string name="recipe_requires">Requires: craft %1$s first</string>+    <string name="achievements">Awards</string>+    <string name="achievements_earned">%1$d of %2$d earned in this world</string>+    <string name="achievements_unavailable">Awards are still loading.</string>     <string name="seed_2">Seed: %1$s  •  %2$s</string>     <string name="estus">Estus ×%1$s</string>     <string name="down">Down</string>
library/src/main/java/com/vayunmathur/library/util/AchievementsManager.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/AchievementsManager.kt b/library/src/main/java/com/vayunmathur/library/util/AchievementsManager.ktindex f42a02dea1..90a68fbabb 100644--- a/library/src/main/java/com/vayunmathur/library/util/AchievementsManager.kt+++ b/library/src/main/java/com/vayunmathur/library/util/AchievementsManager.kt@@ -14,11 +14,26 @@ import kotlinx.serialization.json.Json  private val achievementsJson = Json { ignoreUnknownKeys = true } -abstract class AchievementsManager(val context: Context, jsonContent: String) {+/**+ * Tracks achievement unlocks and progress in the app-wide DataStore.+ *+ * [keyPrefix] namespaces the stored keys. The default empty prefix is the app-level tier — the one the+ * Games Hub mirrors — so every existing game keeps writing exactly the keys it always has. A game with+ * multiple saves can additionally construct one manager per save with a prefix, giving each its own+ * independent progress without touching the app-level totals.+ */+abstract class AchievementsManager(+    val context: Context,+    jsonContent: String,+    private val keyPrefix: String = "",+) {     protected val ds = DataStoreUtils.getInstance(context)     val achievements: List<Achievement> =         achievementsJson.decodeFromString(ListSerializer(Achievement.serializer()), jsonContent) +    private val unlockedKey get() = "${keyPrefix}achievements_unlocked"+    private fun progressKey(id: String) = "${keyPrefix}achievement_progress_$id"+     private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)      private val _newAchievement = MutableStateFlow<Achievement?>(null)@@ -29,7 +44,7 @@ abstract class AchievementsManager(val context: Context, jsonContent: String) {     fun onAchievementUnlocked(id: String) {         val achievement = achievements.find { it.id == id } ?: return         scope.launch {-            if (ds.addStringToSetIfAbsent("achievements_unlocked", id)) {+            if (ds.addStringToSetIfAbsent(unlockedKey, id)) {                 _newAchievement.value = achievement             }         }@@ -38,7 +53,7 @@ abstract class AchievementsManager(val context: Context, jsonContent: String) {     fun onProgressUpdated(id: String, progress: Int) {         val achievement = achievements.find { it.id == id } ?: return         scope.launch {-            if (ds.setLongIfGreater("achievement_progress_$id", progress.toLong()) &&+            if (ds.setLongIfGreater(progressKey(id), progress.toLong()) &&                 progress >= achievement.targetProgress             ) {                 onAchievementUnlocked(id)@@ -47,8 +62,8 @@ abstract class AchievementsManager(val context: Context, jsonContent: String) {     }      fun getAchievementStatuses(): Flow<List<AchievementStatus>> {-        val unlockedFlow = ds.stringSetFlow("achievements_unlocked")-        val progressFlows = achievements.map { ds.longFlow("achievement_progress_${it.id}", 0L) }+        val unlockedFlow = ds.stringSetFlow(unlockedKey)+        val progressFlows = achievements.map { ds.longFlow(progressKey(it.id), 0L) }         return combine(unlockedFlow, combine(progressFlows) { it }) { unlocked, progresses ->             achievements.mapIndexed { index, achievement ->                 AchievementStatus(@@ -63,4 +78,9 @@ abstract class AchievementsManager(val context: Context, jsonContent: String) {     fun dismissNotification() {         _newAchievement.value = null     }++    /** Forget everything stored under [keyPrefix]. Used when the save it belongs to is deleted. */+    suspend fun forgetAll() {+        ds.removeKeys(listOf(unlockedKey) + achievements.map { progressKey(it.id) })+    } }
library/src/main/java/com/vayunmathur/library/util/DataStoreUtils.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/DataStoreUtils.kt b/library/src/main/java/com/vayunmathur/library/util/DataStoreUtils.ktindex 5a35f7e9be..010ed4e735 100644--- a/library/src/main/java/com/vayunmathur/library/util/DataStoreUtils.kt+++ b/library/src/main/java/com/vayunmathur/library/util/DataStoreUtils.kt@@ -182,6 +182,19 @@ class DataStoreUtils private constructor(context: Context) {         }     } +    /**+     * Drop [names] entirely, whatever type they hold. Deleting the thing a namespaced key belongs to+     * has to delete the key too, or the store grows a tail of state nothing can ever reach again.+     */+    suspend fun removeKeys(names: Collection<String>) {+        dataStore.edit { prefs ->+            for (name in names) {+                prefs.remove(stringSetPreferencesKey(name))+                prefs.remove(longPreferencesKey(name))+            }+        }+    }+     fun getBoolean(string: String, bool: Boolean): Boolean {         return getWithFallback(booleanPreferencesKey(string)) ?: bool     }