Compare commits
No commits in common. "1ab75f4701e6e8c8f325666178b6a28b0aa841e9" and "c75439d15a96410d125cc73c2975f56a72bed62f" have entirely different histories.
1ab75f4701
...
c75439d15a
@ -1,6 +1,5 @@
|
|||||||
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.*
|
||||||
@ -23,7 +22,9 @@ import java.time.YearMonth
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MonthYearPickerDialog(
|
fun MonthYearPickerDialog(
|
||||||
selectedMonth: YearMonth, onMonthSelected: (YearMonth) -> Unit, onDismiss: () -> Unit
|
selectedMonth: YearMonth,
|
||||||
|
onMonthSelected: (YearMonth) -> Unit,
|
||||||
|
onDismiss: () -> Unit
|
||||||
) {
|
) {
|
||||||
var currentYearMonth by remember { mutableStateOf(selectedMonth) }
|
var currentYearMonth by remember { mutableStateOf(selectedMonth) }
|
||||||
|
|
||||||
@ -70,7 +71,8 @@ fun MonthYearPickerDialog(
|
|||||||
|
|
||||||
// 月份网格
|
// 月份网格
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(3), modifier = Modifier.height(200.dp)
|
columns = GridCells.Fixed(3),
|
||||||
|
modifier = Modifier.height(200.dp)
|
||||||
) {
|
) {
|
||||||
items(12) { index ->
|
items(12) { index ->
|
||||||
val month = index + 1
|
val month = index + 1
|
||||||
@ -124,7 +126,6 @@ fun MonthYearPickerDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MonthlyStatistics(
|
fun MonthlyStatistics(
|
||||||
totalIncome: Double,
|
totalIncome: Double,
|
||||||
@ -162,9 +163,11 @@ fun MonthlyStatistics(
|
|||||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, "上个月")
|
Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, "上个月")
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(text = "${selectedMonth.year}年${selectedMonth.monthValue}月",
|
Text(
|
||||||
|
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, "下个月")
|
||||||
@ -174,38 +177,24 @@ fun MonthlyStatistics(
|
|||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
// 支出统计
|
|
||||||
Column(modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.clickable { onExpenseClick() }
|
|
||||||
.background(
|
|
||||||
if (selectedType == TransactionType.EXPENSE) MaterialTheme.colorScheme.primaryContainer
|
|
||||||
else Color.Transparent, RoundedCornerShape(8.dp)
|
|
||||||
)
|
|
||||||
.padding(8.dp)) {
|
|
||||||
Text(
|
|
||||||
text = "支出", 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
|
Column(
|
||||||
.weight(1f)
|
modifier = Modifier
|
||||||
.clickable { onIncomeClick() }
|
.weight(1f)
|
||||||
.background(
|
.clickable { onIncomeClick() }
|
||||||
if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer
|
.background(
|
||||||
else Color.Transparent, RoundedCornerShape(8.dp)
|
if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer
|
||||||
)
|
else Color.Transparent,
|
||||||
.padding(8.dp)) {
|
RoundedCornerShape(8.dp)
|
||||||
|
)
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "收入", style = MaterialTheme.typography.titleMedium
|
text = "收入",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "¥${String.format("%.2f", totalIncome)}",
|
text = "¥${String.format("%.2f", totalIncome)}",
|
||||||
@ -215,30 +204,35 @@ fun MonthlyStatistics(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
// 结余统计
|
|
||||||
Column(modifier = Modifier
|
// 支出统计
|
||||||
.weight(1f)
|
Column(
|
||||||
.clickable { onClearFilter() }
|
modifier = Modifier
|
||||||
.background(
|
.weight(1f)
|
||||||
if (selectedType == TransactionType.INCOME) MaterialTheme.colorScheme.primaryContainer
|
.clickable { onExpenseClick() }
|
||||||
else Color.Transparent, RoundedCornerShape(8.dp)
|
.background(
|
||||||
)
|
if (selectedType == TransactionType.EXPENSE) MaterialTheme.colorScheme.primaryContainer
|
||||||
.padding(8.dp)) {
|
else Color.Transparent,
|
||||||
|
RoundedCornerShape(8.dp)
|
||||||
|
)
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "结余", style = MaterialTheme.typography.titleMedium
|
text = "支出",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "¥${String.format("%.2f", totalIncome - totalExpense)}",
|
text = "¥${String.format("%.2f", totalExpense)}",
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
color = if (totalIncome >= totalExpense) MaterialTheme.colorScheme.tertiary
|
color = MaterialTheme.colorScheme.error
|
||||||
else MaterialTheme.colorScheme.error
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedType != null) {
|
if (selectedType != null) {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = onClearFilter, modifier = Modifier.align(Alignment.End)
|
onClick = onClearFilter,
|
||||||
|
modifier = Modifier.align(Alignment.End)
|
||||||
) {
|
) {
|
||||||
Text("清除筛选")
|
Text("清除筛选")
|
||||||
}
|
}
|
||||||
@ -247,8 +241,10 @@ fun MonthlyStatistics(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showMonthPicker) {
|
if (showMonthPicker) {
|
||||||
MonthYearPickerDialog(selectedMonth = selectedMonth,
|
MonthYearPickerDialog(
|
||||||
|
selectedMonth = selectedMonth,
|
||||||
onMonthSelected = onMonthSelected,
|
onMonthSelected = onMonthSelected,
|
||||||
onDismiss = { showMonthPicker = false })
|
onDismiss = { showMonthPicker = false }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user