mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Library store pills follow the new default store order (#2811)
* fix(library): move an unarranged store order to the new default at startup * fix(stores): forget an unarranged store order instead of saving the default
This commit is contained in:
1 parent
c1cf0f3a9c
commit
c336f994e1
4 files changed
+61
-12
No files matched your search
@@ -53,6 +53,7 @@ class App : Application() {
|
||||
com.droiddeck.launcher.session.QuestExperimental.initialize(this)
|
||||
com.droiddeck.launcher.session.SessionPrefs.applyNtsyncDefault(this)
|
||||
com.droiddeck.launcher.session.SessionPrefs.settleGpuDriverMode(this)
|
||||
com.droiddeck.launcher.session.SessionPrefs.settleStoresTabOrder(this, com.droiddeck.launcher.stores.Store.entries.map { it.id })
|
||||
com.droiddeck.launcher.update.AppUpdates.init(this)
|
||||
com.droiddeck.launcher.update.UpdateWatch.sync(this, com.droiddeck.launcher.update.AppUpdates.follow(this, null))
|
||||
com.droiddeck.launcher.core.DownloadSource.init(this)
|
||||
|
||||
@@ -315,6 +315,20 @@ object SessionPrefs {
|
||||
|
||||
fun storesTabOrder(context: Context): List<String> = idList(prefs(context).getString("storesTabOrder", null))
|
||||
|
||||
private val LEGACY_STORES_TAB_ORDER = listOf("gog", "epic", "amazon", "xbox", "itch", "gamejolt", "battlenet", "ubisoft", "ea", "rockstar")
|
||||
|
||||
/**
|
||||
* Forgets an order the user never arranged, so the Stores tabs and Library pills follow whatever the default is now.
|
||||
* Earlier versions saved the default of their day, which is why a saved order alone does not mean the user chose it.
|
||||
*/
|
||||
fun settleStoresTabOrder(context: Context, defaults: List<String>) {
|
||||
if (storesTabOrderCustomized(context)) return
|
||||
val saved = storesTabOrder(context)
|
||||
if (saved.isEmpty()) return
|
||||
if (saved == LEGACY_STORES_TAB_ORDER || saved == defaults) prefs(context).edit().remove("storesTabOrder").apply()
|
||||
else setStoresTabOrderCustomized(context, true)
|
||||
}
|
||||
|
||||
fun setStoresTabOrder(context: Context, order: List<String>) {
|
||||
prefs(context).edit().putString("storesTabOrder", order.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
@@ -155,18 +155,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
|
||||
val padH = if (narrow) 14.dp else 22.dp
|
||||
val tabs = remember {
|
||||
androidx.compose.runtime.mutableStateListOf<StoreTab>().apply {
|
||||
val savedOrder = SessionPrefs.storesTabOrder(ctx)
|
||||
if (!SessionPrefs.storesTabOrderCustomized(ctx)) {
|
||||
val legacyOrder = listOf(
|
||||
"gog", "epic", "amazon", "xbox", "itch",
|
||||
"gamejolt", "battlenet", "ubisoft", "ea", "rockstar"
|
||||
)
|
||||
if (savedOrder.isNotEmpty() && savedOrder != legacyOrder) {
|
||||
SessionPrefs.setStoresTabOrderCustomized(ctx, true)
|
||||
} else {
|
||||
SessionPrefs.setStoresTabOrder(ctx, Store.entries.map { it.id })
|
||||
}
|
||||
}
|
||||
SessionPrefs.settleStoresTabOrder(ctx, Store.entries.map { it.id })
|
||||
addAll(arrangeStoreTabs(SessionPrefs.storesTabOrder(ctx), SessionPrefs.storesTabHidden(ctx)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.arrangeStoreTabs
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class StoresTabOrderTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private val defaults = Store.entries.map { it.id }
|
||||
private fun shown() = arrangeStoreTabs(SessionPrefs.storesTabOrder(app), emptySet()).map { it.store.id }
|
||||
|
||||
@Test
|
||||
fun anOldDefaultOrderMovesToTheCurrentOne() {
|
||||
SessionPrefs.setStoresTabOrder(app, listOf("gog", "epic", "amazon", "xbox", "itch", "gamejolt", "battlenet", "ubisoft", "ea", "rockstar"))
|
||||
SessionPrefs.settleStoresTabOrder(app, defaults)
|
||||
assertEquals(defaults, shown())
|
||||
assertFalse(SessionPrefs.storesTabOrderCustomized(app))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSavedCurrentDefaultIsNotMistakenForTheUsersOwn() {
|
||||
SessionPrefs.setStoresTabOrder(app, defaults)
|
||||
repeat(2) { SessionPrefs.settleStoresTabOrder(app, defaults) }
|
||||
assertFalse(SessionPrefs.storesTabOrderCustomized(app))
|
||||
assertTrue(SessionPrefs.storesTabOrder(app).isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anArrangedOrderIsKept() {
|
||||
val mine = defaults.reversed()
|
||||
SessionPrefs.setStoresTabOrder(app, mine)
|
||||
SessionPrefs.settleStoresTabOrder(app, defaults)
|
||||
assertTrue(SessionPrefs.storesTabOrderCustomized(app))
|
||||
assertEquals(mine, shown())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user