Make Preference disableable
This commit is contained in:
parent
a7536f649c
commit
703f0127d6
@ -2,15 +2,14 @@ package de.mm20.launcher2.ui.component.preferences
|
|||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.Icon
|
import androidx.compose.material.*
|
||||||
import androidx.compose.material.MaterialTheme
|
|
||||||
import androidx.compose.material.Surface
|
|
||||||
import androidx.compose.material.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import de.mm20.launcher2.ui.ktx.conditional
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Preference(
|
fun Preference(
|
||||||
@ -18,52 +17,56 @@ fun Preference(
|
|||||||
title: String,
|
title: String,
|
||||||
summary: String? = null,
|
summary: String? = null,
|
||||||
onClick: () -> Unit = {},
|
onClick: () -> Unit = {},
|
||||||
controls: @Composable (() -> Unit)? = null
|
controls: @Composable (() -> Unit)? = null,
|
||||||
|
enabled: Boolean = true
|
||||||
) {
|
) {
|
||||||
Surface(
|
CompositionLocalProvider(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
LocalContentAlpha provides if (enabled) ContentAlpha.high else ContentAlpha.disabled
|
||||||
elevation = 0.dp
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Surface(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
modifier = Modifier
|
elevation = 0.dp
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable(onClick = onClick)
|
|
||||||
.padding(horizontal = 16.dp, vertical = 16.dp),
|
|
||||||
) {
|
) {
|
||||||
Box(
|
Row(
|
||||||
modifier = Modifier.width(56.dp),
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
contentAlignment = Alignment.CenterStart
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.conditional(enabled, Modifier.clickable(onClick = onClick))
|
||||||
|
.padding(horizontal = 16.dp, vertical = 16.dp),
|
||||||
) {
|
) {
|
||||||
if (icon != null) {
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier.padding(start = 4.dp),
|
|
||||||
imageVector = icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colors.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Text(text = title, style = MaterialTheme.typography.subtitle2)
|
|
||||||
if (summary != null) {
|
|
||||||
Text(
|
|
||||||
text = summary,
|
|
||||||
style = MaterialTheme.typography.body1,
|
|
||||||
modifier = Modifier.padding(top = 1.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (controls != null) {
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.padding(start = 24.dp)
|
modifier = Modifier.width(56.dp),
|
||||||
|
contentAlignment = Alignment.CenterStart
|
||||||
) {
|
) {
|
||||||
controls()
|
if (icon != null) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.padding(start = 4.dp),
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colors.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
) {
|
||||||
|
Text(text = title, style = MaterialTheme.typography.subtitle2)
|
||||||
|
if (summary != null) {
|
||||||
|
Text(
|
||||||
|
text = summary,
|
||||||
|
style = MaterialTheme.typography.body1,
|
||||||
|
modifier = Modifier.padding(top = 1.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (controls != null) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(start = 24.dp)
|
||||||
|
) {
|
||||||
|
controls()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user