Updated on 2026-08-14
This commit is contained in:
parent
55bda27036
commit
50a485e986
16 changed files with 34 additions and 100 deletions
|
|
@ -88,7 +88,6 @@ dependencies {
|
|||
implementation(projects.data.card)
|
||||
implementation(projects.data.common)
|
||||
implementation(projects.data.settings)
|
||||
implementation(projects.data.source.preferences)
|
||||
implementation(projects.data.tokens)
|
||||
implementation(projects.data.txhistory)
|
||||
implementation(projects.data.wallets)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import com.tangem.blockchainsdk.BlockchainSDKFactory
|
|||
import com.tangem.core.analytics.Analytics
|
||||
import com.tangem.core.analytics.filter.OneTimeEventFilter
|
||||
import com.tangem.core.featuretoggle.manager.FeatureTogglesManager
|
||||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import com.tangem.datasource.api.common.MoshiConverter
|
||||
import com.tangem.datasource.api.common.createNetworkLoggingInterceptor
|
||||
import com.tangem.datasource.asset.AssetReader
|
||||
|
|
@ -80,7 +79,6 @@ lateinit var store: Store<AppState>
|
|||
|
||||
lateinit var foregroundActivityObserver: ForegroundActivityObserver
|
||||
lateinit var activityResultCaller: ActivityResultCaller
|
||||
lateinit var preferencesStorage: PreferencesDataSource
|
||||
lateinit var walletConnectRepository: WalletConnectRepository
|
||||
internal lateinit var derivationsFinder: DerivationsFinder
|
||||
|
||||
|
|
@ -106,9 +104,6 @@ internal class TapApplication : Application(), ImageLoaderFactory {
|
|||
@Inject
|
||||
lateinit var customTokenFeatureToggles: CustomTokenFeatureToggles
|
||||
|
||||
@Inject
|
||||
lateinit var preferencesDataSource: PreferencesDataSource
|
||||
|
||||
@Inject
|
||||
lateinit var walletConnect2Repository: WalletConnect2Repository
|
||||
|
||||
|
|
@ -202,7 +197,6 @@ internal class TapApplication : Application(), ImageLoaderFactory {
|
|||
activityResultCaller = foregroundActivityObserver
|
||||
registerActivityLifecycleCallbacks(foregroundActivityObserver.callbacks)
|
||||
|
||||
preferencesStorage = preferencesDataSource
|
||||
walletConnectRepository = WalletConnectRepository(this)
|
||||
|
||||
// TODO: Try to performance and user experience.
|
||||
|
|
|
|||
|
|
@ -148,4 +148,12 @@ internal object SettingsDomainModule {
|
|||
): SetSaveWalletScreenShownUseCase {
|
||||
return SetSaveWalletScreenShownUseCase(settingsRepository = settingsRepository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@ViewModelScoped
|
||||
fun provideIncrementAppLaunchCounterUseCase(
|
||||
settingsRepository: SettingsRepository,
|
||||
): IncrementAppLaunchCounterUseCase {
|
||||
return IncrementAppLaunchCounterUseCase(settingsRepository = settingsRepository)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
|
|||
import com.tangem.domain.balancehiding.ListenToFlipsUseCase
|
||||
import com.tangem.domain.balancehiding.UpdateBalanceHidingSettingsUseCase
|
||||
import com.tangem.domain.settings.DeleteDeprecatedLogsUseCase
|
||||
import com.tangem.domain.settings.IncrementAppLaunchCounterUseCase
|
||||
import com.tangem.tap.features.main.model.MainScreenState
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -26,6 +27,7 @@ internal class MainViewModel @Inject constructor(
|
|||
private val reduxNavController: ReduxNavController,
|
||||
private val fetchAppCurrenciesUseCase: FetchAppCurrenciesUseCase,
|
||||
private val deleteDeprecatedLogsUseCase: DeleteDeprecatedLogsUseCase,
|
||||
private val incrementAppLaunchCounterUseCase: IncrementAppLaunchCounterUseCase,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
) : ViewModel(), MainIntents {
|
||||
|
|
@ -40,6 +42,8 @@ internal class MainViewModel @Inject constructor(
|
|||
val state: StateFlow<MainScreenState> = stateHolder.stateFlow
|
||||
|
||||
init {
|
||||
viewModelScope.launch(dispatchers.main) { incrementAppLaunchCounterUseCase() }
|
||||
|
||||
updateAppCurrencies()
|
||||
observeFlips()
|
||||
displayBalancesHidingStatusToast()
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ dependencies {
|
|||
implementation(projects.core.datasource)
|
||||
implementation(projects.core.utils)
|
||||
|
||||
implementation(projects.data.source.preferences)
|
||||
|
||||
implementation(projects.domain.card)
|
||||
implementation(projects.domain.models)
|
||||
}
|
||||
|
|
@ -15,8 +15,6 @@ dependencies {
|
|||
implementation(projects.core.datasource)
|
||||
implementation(projects.core.utils)
|
||||
|
||||
implementation(projects.data.source.preferences)
|
||||
|
||||
implementation(projects.domain.balanceHiding.models)
|
||||
implementation(projects.domain.settings)
|
||||
|
||||
|
|
|
|||
|
|
@ -104,4 +104,11 @@ internal class DefaultSettingsRepository(
|
|||
override suspend fun setShouldSaveAccessCodes(value: Boolean) {
|
||||
appPreferencesStore.store(key = PreferencesKeys.SHOULD_SAVE_ACCESS_CODES_KEY, value = value)
|
||||
}
|
||||
|
||||
override suspend fun incrementAppLaunchCounter() {
|
||||
appPreferencesStore.editData { preferences ->
|
||||
val count = preferences.getOrDefault(key = PreferencesKeys.APP_LAUNCH_COUNT_KEY, default = 0)
|
||||
preferences[PreferencesKeys.APP_LAUNCH_COUNT_KEY] = count + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
1
data/source/preferences/.gitignore
vendored
1
data/source/preferences/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
/build
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.android)
|
||||
alias(deps.plugins.kotlin.kapt)
|
||||
alias(deps.plugins.android.library)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.tangem.data.source.preferences"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(deps.androidx.core.ktx)
|
||||
implementation(deps.moshi)
|
||||
implementation(deps.moshi.kotlin)
|
||||
implementation(deps.hilt.android)
|
||||
kapt(deps.hilt.kapt)
|
||||
|
||||
// For MoshiJsonConverter
|
||||
implementation(deps.tangem.card.core)
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.tangem.data.source.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import javax.inject.Inject
|
||||
|
||||
// 🔥FIXME: Only logic to work with preferences must be here, must be separated to repositories
|
||||
// TODO: Replace shared preferences with DataStore
|
||||
@Deprecated("Create repository instead")
|
||||
class PreferencesDataSource @Inject internal constructor(applicationContext: Context) {
|
||||
|
||||
private val preferences: SharedPreferences =
|
||||
applicationContext.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
init {
|
||||
incrementLaunchCounter()
|
||||
}
|
||||
|
||||
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_LAUNCH_COUNT_KEY = "launchCount"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package com.tangem.data.source.preferences.adapters
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigDecimal
|
||||
|
||||
class BigDecimalAdapter {
|
||||
@FromJson
|
||||
fun fromJson(value: String) = BigDecimal(value)
|
||||
|
||||
@ToJson
|
||||
fun toJson(value: BigDecimal) = value.toString()
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package com.tangem.data.source.preferences.di
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object PreferencesStoreModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePreferencesStore(@ApplicationContext context: Context) = PreferencesDataSource(context)
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package com.tangem.data.source.preferences.storage
|
||||
|
||||
internal interface Migration {
|
||||
fun migrate()
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.tangem.domain.settings
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
|
||||
class IncrementAppLaunchCounterUseCase(
|
||||
private val settingsRepository: SettingsRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): Either<Throwable, Unit> {
|
||||
return Either.catch { settingsRepository.incrementAppLaunchCounter() }
|
||||
}
|
||||
}
|
||||
|
|
@ -31,4 +31,6 @@ interface SettingsRepository {
|
|||
suspend fun shouldSaveAccessCodes(): Boolean
|
||||
|
||||
suspend fun setShouldSaveAccessCodes(value: Boolean)
|
||||
|
||||
suspend fun incrementAppLaunchCounter()
|
||||
}
|
||||
|
|
@ -151,7 +151,6 @@ include(":data:balance-hiding")
|
|||
include(":data:common")
|
||||
include(":data:card")
|
||||
include(":data:tokens")
|
||||
include(":data:source:preferences")
|
||||
include(":data:settings")
|
||||
include(":data:txhistory")
|
||||
include(":data:wallets")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue