fix: hide spending calendar for first bugdet after migration to transactions

This commit is contained in:
danilkinkin 2024-01-14 15:25:19 +06:00
parent c7b46335a4
commit 1f8a7149c1
3 changed files with 24 additions and 14 deletions

View file

@ -54,6 +54,7 @@ import com.danilkinkin.buckwheat.base.ButtonRow
import com.danilkinkin.buckwheat.base.LocalBottomSheetScrollState
import com.danilkinkin.buckwheat.data.AppViewModel
import com.danilkinkin.buckwheat.data.SpendsViewModel
import com.danilkinkin.buckwheat.data.entities.TransactionType
import com.danilkinkin.buckwheat.finishPeriod.categoriesChart.CategoriesChartCard
import com.danilkinkin.buckwheat.ui.BuckwheatTheme
import com.danilkinkin.buckwheat.util.combineColors
@ -78,6 +79,9 @@ fun FinishPeriod(
val spends by spendsViewModel.spends.observeAsState(emptyList())
val wholeBudget = spendsViewModel.budget.value!!
val scrollState = rememberScrollState()
// Need to hide calendar after migration to transactions,
// because after migration can't restore some transactions like INCOME & SET_DAILY_BUDGET
val afterMigrationToTransactions = remember(transactions) { mutableStateOf(transactions.none { it.type == TransactionType.INCOME }) }
val scroll = with(localDensity) { scrollState.value.toDp() }
@ -225,15 +229,17 @@ fun FinishPeriod(
modifier = Modifier.fillMaxWidth(),
count = spends.size,
)
Spacer(modifier = Modifier.height(36.dp))
SpendsCalendar(
modifier = Modifier.zIndex(-1f),
budget = wholeBudget,
transactions = transactions,
startDate = spendsViewModel.startPeriodDate.value!!,
finishDate = spendsViewModel.finishPeriodDate.value!!,
currency = spendsViewModel.currency.value!!,
)
if (!afterMigrationToTransactions.value) {
Spacer(modifier = Modifier.height(36.dp))
SpendsCalendar(
modifier = Modifier.zIndex(-1f),
budget = wholeBudget,
transactions = transactions,
startDate = spendsViewModel.startPeriodDate.value!!,
finishDate = spendsViewModel.finishPeriodDate.value!!,
currency = spendsViewModel.currency.value!!,
)
}
Spacer(modifier = Modifier.height(36.dp))
CategoriesChartCard(
modifier = Modifier.fillMaxWidth(),

View file

@ -21,7 +21,6 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@ -332,7 +331,7 @@ internal fun Day(
)
val percent = if (spendingDay !== null) {
spendingDay.spending.divide(spendingDay.budget, 2, RoundingMode.HALF_EVEN).toFloat()
spendingDay.spending.divide(spendingDay.budget.coerceAtLeast(BigDecimal(0.1)), 2, RoundingMode.HALF_EVEN).coerceIn(BigDecimal(-100), BigDecimal(100)).toFloat()
} else {
0f
}
@ -434,14 +433,19 @@ fun verticalGridMeasurePolicy(columns: Int) =
}
@Preview(name = "Zero overspending")
@Preview(name = "Zero overspending (Dark mode)", uiMode = UI_MODE_NIGHT_YES)
@Preview(name = "Default")
@Preview(name = "Default (Dark mode)", uiMode = UI_MODE_NIGHT_YES)
@Composable
private fun PreviewDefault() {
BuckwheatTheme {
SpendsCalendar(
budget = BigDecimal(200),
transactions = listOf(
Transaction(
type = TransactionType.INCOME,
value = BigDecimal(800),
date = LocalDate.now().minusDays(5).toDate()
),
Transaction(
type = TransactionType.SET_DAILY_BUDGET,
value = BigDecimal(8),

View file

@ -103,7 +103,7 @@ fun CategoriesChartCard(
// Convert to TagUsage, group by tag and sum amounts
var result = spends
.map { it.copy(comment = it.comment.ifEmpty { labelWithoutTag }) }
.groupBy { it.comment }
.groupBy { it.comment.trim() }
.map { tag ->
TagUsage(
tag.key,