Updated on 2026-08-14
This commit is contained in:
parent
3f1102f232
commit
6af3bb18e4
7 changed files with 65 additions and 6 deletions
|
|
@ -65,11 +65,11 @@ class AppPreferencesStore(
|
|||
}
|
||||
|
||||
/** 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>? {
|
||||
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)
|
||||
val adapter = moshi.adapter<Map<String, V>>(type)
|
||||
|
||||
return this[key]?.let(adapter::fromJson)
|
||||
return this[key]?.let(adapter::fromJson).orEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ object PreferencesKeys {
|
|||
|
||||
val IS_TANGEM_TOS_ACCEPTED_KEY by lazy { booleanPreferencesKey(name = "tangem_tos_accepted") }
|
||||
|
||||
val APP_LOGS_KEY by lazy { stringPreferencesKey(name = "app_logs") }
|
||||
|
||||
fun getStart2CoinTOSAcceptedKey(region: String?) = booleanPreferencesKey(name = "start2Coin_tos_accepted_$region")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,15 @@ dependencies {
|
|||
|
||||
implementation(deps.androidx.datastore)
|
||||
|
||||
/** DI */
|
||||
// region DI
|
||||
implementation(deps.hilt.android)
|
||||
kapt(deps.hilt.kapt)
|
||||
// endregion
|
||||
|
||||
// region Others dependencies
|
||||
implementation(deps.jodatime)
|
||||
implementation(deps.kotlin.coroutines)
|
||||
implementation(deps.moshi)
|
||||
implementation(deps.moshi.kotlin)
|
||||
// endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@ package com.tangem.data.settings
|
|||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectMap
|
||||
import com.tangem.datasource.local.preferences.utils.getSyncOrDefault
|
||||
import com.tangem.datasource.local.preferences.utils.store
|
||||
import com.tangem.domain.settings.models.AppLogsModel
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.joda.time.DateTime
|
||||
|
||||
internal class DefaultSettingsRepository(
|
||||
private val preferencesDataSource: PreferencesDataSource,
|
||||
|
|
@ -32,4 +35,38 @@ internal class DefaultSettingsRepository(
|
|||
value = isEnabled,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun getAppLogs(): List<AppLogsModel> {
|
||||
return appPreferencesStore.getObjectMap<String>(key = PreferencesKeys.APP_LOGS_KEY)
|
||||
.map { AppLogsModel(timestamp = it.key.toLong(), message = it.value) }
|
||||
}
|
||||
|
||||
override suspend fun updateAppLogs(message: String) {
|
||||
val newLogs = DateTime.now().millis.toString() to message
|
||||
|
||||
appPreferencesStore.editData { preferences ->
|
||||
val savedLogs = preferences.getObjectMap<String>(PreferencesKeys.APP_LOGS_KEY)
|
||||
|
||||
preferences.setObjectMap(key = PreferencesKeys.APP_LOGS_KEY, value = savedLogs + newLogs)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteDeprecatedLogs() {
|
||||
val threeDaysAgo = getThreeDaysAgoTimestamp()
|
||||
|
||||
appPreferencesStore.editData { preferences ->
|
||||
val savedLogs = preferences.getObjectMap<String>(PreferencesKeys.APP_LOGS_KEY)
|
||||
|
||||
preferences.setObjectMap(
|
||||
key = PreferencesKeys.APP_LOGS_KEY,
|
||||
value = savedLogs.filterKeys { it.toLong() > threeDaysAgo },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getThreeDaysAgoTimestamp(): Long = DateTime.now().minusDays(THREE_DAYS).millis
|
||||
|
||||
private companion object {
|
||||
const val THREE_DAYS = 3
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
package com.tangem.domain.settings.models
|
||||
|
||||
data class AppLogsModel(val timestamp: Long, val message: String)
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.domain.settings.repositories
|
||||
|
||||
import com.tangem.domain.settings.models.AppLogsModel
|
||||
|
||||
interface SettingsRepository {
|
||||
|
||||
suspend fun shouldShowSaveUserWalletScreen(): Boolean
|
||||
|
|
@ -7,4 +9,13 @@ interface SettingsRepository {
|
|||
suspend fun isWalletScrollPreviewEnabled(): Boolean
|
||||
|
||||
suspend fun setWalletScrollPreviewAvailability(isEnabled: Boolean)
|
||||
|
||||
@Throws
|
||||
suspend fun getAppLogs(): List<AppLogsModel>
|
||||
|
||||
@Throws
|
||||
suspend fun updateAppLogs(message: String)
|
||||
|
||||
@Throws
|
||||
suspend fun deleteDeprecatedLogs()
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ class DefaultSwapTransactionRepository(
|
|||
key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY,
|
||||
)
|
||||
|
||||
val updatesMap = savedMap?.toMutableMap() ?: mutableMapOf()
|
||||
val updatesMap = savedMap.toMutableMap()
|
||||
updatesMap[txId] = status
|
||||
|
||||
mutablePreferences.setObjectMap(
|
||||
|
|
@ -232,9 +232,9 @@ class DefaultSwapTransactionRepository(
|
|||
val savedList = mutablePreferences.getObjectMap<ExchangeStatusModel>(
|
||||
key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY,
|
||||
)
|
||||
val editedList = savedList?.filterNot { it.key == txId }
|
||||
val editedList = savedList.filterNot { it.key == txId }
|
||||
|
||||
if (editedList.isNullOrEmpty()) {
|
||||
if (editedList.isEmpty()) {
|
||||
mutablePreferences.remove(key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY)
|
||||
} else {
|
||||
mutablePreferences.setObjectMap(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue