Showing selected account
This commit is contained in:
parent
5832a877c0
commit
f221bd2095
|
@ -1,19 +1,28 @@
|
||||||
package net.codinux.banking.ui.composables
|
package net.codinux.banking.ui.composables
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import net.codinux.banking.client.model.UserAccount
|
import net.codinux.banking.dataaccess.entities.BankAccountEntity
|
||||||
|
import net.codinux.banking.dataaccess.entities.UserAccountEntity
|
||||||
|
import net.codinux.banking.ui.config.Colors
|
||||||
|
import net.codinux.banking.ui.config.DI
|
||||||
import org.jetbrains.compose.resources.DrawableResource
|
import org.jetbrains.compose.resources.DrawableResource
|
||||||
|
|
||||||
|
private val filterService = DI.bankAccountFilterService
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationMenuItem(
|
fun NavigationMenuItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -21,13 +30,28 @@ fun NavigationMenuItem(
|
||||||
textColor: Color = Color.White,
|
textColor: Color = Color.White,
|
||||||
iconSize: Dp = 24.dp,
|
iconSize: Dp = 24.dp,
|
||||||
iconTextSpacing: Dp = 24.dp,
|
iconTextSpacing: Dp = 24.dp,
|
||||||
userAccount: UserAccount? = null,
|
horizontalPadding: Dp = 8.dp,
|
||||||
fallbackIcon: DrawableResource? = null,
|
userAccount: UserAccountEntity? = null,
|
||||||
|
bankAccount: BankAccountEntity? = null,
|
||||||
|
iconResource: DrawableResource? = null,
|
||||||
|
icon: (@Composable () -> Unit)? = null,
|
||||||
onClick: (() -> Unit)? = null
|
onClick: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
|
val accountFilter by DI.uiState.accountFilter.collectAsState()
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier.clickable { onClick?.invoke() },
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
modifier = modifier
|
||||||
|
.clickable { onClick?.invoke() }
|
||||||
|
.let {
|
||||||
|
if (userAccount != null && filterService.isSelected(userAccount, accountFilter)
|
||||||
|
|| bankAccount != null && filterService.isSelected(bankAccount, accountFilter)) {
|
||||||
|
it.background(Colors.Accent)
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(horizontal = horizontalPadding)
|
||||||
) {
|
) {
|
||||||
BankIcon(userAccount, Modifier.padding(end = iconTextSpacing), Modifier.size(iconSize), fallbackIcon = fallbackIcon)
|
BankIcon(userAccount, Modifier.padding(end = iconTextSpacing), Modifier.size(iconSize), fallbackIcon = fallbackIcon)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.codinux.banking.ui.service
|
package net.codinux.banking.ui.service
|
||||||
|
|
||||||
|
import net.codinux.banking.dataaccess.entities.BankAccountEntity
|
||||||
|
import net.codinux.banking.dataaccess.entities.UserAccountEntity
|
||||||
import net.codinux.banking.ui.model.AccountTransactionViewModel
|
import net.codinux.banking.ui.model.AccountTransactionViewModel
|
||||||
import net.codinux.banking.ui.model.BankAccountFilter
|
import net.codinux.banking.ui.model.BankAccountFilter
|
||||||
|
|
||||||
|
@ -21,4 +23,25 @@ class BankAccountFilterService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun isSelected(userAccount: UserAccountEntity, accountFilter: List<BankAccountFilter>): Boolean {
|
||||||
|
if (accountFilter.isEmpty()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val filter = accountFilter.first()
|
||||||
|
|
||||||
|
return filter.userAccount == userAccount && filter.bankAccount == null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isSelected(bankAccount: BankAccountEntity, accountFilter: List<BankAccountFilter>): Boolean {
|
||||||
|
if (accountFilter.isEmpty()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val filter = accountFilter.first()
|
||||||
|
|
||||||
|
return filter.bankAccount == bankAccount
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue