mirror of https://github.com/tasks/tasks
Subtask support on Android Wear
parent
751c8aabc1
commit
45fbb2794d
@ -0,0 +1,27 @@
|
||||
package org.tasks.presentation.components
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ExpandMore
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.wear.compose.material.Icon
|
||||
import androidx.wear.compose.material.MaterialTheme
|
||||
|
||||
@Composable
|
||||
fun Chevron(collapsed: Boolean) {
|
||||
val rotation by animateFloatAsState(
|
||||
targetValue = if (collapsed) 0f else 180f,
|
||||
animationSpec = tween(250),
|
||||
label = "arrow rotation",
|
||||
)
|
||||
Icon(
|
||||
modifier = Modifier.rotate(rotation),
|
||||
imageVector = Icons.Outlined.ExpandMore,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colors.onSurface,
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package org.tasks.presentation.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.wear.compose.material.MaterialTheme
|
||||
import androidx.wear.compose.material.Text
|
||||
|
||||
@Composable
|
||||
fun GroupSeparator(
|
||||
title: String,
|
||||
collapsed: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier
|
||||
.clip(MaterialTheme.shapes.large)
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick)
|
||||
.padding(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Chevron(collapsed = collapsed)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package org.tasks.presentation.components
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.painter.ColorPainter
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.wear.compose.material.Button
|
||||
import androidx.wear.compose.material.ButtonDefaults
|
||||
import androidx.wear.compose.material.Card
|
||||
import androidx.wear.compose.material.MaterialTheme
|
||||
import androidx.wear.compose.material.Text
|
||||
|
||||
@Composable
|
||||
fun TaskCard(
|
||||
text: String,
|
||||
hidden: Boolean = false,
|
||||
numSubtasks: Int = 0,
|
||||
subtasksCollapsed: Boolean = false,
|
||||
toggleSubtasks: () -> Unit = {},
|
||||
icon: @Composable () -> Unit = {},
|
||||
backgroundColor: Color = MaterialTheme.colors.surface,
|
||||
contentColor: Color = MaterialTheme.colors.onSurface,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Card(
|
||||
onClick = onClick,
|
||||
backgroundPainter = ColorPainter(backgroundColor),
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
icon()
|
||||
Text(
|
||||
text = text,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = contentColor,
|
||||
modifier = Modifier.alpha(if (hidden) .6f else 1f).weight(1f),
|
||||
)
|
||||
if (numSubtasks > 0) {
|
||||
Button(
|
||||
onClick = toggleSubtasks,
|
||||
colors = ButtonDefaults.outlinedButtonColors()
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = numSubtasks.toString(), // TODO: use number formatter
|
||||
color = contentColor,
|
||||
)
|
||||
Chevron(subtasksCollapsed)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue