Updated on 2026-08-14
This commit is contained in:
commit
6d0b295ca3
219 changed files with 3720 additions and 1687 deletions
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.tangem.datasource"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ internal object AppPreferencesStoreModule {
|
|||
fun provideAppPreferencesStore(
|
||||
@ApplicationContext appContext: Context,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
@NetworkMoshi moshi: Moshi,
|
||||
@SdkMoshi moshi: Moshi,
|
||||
): AppPreferencesStore {
|
||||
return AppPreferencesStore(
|
||||
preferencesDataStore = PreferencesDataStore.getInstance(context = appContext, dispatcher = dispatchers.io),
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class AppPreferencesStore(
|
|||
* @see getObjectList
|
||||
* */
|
||||
inline fun <reified T> MutablePreferences.getObject(key: Preferences.Key<String>): T? {
|
||||
val adapter = moshi.adapter(T::class.java) // TODO: Support parameterized types
|
||||
val adapter = moshi.adapter(T::class.java)
|
||||
return this[key]?.let(adapter::fromJson)
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +55,15 @@ class AppPreferencesStore(
|
|||
return this[key]?.let(adapter::fromJson)
|
||||
}
|
||||
|
||||
/** Get list of data [T] by string [key] or default */
|
||||
inline fun <reified T> MutablePreferences.getObjectListOrDefault(
|
||||
key: Preferences.Key<String>,
|
||||
default: List<T>,
|
||||
): List<T> {
|
||||
val adapter = moshi.adapter<List<T>>(Types.newParameterizedType(List::class.java, T::class.java))
|
||||
return this[key]?.let(adapter::fromJson) ?: default
|
||||
}
|
||||
|
||||
/** Get map with [String] key and value [V] by string [key] from [MutablePreferences] */
|
||||
inline fun <reified V> MutablePreferences.getObjectMap(key: Preferences.Key<String>): Map<String, V>? {
|
||||
val type = Types.newParameterizedType(Map::class.java, String::class.java, V::class.java)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package com.tangem.datasource.local.preferences
|
|||
import androidx.datastore.preferences.core.*
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.APP_LAUNCH_COUNT_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.FUNDS_FOUND_DATE_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.SAVE_USER_WALLETS_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.SHOW_RATING_DIALOG_AT_LAUNCH_COUNT_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.USED_CARDS_INFO_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.USER_WAS_INTERACT_WITH_RATING_KEY
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.WAS_TWINS_ONBOARDING_SHOWN
|
||||
|
||||
/**
|
||||
* All preferences keys that DataStore<Preferences> is stored.
|
||||
|
|
@ -54,6 +56,12 @@ object PreferencesKeys {
|
|||
}
|
||||
|
||||
val FEATURE_TOGGLES_KEY by lazy { stringPreferencesKey(name = "featureToggles") }
|
||||
|
||||
val WAS_TWINS_ONBOARDING_SHOWN by lazy { booleanPreferencesKey(name = "twinsOnboardingShown") }
|
||||
|
||||
val IS_TANGEM_TOS_ACCEPTED_KEY by lazy { booleanPreferencesKey(name = "tangem_tos_accepted") }
|
||||
|
||||
fun getStart2CoinTOSAcceptedKey(region: String?) = booleanPreferencesKey(name = "start2Coin_tos_accepted_$region")
|
||||
}
|
||||
|
||||
/** Preferences keys set that should be migrated from "PreferencesDataSource" to a new DataStore<Preferences> */
|
||||
|
|
@ -65,6 +73,8 @@ internal fun getTapPrefKeysToMigrate(): Set<String> {
|
|||
FUNDS_FOUND_DATE_KEY,
|
||||
USER_WAS_INTERACT_WITH_RATING_KEY,
|
||||
USED_CARDS_INFO_KEY,
|
||||
WAS_TWINS_ONBOARDING_SHOWN,
|
||||
IS_TANGEM_TOS_ACCEPTED_KEY,
|
||||
)
|
||||
.map(Preferences.Key<*>::name)
|
||||
.toSet()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue