Updated on 2026-08-14
This commit is contained in:
parent
ecb012fd1b
commit
da27e05e0f
1 changed files with 13 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package com.tangem.tap.persistence
|
|||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
|
|
@ -18,6 +19,10 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
applicationContext.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
init {
|
||||
incrementLaunchCounter()
|
||||
}
|
||||
|
||||
private val fiatCurrenciesAdapter: JsonAdapter<List<FiatCurrency>> by lazy {
|
||||
val moshi = Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
|
|
@ -51,6 +56,8 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
return isFirst
|
||||
}
|
||||
|
||||
fun getCountOfLaunches(): Int = preferences.getInt(APP_LAUNCH_COUNT_KEY, 1)
|
||||
|
||||
fun saveScannedCardId(cardId: String) {
|
||||
val scannedCardsIds: String = restoreScannedCardIds()
|
||||
if (!scannedCardsIds.contains(cardId)) {
|
||||
|
|
@ -65,7 +72,6 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
private fun restoreScannedCardIds(): String =
|
||||
preferences.getString(SCANNED_CARDS_IDS_KEY, "") ?: ""
|
||||
|
||||
|
||||
fun saveDisclaimerAccepted() {
|
||||
preferences.edit().putBoolean(DISCLAIMER_ACCEPTED_KEY, true).apply()
|
||||
}
|
||||
|
|
@ -74,6 +80,11 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
return preferences.getBoolean(DISCLAIMER_ACCEPTED_KEY, false)
|
||||
}
|
||||
|
||||
private fun incrementLaunchCounter() {
|
||||
var count = preferences.getInt(APP_LAUNCH_COUNT_KEY, 0)
|
||||
preferences.edit { putInt(APP_LAUNCH_COUNT_KEY, ++count) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREFERENCES_NAME = "tapPrefs"
|
||||
private const val APP_CURRENCY_KEY = "appCurrency"
|
||||
|
|
@ -81,6 +92,7 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
private const val FIRST_LAUNCH_CHECK_KEY = "firstLaunchCheck"
|
||||
private const val SCANNED_CARDS_IDS_KEY = "scannedCardIds"
|
||||
private const val DISCLAIMER_ACCEPTED_KEY = "disclaimerAccepted"
|
||||
private const val APP_LAUNCH_COUNT_KEY = "launchCount"
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue