Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

[Feature] Hide Selected Accounts In Accounts Tab #3662

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.ivy.accounts

import com.ivy.data.model.Account

sealed interface AccountsEvent {
data class OnReorder(val reorderedList: List<com.ivy.legacy.data.model.AccountData>) :
AccountsEvent
data class OnReorderModalVisible(val reorderVisible: Boolean) : AccountsEvent
data class OnVisibilityUpdate(val updatedList: List<Account>) :
AccountsEvent
data class OnHideModalVisible(val hideVisible: Boolean) : AccountsEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class AccountsState(
val totalBalanceWithoutExcluded: String,
val totalBalanceWithoutExcludedText: String,
val reorderVisible: Boolean,
val hideVisible: Boolean,
val compactAccountsModeEnabled: Boolean,
val hideTotalBalance: Boolean,
)
42 changes: 40 additions & 2 deletions screen/accounts/src/main/java/com/ivy/accounts/AccountsTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -54,6 +55,7 @@ import com.ivy.wallet.ui.theme.Green
import com.ivy.wallet.ui.theme.GreenLight
import com.ivy.wallet.ui.theme.components.BalanceRow
import com.ivy.wallet.ui.theme.components.BalanceRowMini
import com.ivy.wallet.ui.theme.components.CircleButtonFilled
import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon
import com.ivy.wallet.ui.theme.components.ReorderButton
import com.ivy.wallet.ui.theme.components.ReorderModalSingleType
Expand Down Expand Up @@ -82,7 +84,7 @@ private fun BoxWithConstraintsScope.UI(
val nav = navigation()
val ivyContext = com.ivy.legacy.ivyWalletCtx()
var listState = rememberLazyListState()
if (!state.accountsData.isEmpty()) {
if (state.accountsData.any { it.account.isVisible }) {
listState = rememberScrollPositionListState(
key = "accounts_lazy_column",
initialFirstVisibleItemIndex = ivyContext.accountsListState?.firstVisibleItemIndex ?: 0,
Expand Down Expand Up @@ -127,6 +129,14 @@ private fun BoxWithConstraintsScope.UI(

Spacer(Modifier.weight(1f))

HideAccountsButton(modifier = Modifier.size(size = 48.dp)) {
onEvent(
AccountsEvent.OnHideModalVisible(hideVisible = true)
)
}

Spacer(Modifier.width(16.dp))

ReorderButton {
onEvent(
AccountsEvent.OnReorderModalVisible(reorderVisible = true)
Expand All @@ -149,7 +159,7 @@ private fun BoxWithConstraintsScope.UI(
Spacer(Modifier.height(16.dp))
}
}
items(state.accountsData) {
items(state.accountsData.filter { it.account.isVisible }) {
Spacer(Modifier.height(16.dp))
AccountCard(
baseCurrency = state.baseCurrency,
Expand Down Expand Up @@ -178,6 +188,12 @@ private fun BoxWithConstraintsScope.UI(
}
}

HideAccountsModal(
visible = state.hideVisible,
initialItems = state.accountsData,
onDismiss = { onEvent(AccountsEvent.OnHideModalVisible(hideVisible = false)) },
onComplete = { onEvent(AccountsEvent.OnVisibilityUpdate(updatedList = it)) }
)
ReorderModalSingleType(
visible = state.reorderVisible,
initialItems = state.accountsData,
Expand Down Expand Up @@ -347,6 +363,7 @@ private fun PreviewAccountsTabCompactModeDisabled(theme: Theme = Theme.LIGHT) {
icon = null,
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc2 = Account(
Expand All @@ -357,6 +374,7 @@ private fun PreviewAccountsTabCompactModeDisabled(theme: Theme = Theme.LIGHT) {
icon = null,
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc3 = Account(
Expand All @@ -367,6 +385,7 @@ private fun PreviewAccountsTabCompactModeDisabled(theme: Theme = Theme.LIGHT) {
icon = IconAsset.unsafe("revolut"),
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc4 = Account(
Expand All @@ -377,6 +396,7 @@ private fun PreviewAccountsTabCompactModeDisabled(theme: Theme = Theme.LIGHT) {
icon = IconAsset.unsafe("cash"),
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)
val state = AccountsState(
baseCurrency = "BGN",
Expand Down Expand Up @@ -415,6 +435,7 @@ private fun PreviewAccountsTabCompactModeDisabled(theme: Theme = Theme.LIGHT) {
totalBalanceWithoutExcluded = "25.54",
totalBalanceWithoutExcludedText = "BGN 25.54",
reorderVisible = false,
hideVisible = false,
compactAccountsModeEnabled = false,
hideTotalBalance = false
)
Expand All @@ -434,6 +455,7 @@ private fun PreviewAccountsTabCompactModeEnabled(theme: Theme = Theme.LIGHT) {
icon = null,
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc2 = Account(
Expand All @@ -444,6 +466,7 @@ private fun PreviewAccountsTabCompactModeEnabled(theme: Theme = Theme.LIGHT) {
icon = null,
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc3 = Account(
Expand All @@ -454,6 +477,7 @@ private fun PreviewAccountsTabCompactModeEnabled(theme: Theme = Theme.LIGHT) {
icon = IconAsset.unsafe("revolut"),
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)

val acc4 = Account(
Expand All @@ -464,6 +488,7 @@ private fun PreviewAccountsTabCompactModeEnabled(theme: Theme = Theme.LIGHT) {
icon = IconAsset.unsafe("cash"),
includeInBalance = true,
orderNum = 0.0,
isVisible = true,
)
val state = AccountsState(
baseCurrency = "BGN",
Expand Down Expand Up @@ -502,13 +527,26 @@ private fun PreviewAccountsTabCompactModeEnabled(theme: Theme = Theme.LIGHT) {
totalBalanceWithoutExcluded = "25.54",
totalBalanceWithoutExcludedText = "BGN 25.54",
reorderVisible = false,
hideVisible = false,
compactAccountsModeEnabled = true,
hideTotalBalance = false
)
UI(state = state)
}
}

@Composable
fun HideAccountsButton(
modifier: Modifier = Modifier,
onClick: () -> Unit
) {
CircleButtonFilled(
modifier = modifier,
icon = R.drawable.ic_hide_m,
onClick = onClick
)
}

/** For screen shot testing **/
@Composable
fun AccountsTabNonCompactUITest(dark: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.ivy.base.time.TimeConverter
import com.ivy.base.time.TimeProvider
import com.ivy.data.DataObserver
import com.ivy.data.DataWriteEvent
import com.ivy.data.model.Account
import com.ivy.data.repository.AccountRepository
import com.ivy.domain.features.Features
import com.ivy.legacy.IvyWalletCtx
Expand Down Expand Up @@ -59,6 +60,7 @@ class AccountsViewModel @Inject constructor(
private var totalBalanceWithoutExcluded by mutableStateOf("")
private var totalBalanceWithoutExcludedText by mutableStateOf("")
private var reorderVisible by mutableStateOf(false)
private var hideVisible by mutableStateOf(false)

init {
viewModelScope.launch {
Expand Down Expand Up @@ -90,6 +92,7 @@ class AccountsViewModel @Inject constructor(
totalBalanceWithoutExcluded = getTotalBalanceWithoutExcluded(),
totalBalanceWithoutExcludedText = getTotalBalanceWithoutExcludedText(),
reorderVisible = getReorderVisible(),
hideVisible = getHideVisible(),
compactAccountsModeEnabled = getCompactAccountsMode(),
hideTotalBalance = getHideTotalBalance()
)
Expand Down Expand Up @@ -135,6 +138,11 @@ class AccountsViewModel @Inject constructor(
return reorderVisible
}

@Composable
private fun getHideVisible(): Boolean {
return hideVisible
}

@Composable
private fun getCompactAccountsMode(): Boolean {
return features.compactAccountsMode.asEnabledState()
Expand All @@ -145,6 +153,11 @@ class AccountsViewModel @Inject constructor(
when (event) {
is AccountsEvent.OnReorder -> reorder(event.reorderedList)
is AccountsEvent.OnReorderModalVisible -> reorderModalVisible(event.reorderVisible)
is AccountsEvent.OnHideModalVisible -> hideModalVisible(event.hideVisible)
is AccountsEvent.OnVisibilityUpdate -> {
updateVisibility(event.updatedList)
hideVisible = false
}
}
}
}
Expand All @@ -159,6 +172,16 @@ class AccountsViewModel @Inject constructor(
startInternally()
}

private suspend fun updateVisibility(accounts: List<Account>) {
ioThread {
accounts.forEach { acc ->
accountRepository.save(acc)
}
}

startInternally()
}

private fun onStart() {
viewModelScope.launch(Dispatchers.Default) {
startInternally()
Expand Down Expand Up @@ -222,4 +245,8 @@ class AccountsViewModel @Inject constructor(
private fun reorderModalVisible(visible: Boolean) {
reorderVisible = visible
}

private fun hideModalVisible(visible: Boolean) {
hideVisible = visible
}
}
Loading