diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt index 987e3c1b3b..586051a676 100644 --- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt @@ -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 -> { diff --git a/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt b/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt index 47f832dbac..6ce4249585 100644 --- a/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt +++ b/app/src/main/java/com/tangem/tap/persistence/PreferencesStorage.kt @@ -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> 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" } } \ No newline at end of file