Updated on 2026-08-14
This commit is contained in:
commit
2da48c037a
961 changed files with 24212 additions and 13399 deletions
|
|
@ -1,16 +1,49 @@
|
|||
package com.tangem.data.card
|
||||
|
||||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import com.tangem.datasource.local.card.UsedCardInfo
|
||||
import com.tangem.datasource.local.card.UsedCardsStore
|
||||
import com.tangem.domain.card.repository.CardRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.extensions.addOrReplace
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
internal class DefaultCardRepository(
|
||||
private val preferencesDataSource: PreferencesDataSource,
|
||||
private val usedCardsStore: UsedCardsStore,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : CardRepository {
|
||||
|
||||
override suspend fun wasCardScanned(cardId: String): Boolean {
|
||||
return withContext(dispatchers.io) { preferencesDataSource.usedCardsPrefStorage.wasScanned(cardId) }
|
||||
override fun wasCardScanned(cardId: String): Flow<Boolean> {
|
||||
return channelFlow {
|
||||
launch(dispatchers.io) {
|
||||
usedCardsStore.get()
|
||||
.collect { savedCards ->
|
||||
send(element = savedCards.any { it.cardId == cardId })
|
||||
}
|
||||
}
|
||||
|
||||
withContext(dispatchers.io) {
|
||||
if (usedCardsStore.getSyncOrNull() == null) {
|
||||
send(element = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun setCardWasScanned(cardId: String) {
|
||||
withContext(dispatchers.io) {
|
||||
usedCardsStore.store(
|
||||
item = usedCardsStore.getSyncOrNull()
|
||||
?.updateCard(cardId)
|
||||
?: listOf(UsedCardInfo(cardId = cardId, isScanned = true)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<UsedCardInfo>.updateCard(cardId: String): List<UsedCardInfo> {
|
||||
val card = find { it.cardId == cardId } ?: UsedCardInfo(cardId = cardId, isScanned = true)
|
||||
return addOrReplace(item = card.copy(isScanned = true), predicate = { it.cardId == cardId })
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ internal class DefaultCardSdkConfigRepository(
|
|||
ProductType.Wallet,
|
||||
ProductType.Wallet2,
|
||||
ProductType.Start2Coin,
|
||||
ProductType.Wallet2,
|
||||
-> CardIdDisplayFormat.Full
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.tangem.data.card.DefaultCardRepository
|
|||
import com.tangem.data.card.DefaultCardSdkConfigRepository
|
||||
import com.tangem.data.card.sdk.CardSdkProvider
|
||||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import com.tangem.datasource.local.card.UsedCardsStore
|
||||
import com.tangem.domain.card.repository.CardRepository
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -32,9 +33,9 @@ internal object CardDataModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideCardRepository(
|
||||
preferencesDataSource: PreferencesDataSource,
|
||||
usedCardsStore: UsedCardsStore,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
): CardRepository {
|
||||
return DefaultCardRepository(preferencesDataSource = preferencesDataSource, dispatchers = dispatchers)
|
||||
return DefaultCardRepository(usedCardsStore = usedCardsStore, dispatchers = dispatchers)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue