Remove redundant preference composables
(cherry picked from commit dd1923fe88bbb1e7f838d560806598a4ba2174f8) # Conflicts: # app/src/main/java/eu/kanade/presentation/components/Preferences.kt
This commit is contained in:
parent
81d9ac81ce
commit
3be06eacaa
@ -54,9 +54,10 @@ import eu.kanade.presentation.components.DIVIDER_ALPHA
|
|||||||
import eu.kanade.presentation.components.Divider
|
import eu.kanade.presentation.components.Divider
|
||||||
import eu.kanade.presentation.components.EmptyScreen
|
import eu.kanade.presentation.components.EmptyScreen
|
||||||
import eu.kanade.presentation.components.LoadingScreen
|
import eu.kanade.presentation.components.LoadingScreen
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
|
||||||
import eu.kanade.presentation.components.Scaffold
|
import eu.kanade.presentation.components.Scaffold
|
||||||
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
||||||
|
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
|
||||||
|
import eu.kanade.presentation.more.settings.widget.TrailingWidgetBuffer
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
import eu.kanade.presentation.util.horizontalPadding
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
@ -402,15 +403,14 @@ private fun SourceSwitchPreference(
|
|||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
PreferenceRow(
|
TextPreferenceWidget(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = if (source.labelAsName) {
|
title = if (source.labelAsName) {
|
||||||
source.source.toString()
|
source.source.toString()
|
||||||
} else {
|
} else {
|
||||||
LocaleHelper.getSourceDisplayName(source.source.lang, context)
|
LocaleHelper.getSourceDisplayName(source.source.lang, context)
|
||||||
},
|
},
|
||||||
onClick = { onClickSource(source.source.id) },
|
widget = {
|
||||||
action = {
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
@ -424,9 +424,14 @@ private fun SourceSwitchPreference(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Switch(checked = source.enabled, onCheckedChange = null)
|
Switch(
|
||||||
|
checked = source.enabled,
|
||||||
|
onCheckedChange = null,
|
||||||
|
modifier = Modifier.padding(start = TrailingWidgetBuffer),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onPreferenceClick = { onClickSource(source.source.id) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package eu.kanade.presentation.browse
|
|||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@ -13,8 +12,8 @@ import eu.kanade.presentation.components.AppBar
|
|||||||
import eu.kanade.presentation.components.EmptyScreen
|
import eu.kanade.presentation.components.EmptyScreen
|
||||||
import eu.kanade.presentation.components.FastScrollLazyColumn
|
import eu.kanade.presentation.components.FastScrollLazyColumn
|
||||||
import eu.kanade.presentation.components.LoadingScreen
|
import eu.kanade.presentation.components.LoadingScreen
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
|
||||||
import eu.kanade.presentation.components.Scaffold
|
import eu.kanade.presentation.components.Scaffold
|
||||||
|
import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterPresenter
|
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterPresenter
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||||
@ -42,15 +41,13 @@ fun ExtensionFilterScreen(
|
|||||||
textResource = R.string.empty_screen,
|
textResource = R.string.empty_screen,
|
||||||
modifier = Modifier.padding(contentPadding),
|
modifier = Modifier.padding(contentPadding),
|
||||||
)
|
)
|
||||||
else -> {
|
else -> ExtensionFilterContent(
|
||||||
SourceFilterContent(
|
contentPadding = contentPadding,
|
||||||
contentPadding = contentPadding,
|
state = presenter,
|
||||||
state = presenter,
|
onClickLang = {
|
||||||
onClickLang = {
|
presenter.toggleLanguage(it)
|
||||||
presenter.toggleLanguage(it)
|
},
|
||||||
},
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
@ -65,7 +62,7 @@ fun ExtensionFilterScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun SourceFilterContent(
|
private fun ExtensionFilterContent(
|
||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
state: ExtensionFilterState,
|
state: ExtensionFilterState,
|
||||||
onClickLang: (String) -> Unit,
|
onClickLang: (String) -> Unit,
|
||||||
@ -76,29 +73,13 @@ private fun SourceFilterContent(
|
|||||||
items(
|
items(
|
||||||
items = state.items,
|
items = state.items,
|
||||||
) { model ->
|
) { model ->
|
||||||
ExtensionFilterItem(
|
val lang = model.lang
|
||||||
|
SwitchPreferenceWidget(
|
||||||
modifier = Modifier.animateItemPlacement(),
|
modifier = Modifier.animateItemPlacement(),
|
||||||
lang = model.lang,
|
title = LocaleHelper.getSourceDisplayName(lang, LocalContext.current),
|
||||||
enabled = model.enabled,
|
checked = model.enabled,
|
||||||
onClickItem = onClickLang,
|
onCheckedChanged = { onClickLang(lang) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ExtensionFilterItem(
|
|
||||||
modifier: Modifier,
|
|
||||||
lang: String,
|
|
||||||
enabled: Boolean,
|
|
||||||
onClickItem: (String) -> Unit,
|
|
||||||
) {
|
|
||||||
PreferenceRow(
|
|
||||||
modifier = modifier,
|
|
||||||
title = LocaleHelper.getSourceDisplayName(lang, LocalContext.current),
|
|
||||||
action = {
|
|
||||||
Switch(checked = enabled, onCheckedChange = null)
|
|
||||||
},
|
|
||||||
onClick = { onClickItem(lang) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
@ -4,13 +4,9 @@ import androidx.compose.foundation.layout.PaddingValues
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Checkbox
|
import androidx.compose.material3.Checkbox
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.painter.ColorPainter
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import eu.kanade.domain.source.model.Source
|
import eu.kanade.domain.source.model.Source
|
||||||
@ -19,8 +15,8 @@ import eu.kanade.presentation.components.AppBar
|
|||||||
import eu.kanade.presentation.components.EmptyScreen
|
import eu.kanade.presentation.components.EmptyScreen
|
||||||
import eu.kanade.presentation.components.FastScrollLazyColumn
|
import eu.kanade.presentation.components.FastScrollLazyColumn
|
||||||
import eu.kanade.presentation.components.LoadingScreen
|
import eu.kanade.presentation.components.LoadingScreen
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
|
||||||
import eu.kanade.presentation.components.Scaffold
|
import eu.kanade.presentation.components.Scaffold
|
||||||
|
import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.FilterUiModel
|
import eu.kanade.tachiyomi.ui.browse.source.FilterUiModel
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.SourcesFilterPresenter
|
import eu.kanade.tachiyomi.ui.browse.source.SourcesFilterPresenter
|
||||||
@ -143,13 +139,11 @@ private fun SourcesFilterHeader(
|
|||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
onClickItem: (String) -> Unit,
|
onClickItem: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
PreferenceRow(
|
SwitchPreferenceWidget(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = LocaleHelper.getSourceDisplayName(language, LocalContext.current),
|
title = LocaleHelper.getSourceDisplayName(language, LocalContext.current),
|
||||||
action = {
|
checked = enabled,
|
||||||
Switch(checked = enabled, onCheckedChange = null)
|
onCheckedChanged = { onClickItem(language) },
|
||||||
},
|
|
||||||
onClick = { onClickItem(language) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,14 +154,11 @@ fun SourcesFilterToggle(
|
|||||||
isEnabled: Boolean,
|
isEnabled: Boolean,
|
||||||
onClickItem: () -> Unit,
|
onClickItem: () -> Unit,
|
||||||
) {
|
) {
|
||||||
PreferenceRow(
|
SwitchPreferenceWidget(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = stringResource(R.string.pref_category_all_sources),
|
title = stringResource(R.string.pref_category_all_sources),
|
||||||
action = {
|
checked = isEnabled,
|
||||||
Switch(checked = isEnabled, onCheckedChange = null)
|
onCheckedChanged = { onClickItem() },
|
||||||
},
|
|
||||||
onClick = { onClickItem() },
|
|
||||||
painter = remember { ColorPainter(Color.Transparent) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package eu.kanade.presentation.browse
|
|||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
@ -21,6 +22,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -31,7 +33,6 @@ import eu.kanade.domain.source.model.Source
|
|||||||
import eu.kanade.presentation.browse.components.BaseSourceItem
|
import eu.kanade.presentation.browse.components.BaseSourceItem
|
||||||
import eu.kanade.presentation.components.EmptyScreen
|
import eu.kanade.presentation.components.EmptyScreen
|
||||||
import eu.kanade.presentation.components.LoadingScreen
|
import eu.kanade.presentation.components.LoadingScreen
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
|
||||||
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
||||||
import eu.kanade.presentation.theme.header
|
import eu.kanade.presentation.theme.header
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
import eu.kanade.presentation.util.horizontalPadding
|
||||||
@ -333,19 +334,28 @@ fun SourceCategoriesDialog(
|
|||||||
text = {
|
text = {
|
||||||
Column {
|
Column {
|
||||||
categories.forEach {
|
categories.forEach {
|
||||||
PreferenceRow(
|
Row(
|
||||||
title = it,
|
modifier = Modifier
|
||||||
onClick = {
|
.fillMaxWidth()
|
||||||
if (it in newCategories) {
|
.clickable {
|
||||||
newCategories -= it
|
if (it in newCategories) {
|
||||||
} else {
|
newCategories -= it
|
||||||
newCategories += it
|
} else {
|
||||||
}
|
newCategories += it
|
||||||
},
|
}
|
||||||
action = {
|
},
|
||||||
Checkbox(checked = it in newCategories, onCheckedChange = null)
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
},
|
) {
|
||||||
)
|
Checkbox(
|
||||||
|
checked = it in newCategories,
|
||||||
|
onCheckedChange = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
modifier = Modifier.padding(horizontal = horizontalPadding),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package eu.kanade.presentation.components
|
||||||
|
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
const val DIVIDER_ALPHA = 0.2f
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Divider(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
androidx.compose.material3.Divider(
|
||||||
|
modifier = modifier,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA),
|
||||||
|
)
|
||||||
|
}
|
@ -1,192 +0,0 @@
|
|||||||
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
|
|
||||||
import androidx.compose.foundation.layout.heightIn
|
|
||||||
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
|
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import eu.kanade.core.prefs.PreferenceMutableState
|
|
||||||
import eu.kanade.presentation.theme.TachiyomiTheme
|
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
|
||||||
|
|
||||||
const val DIVIDER_ALPHA = 0.2f
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Divider(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
|
||||||
androidx.compose.material3.Divider(
|
|
||||||
modifier = modifier,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun PreferenceRow(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
title: String,
|
|
||||||
painter: Painter? = null,
|
|
||||||
onClick: () -> Unit = {},
|
|
||||||
onLongClick: () -> Unit = {},
|
|
||||||
subtitle: String? = null,
|
|
||||||
action: @Composable (() -> Unit)? = null,
|
|
||||||
// SY -->
|
|
||||||
subtitleAnnotated: AnnotatedString? = null,
|
|
||||||
// SY <--
|
|
||||||
) {
|
|
||||||
val height = if (subtitle != null /* SY --> */ || subtitleAnnotated != null/* SY <-- */) 72.dp else 56.dp
|
|
||||||
|
|
||||||
val titleTextStyle = MaterialTheme.typography.bodyLarge
|
|
||||||
val subtitleTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
|
||||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.75f),
|
|
||||||
)
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.heightIn(min = height)
|
|
||||||
.combinedClickable(
|
|
||||||
onLongClick = onLongClick,
|
|
||||||
onClick = onClick,
|
|
||||||
),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
if (painter != null) {
|
|
||||||
Icon(
|
|
||||||
painter = painter,
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = horizontalPadding, end = 16.dp)
|
|
||||||
.size(24.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
|
||||||
contentDescription = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column(
|
|
||||||
Modifier
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.weight(1f),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
style = titleTextStyle,
|
|
||||||
)
|
|
||||||
if (subtitle != null) {
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.padding(top = 4.dp),
|
|
||||||
text = subtitle,
|
|
||||||
style = subtitleTextStyle,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// SY -->
|
|
||||||
if (subtitleAnnotated != null) {
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.padding(top = 4.dp),
|
|
||||||
text = subtitleAnnotated,
|
|
||||||
style = subtitleTextStyle,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// SY <--
|
|
||||||
}
|
|
||||||
if (action != null) {
|
|
||||||
Box(
|
|
||||||
Modifier
|
|
||||||
.widthIn(min = 56.dp)
|
|
||||||
.padding(end = horizontalPadding),
|
|
||||||
) {
|
|
||||||
action()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SwitchPreference(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
checked: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
title: String,
|
|
||||||
subtitle: String? = null,
|
|
||||||
painter: Painter? = null,
|
|
||||||
// SY -->
|
|
||||||
subtitleAnnotated: AnnotatedString? = null,
|
|
||||||
// SY <--
|
|
||||||
) {
|
|
||||||
PreferenceRow(
|
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
subtitle = subtitle,
|
|
||||||
painter = painter,
|
|
||||||
action = { Switch(checked = checked, onCheckedChange = null) },
|
|
||||||
onClick = onClick,
|
|
||||||
// SY -->
|
|
||||||
subtitleAnnotated = subtitleAnnotated,
|
|
||||||
// SY <--
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SwitchPreference(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
preference: PreferenceMutableState<Boolean>,
|
|
||||||
title: String,
|
|
||||||
subtitle: String? = null,
|
|
||||||
painter: Painter? = null,
|
|
||||||
// SY -->
|
|
||||||
subtitleAnnotated: AnnotatedString? = null,
|
|
||||||
// SY <--
|
|
||||||
) {
|
|
||||||
SwitchPreference(
|
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
subtitle = subtitle,
|
|
||||||
painter = painter,
|
|
||||||
checked = preference.value,
|
|
||||||
onClick = { preference.value = !preference.value },
|
|
||||||
// SY -->
|
|
||||||
subtitleAnnotated = subtitleAnnotated,
|
|
||||||
// SY <--
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 = {},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -44,43 +44,42 @@ internal fun BasePreferenceWidget(
|
|||||||
widget: @Composable (() -> Unit)? = null,
|
widget: @Composable (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val highlighted = LocalPreferenceHighlighted.current
|
val highlighted = LocalPreferenceHighlighted.current
|
||||||
Box(modifier = Modifier.highlightBackground(highlighted)) {
|
Row(
|
||||||
Row(
|
modifier = modifier
|
||||||
modifier = modifier
|
.highlightBackground(highlighted)
|
||||||
.sizeIn(minHeight = 56.dp)
|
.sizeIn(minHeight = 56.dp)
|
||||||
.clickable(enabled = onClick != null, onClick = { onClick?.invoke() })
|
.clickable(enabled = onClick != null, onClick = { onClick?.invoke() })
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (icon != null) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(start = PrefsHorizontalPadding, end = 8.dp),
|
||||||
|
content = { icon() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.padding(vertical = PrefsVerticalPadding),
|
||||||
) {
|
) {
|
||||||
if (icon != null) {
|
if (!title.isNullOrBlank()) {
|
||||||
Box(
|
Text(
|
||||||
modifier = Modifier.padding(start = PrefsHorizontalPadding, end = 8.dp),
|
modifier = Modifier.padding(horizontal = PrefsHorizontalPadding),
|
||||||
content = { icon() },
|
text = title,
|
||||||
)
|
overflow = TextOverflow.Ellipsis,
|
||||||
}
|
maxLines = 2,
|
||||||
Column(
|
style = MaterialTheme.typography.titleLarge,
|
||||||
modifier = Modifier
|
fontSize = TitleFontSize,
|
||||||
.weight(1f)
|
|
||||||
.padding(vertical = PrefsVerticalPadding),
|
|
||||||
) {
|
|
||||||
if (!title.isNullOrBlank()) {
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.padding(horizontal = PrefsHorizontalPadding),
|
|
||||||
text = title,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
maxLines = 2,
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontSize = TitleFontSize,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
subcomponent?.invoke(this)
|
|
||||||
}
|
|
||||||
if (widget != null) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.padding(end = PrefsHorizontalPadding),
|
|
||||||
content = { widget() },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
subcomponent?.invoke(this)
|
||||||
|
}
|
||||||
|
if (widget != null) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(end = PrefsHorizontalPadding),
|
||||||
|
content = { widget() },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SwitchPreferenceWidget(
|
fun SwitchPreferenceWidget(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String? = null,
|
subtitle: String? = null,
|
||||||
icon: ImageVector? = null,
|
icon: ImageVector? = null,
|
||||||
@ -21,6 +22,7 @@ fun SwitchPreferenceWidget(
|
|||||||
onCheckedChanged: (Boolean) -> Unit,
|
onCheckedChanged: (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
TextPreferenceWidget(
|
TextPreferenceWidget(
|
||||||
|
modifier = modifier,
|
||||||
title = title,
|
title = title,
|
||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
|
@ -67,7 +67,7 @@ fun TextPreferenceWidget(
|
|||||||
fun TextPreferenceWidget(
|
fun TextPreferenceWidget(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: AnnotatedString,
|
subtitle: AnnotatedString?,
|
||||||
icon: ImageVector? = null,
|
icon: ImageVector? = null,
|
||||||
iconTint: Color = MaterialTheme.colorScheme.primary,
|
iconTint: Color = MaterialTheme.colorScheme.primary,
|
||||||
widget: @Composable (() -> Unit)? = null,
|
widget: @Composable (() -> Unit)? = null,
|
||||||
@ -76,15 +76,19 @@ fun TextPreferenceWidget(
|
|||||||
BasePreferenceWidget(
|
BasePreferenceWidget(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = title,
|
title = title,
|
||||||
subcomponent = {
|
subcomponent = if (!subtitle.isNullOrBlank()) {
|
||||||
Text(
|
{
|
||||||
text = subtitle,
|
Text(
|
||||||
modifier = Modifier
|
text = subtitle,
|
||||||
.padding(horizontal = PrefsHorizontalPadding)
|
modifier = Modifier
|
||||||
.secondaryItemAlpha(),
|
.padding(horizontal = PrefsHorizontalPadding)
|
||||||
style = MaterialTheme.typography.bodySmall,
|
.secondaryItemAlpha(),
|
||||||
maxLines = 10,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
maxLines = 10,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
},
|
},
|
||||||
icon = if (icon != null) {
|
icon = if (icon != null) {
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,6 @@ import kotlinx.coroutines.channels.Channel
|
|||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -36,7 +35,6 @@ class ExtensionFilterPresenter(
|
|||||||
logcat(LogPriority.ERROR, exception)
|
logcat(LogPriority.ERROR, exception)
|
||||||
_events.send(Event.FailedFetchingLanguages)
|
_events.send(Event.FailedFetchingLanguages)
|
||||||
}
|
}
|
||||||
.stateIn(presenterScope)
|
|
||||||
.collectLatest(::collectLatestSourceLangMap)
|
.collectLatest(::collectLatestSourceLangMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import kotlinx.coroutines.channels.Channel
|
|||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -44,7 +43,6 @@ class SourcesFilterPresenter(
|
|||||||
logcat(LogPriority.ERROR, exception)
|
logcat(LogPriority.ERROR, exception)
|
||||||
_events.send(Event.FailedFetchingLanguages)
|
_events.send(Event.FailedFetchingLanguages)
|
||||||
}
|
}
|
||||||
.stateIn(presenterScope)
|
|
||||||
.collectLatest(::collectLatestSourceLangMap)
|
.collectLatest(::collectLatestSourceLangMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import androidx.compose.foundation.verticalScroll
|
|||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@ -46,10 +47,10 @@ import eu.kanade.core.prefs.PreferenceMutableState
|
|||||||
import eu.kanade.presentation.components.AppBar
|
import eu.kanade.presentation.components.AppBar
|
||||||
import eu.kanade.presentation.components.Divider
|
import eu.kanade.presentation.components.Divider
|
||||||
import eu.kanade.presentation.components.LoadingScreen
|
import eu.kanade.presentation.components.LoadingScreen
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
|
||||||
import eu.kanade.presentation.components.Scaffold
|
import eu.kanade.presentation.components.Scaffold
|
||||||
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
||||||
import eu.kanade.presentation.components.SwitchPreference
|
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
|
||||||
|
import eu.kanade.presentation.more.settings.widget.TrailingWidgetBuffer
|
||||||
import eu.kanade.presentation.util.plus
|
import eu.kanade.presentation.util.plus
|
||||||
import eu.kanade.presentation.util.topPaddingValues
|
import eu.kanade.presentation.util.topPaddingValues
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController
|
import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController
|
||||||
@ -126,9 +127,9 @@ class SettingsDebugController : BasicFullComposeController() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
items(functions) { (func, name) ->
|
items(functions) { (func, name) ->
|
||||||
PreferenceRow(
|
TextPreferenceWidget(
|
||||||
title = name,
|
title = name,
|
||||||
onClick = {
|
onPreferenceClick = {
|
||||||
scope.launch(Dispatchers.Default) {
|
scope.launch(Dispatchers.Default) {
|
||||||
val text = try {
|
val text = try {
|
||||||
running = true
|
running = true
|
||||||
@ -155,16 +156,24 @@ class SettingsDebugController : BasicFullComposeController() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
items(toggles) { (name, pref, default) ->
|
items(toggles) { (name, pref, default) ->
|
||||||
SwitchPreference(
|
var state by pref
|
||||||
preference = pref,
|
TextPreferenceWidget(
|
||||||
title = name.replace('_', ' ')
|
title = name.replace('_', ' ')
|
||||||
.lowercase(Locale.getDefault())
|
.lowercase(Locale.getDefault())
|
||||||
.capitalize(Locale.getDefault()),
|
.capitalize(Locale.getDefault()),
|
||||||
subtitleAnnotated = if (pref.value != default) {
|
subtitle = if (pref.value != default) {
|
||||||
AnnotatedString("MODIFIED", SpanStyle(color = Color.Red))
|
AnnotatedString("MODIFIED", SpanStyle(color = Color.Red))
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
},
|
},
|
||||||
|
widget = {
|
||||||
|
Switch(
|
||||||
|
checked = state,
|
||||||
|
onCheckedChange = null,
|
||||||
|
modifier = Modifier.padding(start = TrailingWidgetBuffer),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onPreferenceClick = { state = !state },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user