|
|
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.outlined.Add
|
|
|
|
|
import androidx.compose.material.icons.outlined.CheckBox
|
|
|
|
|
import androidx.compose.material.icons.outlined.CheckBoxOutlineBlank
|
|
|
|
|
import androidx.compose.material.icons.outlined.Repeat
|
|
|
|
@ -15,6 +16,7 @@ import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.graphics.painter.ColorPainter
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.paging.compose.LazyPagingItems
|
|
|
|
|
import androidx.wear.compose.material.Button
|
|
|
|
@ -28,8 +30,11 @@ import com.google.android.horologist.compose.layout.ScalingLazyColumn
|
|
|
|
|
import com.google.android.horologist.compose.layout.ScreenScaffold
|
|
|
|
|
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
|
|
|
|
|
import com.google.android.horologist.compose.paging.items
|
|
|
|
|
import org.jetbrains.compose.resources.stringResource
|
|
|
|
|
import org.tasks.GrpcProto
|
|
|
|
|
import org.tasks.kmp.org.tasks.themes.ColorProvider
|
|
|
|
|
import tasks.kmp.generated.resources.Res
|
|
|
|
|
import tasks.kmp.generated.resources.add_task
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalHorologistApi::class)
|
|
|
|
|
@Composable
|
|
|
|
@ -37,6 +42,7 @@ fun TaskListScreen(
|
|
|
|
|
uiItems: LazyPagingItems<GrpcProto.UiItem>,
|
|
|
|
|
onComplete: (Long) -> Unit,
|
|
|
|
|
onClick: (Long) -> Unit,
|
|
|
|
|
addTask: () -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
val columnState = rememberResponsiveColumnState()
|
|
|
|
|
ScreenScaffold(
|
|
|
|
@ -46,24 +52,59 @@ fun TaskListScreen(
|
|
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
|
|
columnState = columnState,
|
|
|
|
|
) {
|
|
|
|
|
item {
|
|
|
|
|
TaskCard(
|
|
|
|
|
text = stringResource(Res.string.add_task),
|
|
|
|
|
icon = {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Outlined.Add,
|
|
|
|
|
tint = MaterialTheme.colors.onPrimary,
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
modifier = Modifier.padding(12.dp),
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
backgroundColor = MaterialTheme.colors.primary,
|
|
|
|
|
contentColor = MaterialTheme.colors.onPrimary,
|
|
|
|
|
onClick = addTask,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
items(
|
|
|
|
|
items = uiItems,
|
|
|
|
|
key = { item -> "${item.type}_${item.id}" },
|
|
|
|
|
) { item ->
|
|
|
|
|
if (item == null) {
|
|
|
|
|
TaskCard(
|
|
|
|
|
task = GrpcProto.UiItem.getDefaultInstance(),
|
|
|
|
|
showCheckbox = false,
|
|
|
|
|
onComplete = {},
|
|
|
|
|
text = "",
|
|
|
|
|
icon = {},
|
|
|
|
|
onClick = {},
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
when (item.type) {
|
|
|
|
|
GrpcProto.UiItemType.Task ->
|
|
|
|
|
TaskCard(
|
|
|
|
|
task = item,
|
|
|
|
|
showCheckbox = true,
|
|
|
|
|
onComplete = { onComplete(item.id) },
|
|
|
|
|
text = item.title,
|
|
|
|
|
icon = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = { onComplete(item.id) },
|
|
|
|
|
colors = ButtonDefaults.iconButtonColors(),
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = when {
|
|
|
|
|
item.completed -> Icons.Outlined.CheckBox
|
|
|
|
|
item.repeating -> Icons.Outlined.Repeat
|
|
|
|
|
else -> Icons.Outlined.CheckBoxOutlineBlank
|
|
|
|
|
},
|
|
|
|
|
tint = Color(
|
|
|
|
|
ColorProvider.priorityColor(
|
|
|
|
|
item.priority,
|
|
|
|
|
isDarkMode = true,
|
|
|
|
|
desaturate = true
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onClick = { onClick(item.id) },
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -95,44 +136,26 @@ fun GroupSeparator(
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun TaskCard(
|
|
|
|
|
task: GrpcProto.UiItem,
|
|
|
|
|
showCheckbox: Boolean,
|
|
|
|
|
onComplete: () -> Unit,
|
|
|
|
|
text: String,
|
|
|
|
|
icon: @Composable () -> Unit = {},
|
|
|
|
|
backgroundColor: Color = MaterialTheme.colors.surface,
|
|
|
|
|
contentColor: Color = MaterialTheme.colors.onSurface,
|
|
|
|
|
onClick: () -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
Card(
|
|
|
|
|
onClick = onClick,
|
|
|
|
|
backgroundPainter = ColorPainter(MaterialTheme.colors.surface),
|
|
|
|
|
backgroundPainter = ColorPainter(backgroundColor),
|
|
|
|
|
contentPadding = PaddingValues(start = 0.dp, top = 0.dp, end = 12.dp, bottom = 0.dp),
|
|
|
|
|
) {
|
|
|
|
|
Row(
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
) {
|
|
|
|
|
if (showCheckbox) {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = onComplete,
|
|
|
|
|
colors = ButtonDefaults.iconButtonColors(),
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = when {
|
|
|
|
|
task.completed -> Icons.Outlined.CheckBox
|
|
|
|
|
task.repeating -> Icons.Outlined.Repeat
|
|
|
|
|
else -> Icons.Outlined.CheckBoxOutlineBlank
|
|
|
|
|
},
|
|
|
|
|
tint = Color(
|
|
|
|
|
ColorProvider.priorityColor(
|
|
|
|
|
task.priority,
|
|
|
|
|
isDarkMode = true,
|
|
|
|
|
desaturate = true
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
icon()
|
|
|
|
|
Text(
|
|
|
|
|
text = task.title,
|
|
|
|
|
modifier = Modifier.padding(vertical = 12.dp)
|
|
|
|
|
text = text,
|
|
|
|
|
maxLines = 2,
|
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
|
color = contentColor,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|