Updated on 2026-08-14

This commit is contained in:
Tangem 2020-04-14 17:44:29 +03:00
parent 0ef866f5da
commit 6a7d67e0c0
3 changed files with 8 additions and 5 deletions

View file

@ -11,6 +11,6 @@ interface Store<M> {
interface KeyedStore<M> {
fun save(key: String, value: M)
fun restore(key: String): M
fun restoreAll(): Map<String, M>
fun restoreAll(): MutableMap<String, M>
fun delete(key: String)
}

View file

@ -11,8 +11,11 @@ import com.tangem.tangemtest.ucase.variants.personalize.dto.PersonalizationConfi
class PersonalizationConfigStore(context: Context) : Store<PersonalizationConfig>, KeyedStore<PersonalizationConfig> {
companion object {
val defaultKey = "default"
}
private val sharedPreferencesKey = "personalization_presets"
private val defaultKey = "default"
private val sp: SharedPreferences = (context.applicationContext as AppTangemDemo).sharedPreferences(sharedPreferencesKey)
private val gson: Gson = Gson()
@ -32,7 +35,7 @@ class PersonalizationConfigStore(context: Context) : Store<PersonalizationConfig
return fromJson(json!!)
}
override fun restoreAll(): Map<String, PersonalizationConfig> {
override fun restoreAll(): MutableMap<String, PersonalizationConfig> {
val map = mutableMapOf<String, PersonalizationConfig>()
sp.all.forEach { map[it.key] = fromJson(it.value as String) }
return map.toSortedMap()

View file

@ -21,13 +21,13 @@ class PersonalizationPresetManager(
fun loadPreset() {
val presets = store.restoreAll()
presets.remove(PersonalizationConfigStore.defaultKey)
val namesList = presets.map { it.key }.toMutableList()
if (namesList.size <= 1) {
if (namesList.isEmpty()) {
view.showSnackbar(R.string.error_nothing_to_load)
return
}
namesList.removeAt(0)
view.showLoadPresetDialog(namesList, {
val converter = PersonalizationConfigConverter()
val config = store.restore(it)