Updated on 2026-08-14
This commit is contained in:
parent
1bc38864da
commit
f95a3b8fcc
3 changed files with 22 additions and 18 deletions
|
|
@ -8,8 +8,14 @@ import androidx.compose.foundation.lazy.rememberLazyListState
|
|||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.pullrefresh.pullRefresh
|
||||
import androidx.compose.material.pullrefresh.rememberPullRefreshState
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material3.FabPosition
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
|
@ -52,7 +58,9 @@ internal fun WalletScreen(state: WalletState) {
|
|||
|
||||
when (state) {
|
||||
is WalletState.ContentState -> {
|
||||
val walletsListState = rememberLazyListState()
|
||||
val walletsListState = rememberLazyListState(
|
||||
initialFirstVisibleItemIndex = state.walletsListConfig.selectedWalletIndex,
|
||||
)
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val isAutoScroll = remember { mutableStateOf(value = false) }
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import kotlin.properties.Delegates
|
|||
@Suppress("LargeClass", "LongParameterList", "TooManyFunctions")
|
||||
@HiltViewModel
|
||||
internal class WalletViewModel @Inject constructor(
|
||||
// region Parameters
|
||||
private val getWalletsUseCase: GetWalletsUseCase,
|
||||
private val saveWalletUseCase: SaveWalletUseCase,
|
||||
getSelectedWalletUseCase: GetSelectedWalletUseCase,
|
||||
|
|
@ -92,6 +93,7 @@ internal class WalletViewModel @Inject constructor(
|
|||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val reduxStateHolder: ReduxStateHolder,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
// endregion Parameters
|
||||
) : ViewModel(), DefaultLifecycleObserver, WalletClickIntents {
|
||||
|
||||
/** Feature router */
|
||||
|
|
@ -161,8 +163,8 @@ internal class WalletViewModel @Inject constructor(
|
|||
if (sourceList.isEmpty()) return
|
||||
|
||||
when (val action = walletsUpdateActionResolver.resolve(sourceList)) {
|
||||
is WalletsUpdateActionResolver.Action.InitialWallets -> {
|
||||
loadAndUpdateState(index = action.selectedWalletIndex)
|
||||
is WalletsUpdateActionResolver.Action.Initialize -> {
|
||||
loadAndUpdateState(action.selectedWalletIndex)
|
||||
}
|
||||
is WalletsUpdateActionResolver.Action.UpdateWalletName -> {
|
||||
uiState = stateFactory.getStateWithUpdatedWalletName(name = action.name)
|
||||
|
|
@ -176,7 +178,7 @@ internal class WalletViewModel @Inject constructor(
|
|||
deleteWalletAndUpdateState(action = action)
|
||||
}
|
||||
is WalletsUpdateActionResolver.Action.AddWallet -> {
|
||||
loadAndUpdateState(index = action.selectedWalletIndex)
|
||||
loadAndUpdateState(action.selectedWalletIndex)
|
||||
}
|
||||
is WalletsUpdateActionResolver.Action.Unknown -> Unit
|
||||
}
|
||||
|
|
@ -196,20 +198,14 @@ internal class WalletViewModel @Inject constructor(
|
|||
getContentItemsUpdates(action.selectedWalletIndex)
|
||||
}
|
||||
} else {
|
||||
loadAndUpdateState(index = action.selectedWalletIndex)
|
||||
loadAndUpdateState(selectedWalletIndex = action.selectedWalletIndex)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAndUpdateState(index: Int) {
|
||||
uiState = stateFactory.getSkeletonState(wallets = wallets, selectedWalletIndex = index)
|
||||
private fun loadAndUpdateState(selectedWalletIndex: Int) {
|
||||
uiState = stateFactory.getSkeletonState(wallets = wallets, selectedWalletIndex = selectedWalletIndex)
|
||||
|
||||
uiState = stateFactory.getStateAndTriggerEvent(
|
||||
state = uiState,
|
||||
event = WalletEvent.ChangeWallet(index = index),
|
||||
setUiState = { uiState = it },
|
||||
)
|
||||
|
||||
getContentItemsUpdates(index = index)
|
||||
getContentItemsUpdates(index = selectedWalletIndex)
|
||||
}
|
||||
|
||||
override fun onBackClick() {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ internal class WalletsUpdateActionResolver(
|
|||
|
||||
return when (val state = currentStateProvider()) {
|
||||
is WalletState.Initial -> {
|
||||
Action.InitialWallets(
|
||||
Action.Initialize(
|
||||
selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId),
|
||||
)
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ internal class WalletsUpdateActionResolver(
|
|||
|
||||
sealed class Action {
|
||||
|
||||
data class InitialWallets(val selectedWalletIndex: Int) : Action()
|
||||
data class Initialize(val selectedWalletIndex: Int) : Action()
|
||||
|
||||
data class UpdateWalletName(val name: String) : Action()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue