mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-30 01:15:05 -05:00
Add Composable preview for preferences
...except Android Studio refuses to actually render them.
This commit is contained in:
parent
a7decdb62d
commit
11f1482818
1 changed files with 51 additions and 2 deletions
|
@ -17,8 +17,10 @@ import androidx.compose.runtime.Composable
|
||||||
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.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.kanade.core.prefs.PreferenceMutableState
|
import eu.kanade.core.prefs.PreferenceMutableState
|
||||||
|
import eu.kanade.presentation.theme.TachiyomiTheme
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
import eu.kanade.presentation.util.horizontalPadding
|
||||||
|
|
||||||
const val DIVIDER_ALPHA = 0.2f
|
const val DIVIDER_ALPHA = 0.2f
|
||||||
|
@ -102,7 +104,8 @@ fun PreferenceRow(
|
||||||
@Composable
|
@Composable
|
||||||
fun SwitchPreference(
|
fun SwitchPreference(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
preference: PreferenceMutableState<Boolean>,
|
checked: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String? = null,
|
subtitle: String? = null,
|
||||||
painter: Painter? = null,
|
painter: Painter? = null,
|
||||||
|
@ -112,7 +115,53 @@ fun SwitchPreference(
|
||||||
title = title,
|
title = title,
|
||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
painter = painter,
|
painter = painter,
|
||||||
action = { Switch(checked = preference.value, onCheckedChange = null) },
|
action = { Switch(checked = checked, onCheckedChange = null) },
|
||||||
|
onClick = onClick,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SwitchPreference(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
preference: PreferenceMutableState<Boolean>,
|
||||||
|
title: String,
|
||||||
|
subtitle: String? = null,
|
||||||
|
painter: Painter? = null,
|
||||||
|
) {
|
||||||
|
SwitchPreference(
|
||||||
|
modifier = modifier,
|
||||||
|
title = title,
|
||||||
|
subtitle = subtitle,
|
||||||
|
painter = painter,
|
||||||
|
checked = preference.value,
|
||||||
onClick = { preference.value = !preference.value },
|
onClick = { preference.value = !preference.value },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
private fun PreferencesPreview() {
|
||||||
|
TachiyomiTheme {
|
||||||
|
Column {
|
||||||
|
PreferenceRow(
|
||||||
|
title = "Plain",
|
||||||
|
subtitle = "Subtitle",
|
||||||
|
)
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
SwitchPreference(
|
||||||
|
title = "Switch (on)",
|
||||||
|
subtitle = "Subtitle",
|
||||||
|
checked = true,
|
||||||
|
onClick = {},
|
||||||
|
)
|
||||||
|
SwitchPreference(
|
||||||
|
title = "Switch (off)",
|
||||||
|
subtitle = "Subtitle",
|
||||||
|
checked = false,
|
||||||
|
onClick = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue