Updated on 2026-08-14
This commit is contained in:
commit
9488319315
29 changed files with 110 additions and 366 deletions
|
|
@ -80,24 +80,10 @@ internal class DefaultCardRepository(
|
|||
return appPreferencesStore.getSyncOrDefault(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, default = false)
|
||||
}
|
||||
|
||||
override suspend fun isStart2CoinTOSAccepted(cardId: String): Boolean {
|
||||
return appPreferencesStore.getSyncOrDefault(
|
||||
key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)),
|
||||
default = false,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun acceptTangemTOS() {
|
||||
return appPreferencesStore.store(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, true)
|
||||
}
|
||||
|
||||
override suspend fun acceptStart2CoinTOS(cardId: String) {
|
||||
appPreferencesStore.store(
|
||||
key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)),
|
||||
value = true,
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun AppPreferencesStore.editUsedCards(cardId: String, update: (UsedCardInfo) -> UsedCardInfo) {
|
||||
editData { mutablePreferences ->
|
||||
val usedCards = mutablePreferences.getUsedCards()
|
||||
|
|
@ -127,16 +113,5 @@ internal class DefaultCardRepository(
|
|||
.firstOrNull { it.cardId == cardId }
|
||||
}
|
||||
|
||||
private fun getRegion(cardId: String): String? {
|
||||
if (cardId.isEmpty()) return null
|
||||
|
||||
return when (cardId[1]) {
|
||||
'0' -> "fr"
|
||||
'1' -> "ch"
|
||||
'2' -> "at"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDefaultUsedCardInfo(cardId: String) = UsedCardInfo(cardId = cardId)
|
||||
}
|
||||
|
|
@ -1,11 +1,6 @@
|
|||
package com.tangem.data.settings
|
||||
|
||||
import android.os.SystemClock
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.getIsFirstTimeAskingPermission
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.getPermissionDaysCount
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.getPermissionLaunchCount
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.getShouldShowInitialPermissionScreen
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys.getShouldShowPermission
|
||||
import com.tangem.datasource.local.preferences.utils.getSyncOrDefault
|
||||
|
|
@ -30,47 +25,11 @@ internal class DefaultPermissionRepository(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun isFirstTimeAskingPermission(permission: String): Boolean =
|
||||
appPreferencesStore.getSyncOrDefault(
|
||||
key = getIsFirstTimeAskingPermission(permission),
|
||||
default = true,
|
||||
)
|
||||
|
||||
override suspend fun setFirstTimeAskingPermission(permission: String, value: Boolean) {
|
||||
appPreferencesStore.store(
|
||||
key = getIsFirstTimeAskingPermission(permission),
|
||||
value = value,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun shouldAskPermission(permission: String): Boolean {
|
||||
val shouldAskPermission = appPreferencesStore.getSyncOrDefault(getShouldShowPermission(permission), true)
|
||||
val delayedLaunches = appPreferencesStore.getSyncOrDefault(getPermissionLaunchCount(permission), 0)
|
||||
val delayedDays = appPreferencesStore.getSyncOrDefault(getPermissionDaysCount(permission), 0)
|
||||
val currentLaunchCounter = appPreferencesStore.getSyncOrDefault(PreferencesKeys.APP_LAUNCH_COUNT_KEY, 0)
|
||||
|
||||
val nowMillis = SystemClock.elapsedRealtime()
|
||||
val isDaysDelayed = delayedDays < nowMillis
|
||||
val isLaunchesDelayed = delayedLaunches < currentLaunchCounter
|
||||
return shouldAskPermission && isDaysDelayed && isLaunchesDelayed
|
||||
return appPreferencesStore.getSyncOrDefault(getShouldShowPermission(permission), true)
|
||||
}
|
||||
|
||||
override suspend fun neverAskPermission(permission: String) {
|
||||
appPreferencesStore.store(key = getShouldShowPermission(permission), value = false)
|
||||
}
|
||||
|
||||
override suspend fun delayPermissionAsking(permission: String) {
|
||||
appPreferencesStore.editData {
|
||||
val appLaunchCounter = it.getOrDefault(PreferencesKeys.APP_LAUNCH_COUNT_KEY, 0)
|
||||
val nowMillis = SystemClock.elapsedRealtime()
|
||||
|
||||
it[getPermissionLaunchCount(permission)] = appLaunchCounter + DELAY_LAUNCH_COUNT
|
||||
it[getPermissionDaysCount(permission)] = nowMillis + DELAY_DAYS_COUNT
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val DELAY_LAUNCH_COUNT = 5
|
||||
const val DELAY_DAYS_COUNT = 3L * 24 * 3600 * 1000 // 3 days in millis
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue