feat: 更新任务优先级的实现展示方式
This commit is contained in:
parent
3711287ad5
commit
e8af5d8538
3 changed files with 65 additions and 61 deletions
|
|
@ -0,0 +1,29 @@
|
||||||
|
package cn.super12138.todo.logic.model
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import cn.super12138.todo.R
|
||||||
|
|
||||||
|
enum class Priority(val value: Float) {
|
||||||
|
Urgent(10f),
|
||||||
|
Important(5f),
|
||||||
|
Default(0f),
|
||||||
|
NotImportant(-5f),
|
||||||
|
NotUrgent(-10f);
|
||||||
|
|
||||||
|
fun getDisplayName(context: Context): String {
|
||||||
|
val resId = when (this) {
|
||||||
|
Urgent -> R.string.priority_urgent
|
||||||
|
Important -> R.string.priority_important
|
||||||
|
Default -> R.string.priority_default
|
||||||
|
NotImportant -> R.string.priority_not_important
|
||||||
|
NotUrgent -> R.string.priority_not_urgent
|
||||||
|
}
|
||||||
|
return context.getString(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromFloat(float: Float): Priority {
|
||||||
|
return Priority.entries.find { it.value == float } ?: Default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -44,12 +44,12 @@ import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.logic.database.TodoEntity
|
import cn.super12138.todo.logic.database.TodoEntity
|
||||||
|
import cn.super12138.todo.logic.model.Priority
|
||||||
import cn.super12138.todo.logic.model.Subjects
|
import cn.super12138.todo.logic.model.Subjects
|
||||||
import cn.super12138.todo.ui.TodoDefaults
|
import cn.super12138.todo.ui.TodoDefaults
|
||||||
import cn.super12138.todo.ui.components.AnimatedExtendedFloatingActionButton
|
import cn.super12138.todo.ui.components.AnimatedExtendedFloatingActionButton
|
||||||
import cn.super12138.todo.ui.components.FilterChipGroup
|
import cn.super12138.todo.ui.components.FilterChipGroup
|
||||||
import cn.super12138.todo.ui.components.LargeTopAppBarScaffold
|
import cn.super12138.todo.ui.components.LargeTopAppBarScaffold
|
||||||
import cn.super12138.todo.ui.pages.main.components.getPriorityString
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -193,7 +193,7 @@ fun TodoEditorPage(
|
||||||
.sizeIn(45.dp, 25.dp)
|
.sizeIn(45.dp, 25.dp)
|
||||||
.wrapContentWidth()
|
.wrapContentWidth()
|
||||||
) {
|
) {
|
||||||
Text(stringResource(getPriorityString(sliderPosition)))
|
Text(Priority.fromFloat(sliderPosition).getDisplayName(context))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
interactionSource = interactionSource
|
interactionSource = interactionSource
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Check
|
import androidx.compose.material.icons.outlined.Check
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.BadgedBox
|
||||||
import androidx.compose.material3.ElevatedCard
|
import androidx.compose.material3.ElevatedCard
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
|
@ -25,13 +27,14 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
|
import cn.super12138.todo.logic.model.Priority
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -46,6 +49,7 @@ fun TodoCard(
|
||||||
onChecked: () -> Unit = {},
|
onChecked: () -> Unit = {},
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
@ -82,33 +86,39 @@ fun TodoCard(
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
Text(
|
BadgedBox(
|
||||||
text = content,
|
badge = {
|
||||||
style = MaterialTheme.typography.titleLarge,
|
Badge(
|
||||||
maxLines = 1,
|
containerColor = when (priority) {
|
||||||
overflow = TextOverflow.Ellipsis,
|
-10f -> MaterialTheme.colorScheme.surfaceContainerHighest
|
||||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
-5f -> MaterialTheme.colorScheme.surfaceContainerHighest
|
||||||
modifier = Modifier
|
0f -> MaterialTheme.colorScheme.secondary
|
||||||
.fillMaxWidth()
|
5f -> MaterialTheme.colorScheme.tertiary
|
||||||
.basicMarquee() // TODO: 后续评估性能影响
|
10f -> MaterialTheme.colorScheme.error
|
||||||
)
|
else -> MaterialTheme.colorScheme.secondary
|
||||||
Row(
|
},
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
modifier = Modifier.padding(start = 5.dp)
|
||||||
modifier = Modifier.fillMaxWidth()
|
) {
|
||||||
|
Text(Priority.fromFloat(priority).getDisplayName(context))
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = subject,
|
text = content,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||||
maxLines = 1
|
modifier = Modifier.basicMarquee() // TODO: 后续评估性能影响
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
PriorityText(
|
|
||||||
priority = priority,
|
|
||||||
isCompleted = completed
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = subject,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||||
|
maxLines = 1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedVisibility(!selected && !completed) {
|
AnimatedVisibility(!selected && !completed) {
|
||||||
|
|
@ -141,41 +151,6 @@ fun TodoCard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun PriorityText(
|
|
||||||
priority: Float,
|
|
||||||
isCompleted: Boolean,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(getPriorityString(priority)),
|
|
||||||
style = MaterialTheme.typography.labelMedium.copy(
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = when (priority) {
|
|
||||||
-10f -> MaterialTheme.colorScheme.outline
|
|
||||||
-5f -> MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
0f -> MaterialTheme.colorScheme.secondary
|
|
||||||
5f -> MaterialTheme.colorScheme.tertiary
|
|
||||||
10f -> MaterialTheme.colorScheme.onErrorContainer
|
|
||||||
else -> MaterialTheme.colorScheme.secondary
|
|
||||||
}
|
|
||||||
),
|
|
||||||
textDecoration = if (isCompleted) TextDecoration.LineThrough else TextDecoration.None,
|
|
||||||
maxLines = 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPriorityString(priority: Float): Int {
|
|
||||||
return when (priority) {
|
|
||||||
-10f -> R.string.priority_not_urgent
|
|
||||||
-5f -> R.string.priority_not_important
|
|
||||||
0f -> R.string.priority_default
|
|
||||||
5f -> R.string.priority_important
|
|
||||||
10f -> R.string.priority_urgent
|
|
||||||
else -> R.string.priority_default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(locale = "zh-rCN", showBackground = true)
|
@Preview(locale = "zh-rCN", showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun TodoCardPreview() {
|
private fun TodoCardPreview() {
|
||||||
|
|
@ -183,7 +158,7 @@ private fun TodoCardPreview() {
|
||||||
content = "背《岳阳楼记》《出师表》《琵琶行》",
|
content = "背《岳阳楼记》《出师表》《琵琶行》",
|
||||||
subject = "语文",
|
subject = "语文",
|
||||||
completed = false,
|
completed = false,
|
||||||
priority = 5f,
|
priority = Priority.Important.value,
|
||||||
selected = false,
|
selected = false,
|
||||||
onCardClick = {},
|
onCardClick = {},
|
||||||
onCardLongClick = {},
|
onCardLongClick = {},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue