Updated on 2026-08-14

This commit is contained in:
Tangem 2020-11-18 10:20:37 +00:00
commit ae2d88274e
2 changed files with 13 additions and 7 deletions

View file

@ -25,7 +25,7 @@ class HomeMiddleware {
when (action) {
is HomeAction.CheckIfFirstLaunch -> {
store.dispatch(
HomeAction.CheckIfFirstLaunch.Result(preferencesStorage.isFirstLaunch())
HomeAction.CheckIfFirstLaunch.Result(preferencesStorage.getCountOfLaunches() == 1)
)
}
is HomeAction.ReadCard -> {

View file

@ -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())
@ -45,11 +50,7 @@ class PreferencesStorage(applicationContext: Application) {
return preferences.edit().putString(FIAT_CURRENCIES_KEY, json).apply()
}
fun isFirstLaunch(): Boolean {
val isFirst = !preferences.contains(FIRST_LAUNCH_CHECK_KEY)
if (isFirst) preferences.edit().putInt(FIRST_LAUNCH_CHECK_KEY, System.currentTimeMillis().toInt()).apply()
return isFirst
}
fun getCountOfLaunches(): Int = preferences.getInt(APP_LAUNCH_COUNT_KEY, 1)
fun saveScannedCardId(cardId: String) {
val scannedCardsIds: String = restoreScannedCardIds()
@ -65,7 +66,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 +74,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 +86,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"
}
}