mirror of https://github.com/tasks/tasks
Calendar picker updates
* Move some components to compose package * Add compose previews * Use calendar id for selectedpull/1964/head
parent
df65415a83
commit
135f628dae
@ -0,0 +1,87 @@
|
|||||||
|
package org.tasks.compose
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.MaterialTheme
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Block
|
||||||
|
import androidx.compose.material.icons.outlined.Event
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.google.android.material.composethemeadapter.MdcTheme
|
||||||
|
import org.tasks.R
|
||||||
|
import org.tasks.calendars.AndroidCalendar
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CalendarPickerList(
|
||||||
|
calendars: List<AndroidCalendar>,
|
||||||
|
selected: String?,
|
||||||
|
onClick: (AndroidCalendar?) -> Unit,
|
||||||
|
) {
|
||||||
|
val selectedCalendar = calendars.find { it.id == selected }
|
||||||
|
MdcTheme {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 12.dp)
|
||||||
|
) {
|
||||||
|
CheckableIconRow(
|
||||||
|
icon = Icons.Outlined.Block,
|
||||||
|
tint = MaterialTheme.colors.onSurface,
|
||||||
|
text = stringResource(id = R.string.dont_add_to_calendar),
|
||||||
|
selected = selectedCalendar == null,
|
||||||
|
onClick = { onClick(null) },
|
||||||
|
)
|
||||||
|
calendars.forEach {
|
||||||
|
CheckableIconRow(
|
||||||
|
icon = Icons.Outlined.Event,
|
||||||
|
tint = Color(it.color),
|
||||||
|
text = it.name,
|
||||||
|
selected = selectedCalendar == it,
|
||||||
|
onClick = { onClick(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true, widthDp = 320)
|
||||||
|
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES, widthDp = 320)
|
||||||
|
@Composable
|
||||||
|
fun CalendarPicker() {
|
||||||
|
MdcTheme {
|
||||||
|
CalendarPickerList(
|
||||||
|
calendars = listOf(
|
||||||
|
AndroidCalendar("1", "Home", -765666),
|
||||||
|
AndroidCalendar("2", "Work", -5434281),
|
||||||
|
AndroidCalendar("3", "Personal", -10395295),
|
||||||
|
),
|
||||||
|
selected = "2",
|
||||||
|
onClick = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true, widthDp = 320)
|
||||||
|
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES, widthDp = 320)
|
||||||
|
@Composable
|
||||||
|
fun CalendarPickerNoneSelected() {
|
||||||
|
MdcTheme {
|
||||||
|
CalendarPickerList(
|
||||||
|
calendars = listOf(
|
||||||
|
AndroidCalendar("1", "Home", -765666),
|
||||||
|
AndroidCalendar("2", "Work", -5434281),
|
||||||
|
AndroidCalendar("3", "Personal", -10395295),
|
||||||
|
),
|
||||||
|
selected = null,
|
||||||
|
onClick = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package org.tasks.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.ContentAlpha
|
||||||
|
import androidx.compose.material.Icon
|
||||||
|
import androidx.compose.material.MaterialTheme
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Check
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CheckableIconRow(
|
||||||
|
icon: ImageVector,
|
||||||
|
tint: Color,
|
||||||
|
text: String,
|
||||||
|
selected: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable { onClick() }
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = tint.copy(alpha = ContentAlpha.medium),
|
||||||
|
modifier = Modifier.padding(start = 16.dp, end = 32.dp, top = 12.dp, bottom = 12.dp),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = MaterialTheme.typography.body1,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
if (selected) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Check,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colors.primary.copy(alpha = ContentAlpha.medium),
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue