Compare commits

...

5 Commits

Author SHA1 Message Date
1ab75f4701 Merge branch 'develop' into feature/member
修改
2024-11-27 16:18:26 +08:00
773c155d0c 修复警告 2024-11-27 16:08:34 +08:00
3ad8cf9184 Revert "修复警告"
This reverts commit 1147bc47d7.
2024-11-27 16:07:37 +08:00
1147bc47d7 修复警告 2024-11-27 16:07:10 +08:00
30e9345d81 优化: 主页统计功能改进
- 调整主页统计区域布局和样式
- 优化支出、收入、结余的显示顺序
- 改进结余区域的高亮显示逻辑
- 简化代码结构和格式
2024-11-27 14:27:26 +08:00

View File

@ -1,5 +1,6 @@
package com.yovinchen.bookkeeping.ui.components package com.yovinchen.bookkeeping.ui.components
import android.annotation.SuppressLint
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -22,9 +23,7 @@ import java.time.YearMonth
@Composable @Composable
fun MonthYearPickerDialog( fun MonthYearPickerDialog(
selectedMonth: YearMonth, selectedMonth: YearMonth, onMonthSelected: (YearMonth) -> Unit, onDismiss: () -> Unit
onMonthSelected: (YearMonth) -> Unit,
onDismiss: () -> Unit
) { ) {
var currentYearMonth by remember { mutableStateOf(selectedMonth) } var currentYearMonth by remember { mutableStateOf(selectedMonth) }
@ -71,8 +70,7 @@ fun MonthYearPickerDialog(
// 月份网格 // 月份网格
LazyVerticalGrid( LazyVerticalGrid(
columns = GridCells.Fixed(3), columns = GridCells.Fixed(3), modifier = Modifier.height(200.dp)
modifier = Modifier.height(200.dp)
) { ) {
items(12) { index -> items(12) { index ->
val month = index + 1 val month = index + 1
@ -126,6 +124,7 @@ fun MonthYearPickerDialog(
} }
} }
@SuppressLint("DefaultLocale")
@Composable @Composable
fun MonthlyStatistics( fun MonthlyStatistics(
totalIncome: Double, totalIncome: Double,
@ -163,11 +162,9 @@ fun MonthlyStatistics(
Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, "上个月") Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, "上个月")
} }
Text( Text(text = "${selectedMonth.year}${selectedMonth.monthValue}",
text = "${selectedMonth.year}${selectedMonth.monthValue}",
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
modifier = Modifier.clickable { showMonthPicker = true } modifier = Modifier.clickable { showMonthPicker = true })
)
IconButton(onClick = onNextMonth) { IconButton(onClick = onNextMonth) {
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, "下个月") Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, "下个月")
@ -177,24 +174,38 @@ fun MonthlyStatistics(
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween
horizontalArrangement = Arrangement.SpaceBetween
) { ) {
// 收入统计 // 支出统计
Column( Column(modifier = Modifier
modifier = Modifier .weight(1f)
.weight(1f) .clickable { onExpenseClick() }
.clickable { onIncomeClick() } .background(
.background( if (selectedType == TransactionType.EXPENSE) MaterialTheme.colorScheme.primaryContainer
if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer else Color.Transparent, RoundedCornerShape(8.dp)
else Color.Transparent, )
RoundedCornerShape(8.dp) .padding(8.dp)) {
)
.padding(8.dp)
) {
Text( Text(
text = "收入", text = "支出", style = MaterialTheme.typography.titleMedium
style = MaterialTheme.typography.titleMedium )
Text(
text = "¥${String.format("%.2f", totalExpense)}",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.error
)
}
Spacer(modifier = Modifier.width(16.dp))
// 收入统计
Column(modifier = Modifier
.weight(1f)
.clickable { onIncomeClick() }
.background(
if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer
else Color.Transparent, RoundedCornerShape(8.dp)
)
.padding(8.dp)) {
Text(
text = "收入", style = MaterialTheme.typography.titleMedium
) )
Text( Text(
text = "¥${String.format("%.2f", totalIncome)}", text = "¥${String.format("%.2f", totalIncome)}",
@ -204,35 +215,30 @@ fun MonthlyStatistics(
} }
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
// 结余统计
// 支出统计 Column(modifier = Modifier
Column( .weight(1f)
modifier = Modifier .clickable { onClearFilter() }
.weight(1f) .background(
.clickable { onExpenseClick() } if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer
.background( else Color.Transparent, RoundedCornerShape(8.dp)
if (selectedType == TransactionType.EXPENSE) MaterialTheme.colorScheme.primaryContainer )
else Color.Transparent, .padding(8.dp)) {
RoundedCornerShape(8.dp)
)
.padding(8.dp)
) {
Text( Text(
text = "支出", text = "结余", style = MaterialTheme.typography.titleMedium
style = MaterialTheme.typography.titleMedium
) )
Text( Text(
text = "¥${String.format("%.2f", totalExpense)}", text = "¥${String.format("%.2f", totalIncome - totalExpense)}",
style = MaterialTheme.typography.bodyLarge, style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.error color = if (totalIncome >= totalExpense) MaterialTheme.colorScheme.tertiary
else MaterialTheme.colorScheme.error
) )
} }
} }
if (selectedType != null) { if (selectedType != null) {
TextButton( TextButton(
onClick = onClearFilter, onClick = onClearFilter, modifier = Modifier.align(Alignment.End)
modifier = Modifier.align(Alignment.End)
) { ) {
Text("清除筛选") Text("清除筛选")
} }
@ -241,10 +247,8 @@ fun MonthlyStatistics(
} }
if (showMonthPicker) { if (showMonthPicker) {
MonthYearPickerDialog( MonthYearPickerDialog(selectedMonth = selectedMonth,
selectedMonth = selectedMonth,
onMonthSelected = onMonthSelected, onMonthSelected = onMonthSelected,
onDismiss = { showMonthPicker = false } onDismiss = { showMonthPicker = false })
)
} }
} }