Updated on 2026-08-14
This commit is contained in:
parent
baaa317381
commit
ca51d6803a
13 changed files with 198 additions and 36 deletions
|
|
@ -102,13 +102,16 @@ class AppRatingLaunchObserver(
|
|||
private val K_FUNDS_FOUND_DATE = "fundsFoundDate"
|
||||
private val K_USER_WAS_INTERACT_WITH_RATING = "userWasInteractWithRating"
|
||||
|
||||
private val FUNDS_FOUND_DATE_UNDEFINED = -1L
|
||||
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 }
|
||||
val msWhenFundsWasFound = preferences.getLong(K_FUNDS_FOUND_DATE, FUNDS_FOUND_DATE_UNDEFINED)
|
||||
if (msWhenFundsWasFound != FUNDS_FOUND_DATE_UNDEFINED) {
|
||||
fundsFoundDate = Calendar.getInstance().apply { timeInMillis = msWhenFundsWasFound }
|
||||
}
|
||||
}
|
||||
|
||||
fun foundWalletWithFunds() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.tangem.tap.persistence
|
|||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.tap.common.extensions.replaceBy
|
||||
import com.tangem.tap.common.extensions.replaceByOrAdd
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
|
|
@ -48,18 +48,14 @@ class UsedCardsPrefStorage(
|
|||
return findCardInfo(cardId)?.isActivationStarted ?: false
|
||||
}
|
||||
|
||||
fun activate(cardId: String) {
|
||||
fun activationFinished(cardId: String) {
|
||||
val restoredList = restore()
|
||||
val foundItem = findCardInfo(cardId, restoredList)?.copy(isActivated = true)
|
||||
?: UsedCardInfo(cardId, isActivated = true)
|
||||
val foundItem = findCardInfo(cardId, restoredList)?.copy(isActivationStarted = false)
|
||||
?: UsedCardInfo(cardId, isActivationStarted = false)
|
||||
|
||||
save(foundItem, restoredList)
|
||||
}
|
||||
|
||||
fun wasActivated(cardId: String): Boolean {
|
||||
return findCardInfo(cardId)?.isActivated ?: false
|
||||
}
|
||||
|
||||
private fun findCardInfo(cardId: String, list: MutableList<UsedCardInfo>? = null): UsedCardInfo? {
|
||||
val findInList = list ?: restore()
|
||||
return findInList.firstOrNull { it.cardId == cardId }
|
||||
|
|
@ -68,7 +64,7 @@ class UsedCardsPrefStorage(
|
|||
private fun save(usedCardInfo: UsedCardInfo?, usedCardsInfo: MutableList<UsedCardInfo>) {
|
||||
val info = usedCardInfo ?: return
|
||||
|
||||
usedCardsInfo.replaceBy(info) { it.cardId == info.cardId }
|
||||
usedCardsInfo.replaceByOrAdd(info) { it.cardId == info.cardId }
|
||||
save(usedCardsInfo)
|
||||
}
|
||||
|
||||
|
|
@ -86,13 +82,13 @@ class UsedCardsPrefStorage(
|
|||
private fun restore(): MutableList<UsedCardInfo> {
|
||||
val json = preferences.getString(USED_CARDS_INFO, null) ?: return mutableListOf()
|
||||
return try {
|
||||
jsonConverter.fromJson(json)!!
|
||||
jsonConverter.fromJson(json, jsonConverter.typedList(UsedCardInfo::class.java))!!
|
||||
} catch (ex: Exception) {
|
||||
preferences.edit(true) { remove(USED_CARDS_INFO) }
|
||||
mutableListOf()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
private const val USED_CARDS_INFO = "usedCardsInfo"
|
||||
private const val SCANNED_CARDS_IDS_KEY = "scannedCardIds"
|
||||
|
|
@ -103,5 +99,4 @@ private data class UsedCardInfo(
|
|||
val cardId: String,
|
||||
val isScanned: Boolean = false,
|
||||
val isActivationStarted: Boolean = false,
|
||||
val isActivated: Boolean = false,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue