Updated on 2026-08-14

This commit is contained in:
Tangem 2021-03-10 17:50:03 +03:00
parent a5b7aab659
commit e40faeace0
2 changed files with 41 additions and 11 deletions

View file

@ -11,6 +11,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.tangem.tap.common.entities.TapCurrency.Companion.DEFAULT_FIAT_CURRENCY
import com.tangem.tap.common.redux.global.FiatCurrencyName
import com.tangem.tap.network.coinmarketcap.FiatCurrency
import java.util.*
class PreferencesStorage(applicationContext: Application) {
@ -104,16 +105,34 @@ class AppRatingLaunchObserver(
private val preferences: SharedPreferences,
private val launchCounts: Int,
) {
private val K_SHOW_RATING_DIALOG = "show_rating_dialog_after_app_launch_count"
private val K_SHOW_RATING_AT_LAUNCH_COUNT = "showRatingDialogAtLaunchCount"
private val K_FUNDS_FOUND_DATE = "aFundsFoundDate"
private val deferShowing = 20
private val firstShowing = 3
private var fundsFoundDate: Calendar? = null
init {
val dateTimeMs = preferences.getLong(K_FUNDS_FOUND_DATE, -1)
if (dateTimeMs > 0) fundsFoundDate = Calendar.getInstance().apply { timeInMillis = dateTimeMs }
}
fun foundWalletWithFunds() {
if (fundsFoundDate != null) return
fundsFoundDate = Calendar.getInstance()
preferences.edit().putLong(K_FUNDS_FOUND_DATE, fundsFoundDate!!.timeInMillis).apply()
updateNextShowing(launchCounts + firstShowing)
}
fun isReadyToShow(): Boolean {
if (launchCounts == firstShowing) return true
val fundsDate = fundsFoundDate ?: return false
val nextShowingAt = getCounterOfNextShowing()
return launchCounts >= nextShowingAt
val diff = Calendar.getInstance().timeInMillis - fundsDate.timeInMillis
val diffInDays = diff / (100 * 60 * 60 * 24)
if (diffInDays >= firstShowing) return true
return launchCounts >= getCounterOfNextShowing()
}
fun applyDelayedShowing() {
@ -125,10 +144,10 @@ class AppRatingLaunchObserver(
}
private fun updateNextShowing(at: Int) {
preferences.edit().putInt(K_SHOW_RATING_DIALOG, at).apply()
preferences.edit().putInt(K_SHOW_RATING_AT_LAUNCH_COUNT, at).apply()
}
private fun getCounterOfNextShowing(): Int {
return preferences.getInt(K_SHOW_RATING_DIALOG, firstShowing)
return preferences.getInt(K_SHOW_RATING_AT_LAUNCH_COUNT, firstShowing)
}
}