Skip to content

Commit

Permalink
feat: Update budget item view (#44)
Browse files Browse the repository at this point in the history
* Update budget item view

* Add architecture diagram
  • Loading branch information
n3gbx authored Oct 15, 2024
1 parent 7e4b8e1 commit 17c8728
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 102 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ Android app for tracking and analysing cash-flow<br/>
<img src="./docs/frame_5.png" height="480">
<img src="./docs/frame_6.png" height="480">
</p>

## Architecture diagram
<img src="./docs/architecture_diagram.svg" height="640" alt="Architecture diagram">
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ sealed interface BudgetGroup {
val budgets: List<Budget>

val totalSpentValue: BigDecimal
get() = budgets.sumByDecimal { it.spentValue }
get() = budgets.sumByDecimal { it.spentValue }.setScale(currency.unit.scale)

val totalLimitValue: BigDecimal
get() = budgets.sumByDecimal { it.limitValue }
get() = budgets.sumByDecimal { it.limitValue }.setScale(currency.unit.scale)

val totalLeftValue: BigDecimal
get() = budgets.sumByDecimal { it.leftValue }
get() = budgets.sumByDecimal { it.leftValue }.setScale(currency.unit.scale)

val totalProgressPercentage: BigDecimal
get() = totalSpentValue.percentageOf(totalLimitValue).setScale(0, RoundingMode.HALF_UP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ fun ExpennyBottomSheet(
val scope = remember { ExpennyBottomSheetScope() }

ModalBottomSheet(
modifier = modifier,
modifier = modifier.padding(16.dp),
sheetState = sheetState,
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
shape = RoundedCornerShape(16.dp),
dragHandle = { BottomSheetDefaults.DragHandle() },
onDismissRequest = onDismiss,
windowInsets = WindowInsets(0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.expenny.core.ui.data

import org.expenny.core.common.types.IntervalType
import java.math.BigDecimal

data class PeriodicBudgetUi(
val id: Long,
val leftAmount: AmountUi,
val spentValue: BigDecimal,
val limitValue: BigDecimal,
val spentValue: AmountUi,
val limitValue: AmountUi,
val progressValue: Float,
val categories: List<CategoryUi>,
val intervalType: IntervalType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ class PeriodicBudgetMapper @Inject constructor(

operator fun invoke(model: BudgetGroup.Periodic): PeriodicBudgetUi {
val leftAmount = amountMapper(CurrencyAmount(model.totalLeftValue, model.currency))
val spentAmount = amountMapper(CurrencyAmount(model.totalSpentValue, model.currency))
val limitAmount = amountMapper(CurrencyAmount(model.totalLimitValue, model.currency))
val categories = categoryMapper(model.budgets.map { it.category })

return with(model) {
PeriodicBudgetUi(
id = id,
leftAmount = leftAmount,
spentValue = totalSpentValue,
limitValue = totalLimitValue,
spentValue = spentAmount,
limitValue = limitAmount,
progressValue = totalProgressPercentage.toFloat().div(100f),
intervalType = intervalType,
categories = categories,
Expand Down
1 change: 1 addition & 0 deletions docs/architecture_diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.material3.SheetState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand Down Expand Up @@ -133,7 +134,8 @@ internal fun BudgetsListContent(
items = state.periodicBudgets,
key = { it.id }
) {
PeriodicBudgetItem(
BudgetItem(
modifier = Modifier.fillMaxWidth(),
data = it,
onClick = { onAction(BudgetsListAction.OnPeriodicBudgetClick(it.id, it.intervalType)) },
onLongClick = { onAction(BudgetsListAction.OnPeriodicBudgetLongClick(it.id, it.intervalType)) }
Expand Down Expand Up @@ -183,38 +185,16 @@ private fun PeriodicBudgetIntervalType(
}
}

@Composable
private fun PeriodicBudgetItem(
modifier: Modifier = Modifier,
data: PeriodicBudgetUi,
onClick: () -> Unit,
onLongClick: () -> Unit
) {
Column(modifier = modifier.fillMaxWidth()) {
Text(
modifier = Modifier
.fillMaxWidth()
.height(32.dp),
text = stringArrayResource(R.array.budget_period_type)[data.intervalType.ordinal],
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
BudgetItem(
modifier = Modifier.fillMaxWidth(),
data = data,
onClick = onClick,
onLongClick = onLongClick
)
}
}

@Composable
private fun BudgetItem(
modifier: Modifier = Modifier,
data: PeriodicBudgetUi,
onClick: () -> Unit,
onLongClick: () -> Unit
) {
val periodType = stringArrayResource(R.array.budget_period_type)[data.intervalType.ordinal]
val title = stringResource(R.string.periodic_budget_label, periodType)

ExpennyCard(
modifier = modifier,
onClick = onClick,
Expand All @@ -226,21 +206,20 @@ private fun BudgetItem(
horizontalAlignment = Alignment.Start
) {
Row(
verticalAlignment = Alignment.Top,
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = stringResource(R.string.remaining_funds_label),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
Text(
text = data.leftAmount.displayValue,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleLarge
)
}
Text(
text = title,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleMedium
)
Text(
text = data.limitValue.displayValue,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleMedium
)
}
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
Expand All @@ -260,18 +239,17 @@ private fun BudgetItem(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = data.spentValue.toString(),
text = data.spentValue.value.toString(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
Text(
text = data.limitValue.toString(),
text = data.leftAmount.value.toString(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
}

if (data.categories.isNotEmpty()) {
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,37 @@ internal fun BudgetOverviewContent(
contentWindowInsets = WindowInsets.statusBars,
containerColor = MaterialTheme.colorScheme.surface,
) { paddingValues ->
LazyColumn(
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues),
state = listState,
contentPadding = ExpennyVerticalListPaddingValues,
.padding(paddingValues)
.padding(ExpennyVerticalListPaddingValues),
verticalArrangement = Arrangement.spacedBy(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
ExpennyAccountsFilter(
modifier = Modifier.fillMaxWidth(),
listState = accountsFilterListState,
state = state.accountsFilterState,
onSelect = { onAction(BudgetOverviewAction.OnAccountSelect(it)) },
onSelectAll = { onAction(BudgetOverviewAction.OnAllAccountsSelect) }
)
}
ExpennyAccountsFilter(
modifier = Modifier.fillMaxWidth(),
listState = accountsFilterListState,
state = state.accountsFilterState,
onSelect = { onAction(BudgetOverviewAction.OnAccountSelect(it)) },
onSelectAll = { onAction(BudgetOverviewAction.OnAllAccountsSelect) }
)
if (state.isReadonly) {
item {
ExpennyMessage {
MessageText(text = stringResource(id = R.string.readonly_budget_overview_paragraph))
}
ExpennyMessage {
MessageText(text = stringResource(id = R.string.readonly_budget_overview_paragraph))
}
}
item {
BudgetOverviewProgressIndicator(
progress = state.overview.progressValue,
lowerBound = state.overview.spentValue,
upperBound = state.overview.limitValue,
value = state.overview.leftAmount?.displayValue ?: stringResource(R.string.not_assigned_label)
)
}
item {
BudgetLimitsList(
limits = state.overview.budgets,
onClick = { onAction(BudgetOverviewAction.OnBudgetLimitClick(it)) },
onAddNewClick = { onAction(BudgetOverviewAction.OnAddBudgetLimitClick) },
)
}
BudgetOverviewProgressIndicator(
progress = state.overview.progressValue,
lowerBound = state.overview.spentValue,
upperBound = state.overview.limitValue,
value = state.overview.leftAmount?.displayValue ?: stringResource(R.string.not_assigned_label)
)
BudgetLimitsList(
limits = state.overview.budgets,
onClick = { onAction(BudgetOverviewAction.OnBudgetLimitClick(it)) },
onAddNewClick = { onAction(BudgetOverviewAction.OnAddBudgetLimitClick) },
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,26 @@ internal fun BudgetOverviewProgressIndicator(
)
}
}
Row(
modifier = Modifier.then(
with(LocalDensity.current) {
Modifier.width(progressIndicatorWidth.width.toDp() + 44.dp)
}
),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = lowerBound.toMonetaryString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = upperBound.toMonetaryString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
if (progressIndicatorWidth != IntSize.Zero) {
Row(
modifier = Modifier.then(
with(LocalDensity.current) {
Modifier.width(progressIndicatorWidth.width.toDp() + 44.dp)
}
),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = lowerBound.toMonetaryString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = upperBound.toMonetaryString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
}
}
Expand Down

0 comments on commit 17c8728

Please sign in to comment.