Updated on 2026-08-14
This commit is contained in:
parent
aa03d39dc0
commit
49bd0090ff
18 changed files with 300 additions and 88 deletions
|
|
@ -31,8 +31,6 @@ dependencies {
|
|||
|
||||
/** Domain modules */
|
||||
implementation(projects.domain.account)
|
||||
implementation(projects.domain.appTheme)
|
||||
implementation(projects.domain.appTheme.models)
|
||||
implementation(projects.domain.card)
|
||||
implementation(projects.domain.feedback)
|
||||
implementation(projects.domain.markets.models)
|
||||
|
|
@ -42,6 +40,7 @@ dependencies {
|
|||
implementation(projects.domain.wallets.models)
|
||||
implementation(projects.domain.wallets)
|
||||
implementation(projects.domain.feedback.models)
|
||||
implementation(projects.domain.settings)
|
||||
|
||||
implementation(projects.data.common)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
package com.tangem.feature.tester.presentation.actions
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.tangem.domain.apptheme.model.AppThemeMode
|
||||
import java.io.File
|
||||
|
||||
internal data class TesterActionsContentState(
|
||||
val hideAllCurrenciesUM: HideAllCurrenciesUM,
|
||||
val toggleAppThemeUM: ToggleAppThemeUM,
|
||||
val toggleHotWalletRestrictionUM: ToggleHotWalletRestrictionUM,
|
||||
val shareLogsUM: ShareLogsUM,
|
||||
val onBackClick: () -> Unit,
|
||||
) {
|
||||
@Immutable
|
||||
sealed class HideAllCurrenciesUM {
|
||||
data class Clickable(val onClick: () -> Unit) : HideAllCurrenciesUM()
|
||||
|
||||
data object Progress : HideAllCurrenciesUM()
|
||||
}
|
||||
|
||||
data class ToggleAppThemeUM(
|
||||
val currentAppTheme: AppThemeMode,
|
||||
data class ToggleHotWalletRestrictionUM(
|
||||
val isEnabled: Boolean,
|
||||
val onClick: () -> Unit,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@ import com.tangem.core.ui.extensions.stringResourceSafe
|
|||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.core.ui.utils.findActivity
|
||||
import com.tangem.domain.apptheme.model.AppThemeMode
|
||||
import com.tangem.feature.tester.impl.R
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.HideAllCurrenciesUM
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.ToggleAppThemeUM
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.ToggleHotWalletRestrictionUM
|
||||
import com.tangem.utils.logging.TangemLogger
|
||||
import java.io.File
|
||||
|
||||
|
|
@ -57,10 +56,11 @@ internal fun TesterActionsScreen(state: TesterActionsContentState, modifier: Mod
|
|||
}
|
||||
|
||||
item {
|
||||
val config = state.toggleAppThemeUM
|
||||
val config = state.toggleHotWalletRestrictionUM
|
||||
val statusText = if (config.isEnabled) "ON" else "OFF"
|
||||
|
||||
TesterActionItem(
|
||||
name = stringResourceSafe(id = R.string.toggle_app_theme, config.currentAppTheme.name),
|
||||
name = stringResourceSafe(id = R.string.toggle_hot_wallet_restriction, statusText),
|
||||
onClick = config.onClick,
|
||||
)
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ private fun TesterActionsScreenSample(modifier: Modifier = Modifier) {
|
|||
TesterActionsScreen(
|
||||
state = TesterActionsContentState(
|
||||
hideAllCurrenciesUM = HideAllCurrenciesUM.Clickable {},
|
||||
toggleAppThemeUM = ToggleAppThemeUM(AppThemeMode.DEFAULT) {},
|
||||
toggleHotWalletRestrictionUM = ToggleHotWalletRestrictionUM(isEnabled = true) {},
|
||||
shareLogsUM = TesterActionsContentState.ShareLogsUM(file = null),
|
||||
onBackClick = {},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -5,31 +5,25 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.data.common.account.WalletAccountsSaver
|
||||
import com.tangem.domain.apptheme.ChangeAppThemeModeUseCase
|
||||
import com.tangem.domain.apptheme.GetAppThemeModeUseCase
|
||||
import com.tangem.domain.apptheme.model.AppThemeMode
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.feedback.repository.FeedbackRepository
|
||||
import com.tangem.domain.settings.HotWalletRestrictionManager
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.HideAllCurrenciesUM
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.ToggleAppThemeUM
|
||||
import com.tangem.feature.tester.presentation.actions.TesterActionsContentState.ToggleHotWalletRestrictionUM
|
||||
import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import com.tangem.utils.logging.TangemLogger
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
internal class TesterActionsViewModel @Inject constructor(
|
||||
private val changeAppThemeModeUseCase: ChangeAppThemeModeUseCase,
|
||||
private val getAppThemeModeUseCase: GetAppThemeModeUseCase,
|
||||
private val feedbackRepository: FeedbackRepository,
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val walletAccountsSaver: WalletAccountsSaver,
|
||||
private val hotWalletRestrictionManager: HotWalletRestrictionManager,
|
||||
) : ViewModel() {
|
||||
|
||||
var uiState: TesterActionsContentState by mutableStateOf(initialState)
|
||||
|
|
@ -38,16 +32,16 @@ internal class TesterActionsViewModel @Inject constructor(
|
|||
private val initialState: TesterActionsContentState
|
||||
get() = TesterActionsContentState(
|
||||
hideAllCurrenciesUM = HideAllCurrenciesUM.Clickable(this::hideAllCurrencies),
|
||||
toggleAppThemeUM = ToggleAppThemeUM(
|
||||
currentAppTheme = AppThemeMode.DEFAULT,
|
||||
onClick = this::toggleAppTheme,
|
||||
toggleHotWalletRestrictionUM = ToggleHotWalletRestrictionUM(
|
||||
isEnabled = hotWalletRestrictionManager.isCreationEnabledSync(),
|
||||
onClick = this::toggleHotWalletRestriction,
|
||||
),
|
||||
shareLogsUM = TesterActionsContentState.ShareLogsUM(file = feedbackRepository.getLogFile()),
|
||||
onBackClick = { /* no-op */ },
|
||||
)
|
||||
|
||||
init {
|
||||
bootstrapAppThemeModeUpdates()
|
||||
bootstrapHotWalletRestrictionUpdates()
|
||||
}
|
||||
|
||||
fun setupNavigation(router: InnerTesterRouter) {
|
||||
|
|
@ -78,57 +72,16 @@ internal class TesterActionsViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun toggleAppTheme() = viewModelScope.launch {
|
||||
val currentAppThemeMode = uiState.toggleAppThemeUM.currentAppTheme
|
||||
val newAppThemeMode = when (currentAppThemeMode) {
|
||||
AppThemeMode.FORCE_DARK -> AppThemeMode.FORCE_LIGHT
|
||||
AppThemeMode.FORCE_LIGHT -> AppThemeMode.FOLLOW_SYSTEM
|
||||
AppThemeMode.FOLLOW_SYSTEM -> AppThemeMode.FORCE_DARK
|
||||
}
|
||||
|
||||
TangemLogger.d(
|
||||
"""
|
||||
Change app theme mode
|
||||
|- Current theme mode: $currentAppThemeMode
|
||||
|- New theme mode: $newAppThemeMode
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
changeAppThemeModeUseCase(newAppThemeMode).onLeft { error ->
|
||||
TangemLogger.e(
|
||||
"""
|
||||
Unable to change app theme mode
|
||||
|- Error: $error
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
private fun toggleHotWalletRestriction() = viewModelScope.launch {
|
||||
hotWalletRestrictionManager.toggleCreationEnabled()
|
||||
}
|
||||
|
||||
private fun bootstrapAppThemeModeUpdates() {
|
||||
getAppThemeModeUseCase()
|
||||
.distinctUntilChanged()
|
||||
.onEach { maybeAppThemeMode ->
|
||||
TangemLogger.d(
|
||||
"""
|
||||
Current app theme mode updated
|
||||
|- Previous app theme mode: ${uiState.toggleAppThemeUM.currentAppTheme}
|
||||
|- New app theme mode: $maybeAppThemeMode
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
private fun bootstrapHotWalletRestrictionUpdates() {
|
||||
hotWalletRestrictionManager.isCreationEnabled()
|
||||
.onEach { isEnabled ->
|
||||
uiState = uiState.copy(
|
||||
toggleAppThemeUM = uiState.toggleAppThemeUM.copy(
|
||||
currentAppTheme = maybeAppThemeMode.getOrElse { error ->
|
||||
TangemLogger.e(
|
||||
"""
|
||||
Unable to get current app theme mode, using default
|
||||
|- Default theme mode: ${AppThemeMode.DEFAULT}
|
||||
|- Error: $error
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
AppThemeMode.DEFAULT
|
||||
},
|
||||
toggleHotWalletRestrictionUM = uiState.toggleHotWalletRestrictionUM.copy(
|
||||
isEnabled = isEnabled,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
<string name="environment_toggles" translatable="false">Environment toggles</string>
|
||||
<string name="tester_actions" translatable="false">Tester actions</string>
|
||||
<string name="hide_all_currencies" translatable="false">Hide all currencies</string>
|
||||
<string name="toggle_app_theme" translatable="false">Toggle app theme - %s</string>
|
||||
<string name="excluded_blockchains" translatable="false">Excluded blockchains</string>
|
||||
<string name="excluded_blockchains_search_placeholder" translatable="false">Filter by name or symbol</string>
|
||||
<string name="blockchain_providers" translatable="false">Blockchain providers</string>
|
||||
<string name="toggle_hot_wallet_restriction" translatable="false">Hot wallet creation restriction - %s</string>
|
||||
<string name="share_logs" translatable="false">Share logs</string>
|
||||
<string name="test_push" translatable="false">Test push</string>
|
||||
<string name="accounts" translatable="false">Accounts</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue