From 96fe734ccdf6ba081216b5559dcfa1fa8cc9946a Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:13:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=B7=B2=E5=AE=8C=E6=88=90=E5=BE=85=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 只是完成功能,后续会根据用户自定设置来动态显示 --- .../super12138/todo/ui/pages/main/MainPage.kt | 24 +++++-------------- .../todo/ui/pages/main/ManagerFragment.kt | 1 + .../todo/ui/pages/main/components/TodoCard.kt | 6 ++++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt index 5e92814..32f6347 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt @@ -1,9 +1,7 @@ package cn.super12138.todo.ui.pages.main import androidx.activity.compose.BackHandler -import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.animateColorAsState import androidx.compose.animation.expandIn import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut @@ -13,19 +11,8 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.Close -import androidx.compose.material.icons.outlined.Delete -import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material.icons.outlined.Settings import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable @@ -38,9 +25,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.window.core.layout.WindowWidthSizeClass -import cn.super12138.todo.R import cn.super12138.todo.logic.database.TodoEntity import cn.super12138.todo.ui.pages.main.components.TodoFAB import cn.super12138.todo.ui.pages.main.components.TodoTopAppBar @@ -72,6 +57,10 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) { } } + val showCompleted = true // 后续替换成用户设置 + val filteredTodoList = + if (showCompleted) toDoList.value else toDoList.value.filter { item -> !item.isCompleted } + BackHandler(enabled = !isSelectedIdsEmpty) { // 当按下返回键(或进行返回操作)时清空选择 viewModel.clearAllTodoSelection() @@ -114,7 +103,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) { ManagerFragment( state = listState, - list = toDoList.value.filter { item -> !item.isCompleted }, + list = filteredTodoList, onItemClick = { item -> if (isSelectedIdsEmpty) { openBottomSheet = true @@ -154,10 +143,9 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) { .weight(2f) .fillMaxSize() ) - ManagerFragment( state = listState, - list = toDoList.value.filter { item -> !item.isCompleted }, + list = filteredTodoList, onItemClick = { item -> if (isSelectedIdsEmpty) { openBottomSheet = true diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt index e2096e7..1f4ff8e 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt @@ -68,6 +68,7 @@ fun ManagerFragment( TodoCard( content = item.content, subject = Subjects.fromId(item.subject).getDisplayName(context), + completed = item.isCompleted, onCardClick = { onItemClick(item) }, onCardLongClick = { onItemLongClick(item) }, onChecked = { onItemChecked(item) }, diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt index 3e60353..74cb07e 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import cn.super12138.todo.R @@ -35,6 +36,7 @@ import cn.super12138.todo.R fun TodoCard( content: String, subject: String, + completed: Boolean, onCardClick: () -> Unit = {}, onCardLongClick: () -> Unit = {}, onChecked: () -> Unit = {}, @@ -82,16 +84,18 @@ fun TodoCard( style = MaterialTheme.typography.titleLarge, maxLines = 1, overflow = TextOverflow.Ellipsis, + textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None, modifier = Modifier.basicMarquee() // TODO: 后续评估性能影响 ) Text( text = subject, style = MaterialTheme.typography.labelMedium, + textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None, maxLines = 1 ) } - AnimatedVisibility(!selected) { + AnimatedVisibility(!selected && !completed) { IconButton(onClick = onChecked) { Icon( imageVector = Icons.Outlined.Check,