2022-04-23 12:05:00 -04:00
|
|
|
package eu.kanade.presentation.components
|
|
|
|
|
|
|
|
import androidx.compose.foundation.combinedClickable
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
2022-04-23 12:42:35 -04:00
|
|
|
import androidx.compose.foundation.layout.heightIn
|
2022-04-23 12:05:00 -04:00
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
import androidx.compose.foundation.layout.widthIn
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
2022-04-23 15:51:50 -04:00
|
|
|
import androidx.compose.material3.Switch
|
2022-04-23 12:05:00 -04:00
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Modifier
|
2022-04-23 15:51:50 -04:00
|
|
|
import androidx.compose.ui.graphics.painter.Painter
|
2022-04-23 12:05:00 -04:00
|
|
|
import androidx.compose.ui.unit.dp
|
2022-04-23 15:51:50 -04:00
|
|
|
import eu.kanade.core.prefs.PreferenceMutableState
|
2022-04-23 12:05:00 -04:00
|
|
|
import eu.kanade.presentation.util.horizontalPadding
|
|
|
|
|
2022-04-23 12:42:35 -04:00
|
|
|
@Composable
|
2022-04-30 09:43:49 -04:00
|
|
|
fun Divider(
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
) {
|
2022-04-23 12:42:35 -04:00
|
|
|
androidx.compose.material3.Divider(
|
2022-04-30 09:43:49 -04:00
|
|
|
modifier = modifier,
|
2022-04-23 12:42:35 -04:00
|
|
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:05:00 -04:00
|
|
|
@Composable
|
|
|
|
fun PreferenceRow(
|
2022-04-30 09:43:49 -04:00
|
|
|
modifier: Modifier = Modifier,
|
2022-04-23 12:05:00 -04:00
|
|
|
title: String,
|
2022-04-23 15:51:50 -04:00
|
|
|
painter: Painter? = null,
|
2022-04-23 12:05:00 -04:00
|
|
|
onClick: () -> Unit = {},
|
|
|
|
onLongClick: () -> Unit = {},
|
|
|
|
subtitle: String? = null,
|
|
|
|
action: @Composable (() -> Unit)? = null,
|
|
|
|
) {
|
|
|
|
val height = if (subtitle != null) 72.dp else 56.dp
|
|
|
|
|
2022-04-24 14:39:51 -04:00
|
|
|
val titleTextStyle = MaterialTheme.typography.bodyLarge
|
2022-04-23 12:42:35 -04:00
|
|
|
val subtitleTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
|
|
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.75f),
|
2022-04-23 12:05:00 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
Row(
|
2022-04-30 09:43:49 -04:00
|
|
|
modifier = modifier
|
2022-04-23 12:05:00 -04:00
|
|
|
.fillMaxWidth()
|
2022-04-23 12:42:35 -04:00
|
|
|
.heightIn(min = height)
|
2022-04-23 12:05:00 -04:00
|
|
|
.combinedClickable(
|
|
|
|
onLongClick = onLongClick,
|
2022-04-23 15:51:50 -04:00
|
|
|
onClick = onClick,
|
2022-04-23 12:05:00 -04:00
|
|
|
),
|
2022-05-10 17:54:52 -04:00
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
2022-04-23 12:05:00 -04:00
|
|
|
) {
|
2022-04-23 15:51:50 -04:00
|
|
|
if (painter != null) {
|
2022-04-23 12:05:00 -04:00
|
|
|
Icon(
|
2022-04-23 15:51:50 -04:00
|
|
|
painter = painter,
|
2022-04-23 12:05:00 -04:00
|
|
|
modifier = Modifier
|
|
|
|
.padding(horizontal = horizontalPadding)
|
|
|
|
.size(24.dp),
|
|
|
|
tint = MaterialTheme.colorScheme.primary,
|
2022-04-23 15:51:50 -04:00
|
|
|
contentDescription = null,
|
2022-04-23 12:05:00 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
Column(
|
|
|
|
Modifier
|
|
|
|
.padding(horizontal = horizontalPadding)
|
2022-05-10 17:54:52 -04:00
|
|
|
.weight(1f),
|
2022-04-23 12:05:00 -04:00
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
text = title,
|
2022-04-23 12:42:35 -04:00
|
|
|
style = titleTextStyle,
|
2022-04-23 12:05:00 -04:00
|
|
|
)
|
|
|
|
if (subtitle != null) {
|
|
|
|
Text(
|
2022-04-23 12:42:35 -04:00
|
|
|
modifier = Modifier.padding(top = 4.dp),
|
2022-04-23 12:05:00 -04:00
|
|
|
text = subtitle,
|
2022-04-23 12:42:35 -04:00
|
|
|
style = subtitleTextStyle,
|
2022-04-23 12:05:00 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (action != null) {
|
|
|
|
Box(Modifier.widthIn(min = 56.dp)) {
|
|
|
|
action()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-23 15:51:50 -04:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun SwitchPreference(
|
2022-04-30 09:43:49 -04:00
|
|
|
modifier: Modifier = Modifier,
|
2022-04-23 15:51:50 -04:00
|
|
|
preference: PreferenceMutableState<Boolean>,
|
|
|
|
title: String,
|
|
|
|
subtitle: String? = null,
|
|
|
|
painter: Painter? = null,
|
|
|
|
) {
|
|
|
|
PreferenceRow(
|
2022-04-30 09:43:49 -04:00
|
|
|
modifier = modifier,
|
2022-04-23 15:51:50 -04:00
|
|
|
title = title,
|
|
|
|
subtitle = subtitle,
|
|
|
|
painter = painter,
|
|
|
|
action = {
|
|
|
|
Switch(checked = preference.value, onCheckedChange = null)
|
|
|
|
// TODO: remove this once switch checked state is fixed: https://issuetracker.google.com/issues/228336571
|
|
|
|
Text(preference.value.toString())
|
|
|
|
},
|
|
|
|
onClick = { preference.value = !preference.value },
|
|
|
|
)
|
|
|
|
}
|