Improve subtitle handling
This commit is contained in:
parent
bc1dc90963
commit
28ffdd53a0
@ -201,14 +201,6 @@ internal fun PreferenceItem(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is Preference.PreferenceItem.AnnotatedTextPreference -> {
|
|
||||||
TextPreferenceWidget(
|
|
||||||
title = item.title,
|
|
||||||
subtitle = item.annotatedSubtitle,
|
|
||||||
icon = item.icon,
|
|
||||||
onPreferenceClick = item.onClick,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import eu.kanade.domain.ui.model.AppTheme
|
import eu.kanade.domain.ui.model.AppTheme
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.track.TrackService
|
import eu.kanade.tachiyomi.data.track.TrackService
|
||||||
@ -15,7 +14,10 @@ sealed class Preference {
|
|||||||
abstract val enabled: Boolean
|
abstract val enabled: Boolean
|
||||||
|
|
||||||
sealed class PreferenceItem<T> : Preference() {
|
sealed class PreferenceItem<T> : Preference() {
|
||||||
abstract val subtitle: String?
|
// SY -->
|
||||||
|
abstract val subtitle: CharSequence?
|
||||||
|
|
||||||
|
// SY <--
|
||||||
abstract val icon: ImageVector?
|
abstract val icon: ImageVector?
|
||||||
abstract val onValueChanged: suspend (newValue: T) -> Boolean
|
abstract val onValueChanged: suspend (newValue: T) -> Boolean
|
||||||
|
|
||||||
@ -24,7 +26,7 @@ sealed class Preference {
|
|||||||
*/
|
*/
|
||||||
data class TextPreference(
|
data class TextPreference(
|
||||||
override val title: String,
|
override val title: String,
|
||||||
override val subtitle: String? = null,
|
override val subtitle: CharSequence? = null,
|
||||||
override val icon: ImageVector? = null,
|
override val icon: ImageVector? = null,
|
||||||
override val enabled: Boolean = true,
|
override val enabled: Boolean = true,
|
||||||
override val onValueChanged: suspend (newValue: String) -> Boolean = { true },
|
override val onValueChanged: suspend (newValue: String) -> Boolean = { true },
|
||||||
@ -38,7 +40,7 @@ sealed class Preference {
|
|||||||
data class SwitchPreference(
|
data class SwitchPreference(
|
||||||
val pref: PreferenceData<Boolean>,
|
val pref: PreferenceData<Boolean>,
|
||||||
override val title: String,
|
override val title: String,
|
||||||
override val subtitle: String? = null,
|
override val subtitle: CharSequence? = null,
|
||||||
override val icon: ImageVector? = null,
|
override val icon: ImageVector? = null,
|
||||||
override val enabled: Boolean = true,
|
override val enabled: Boolean = true,
|
||||||
override val onValueChanged: suspend (newValue: Boolean) -> Boolean = { true },
|
override val onValueChanged: suspend (newValue: Boolean) -> Boolean = { true },
|
||||||
@ -171,21 +173,6 @@ sealed class Preference {
|
|||||||
override val icon: ImageVector? = null
|
override val icon: ImageVector? = null
|
||||||
override val onValueChanged: suspend (newValue: String) -> Boolean = { true }
|
override val onValueChanged: suspend (newValue: String) -> Boolean = { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A basic [PreferenceItem] that only displays texts.
|
|
||||||
*/
|
|
||||||
data class AnnotatedTextPreference(
|
|
||||||
override val title: String,
|
|
||||||
val annotatedSubtitle: AnnotatedString,
|
|
||||||
override val icon: ImageVector? = null,
|
|
||||||
override val enabled: Boolean = true,
|
|
||||||
override val onValueChanged: suspend (newValue: String) -> Boolean = { true },
|
|
||||||
|
|
||||||
val onClick: (() -> Unit)? = null,
|
|
||||||
) : PreferenceItem<String>() {
|
|
||||||
override val subtitle: String = annotatedSubtitle.text
|
|
||||||
}
|
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,9 +723,9 @@ object SettingsAdvancedScreen : SearchableSettings {
|
|||||||
stringResource(R.string.app_name),
|
stringResource(R.string.app_name),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Preference.PreferenceItem.AnnotatedTextPreference(
|
Preference.PreferenceItem.TextPreference(
|
||||||
title = stringResource(R.string.open_debug_menu),
|
title = stringResource(R.string.open_debug_menu),
|
||||||
annotatedSubtitle = remember {
|
subtitle = remember {
|
||||||
HtmlCompat.fromHtml(context.getString(R.string.open_debug_menu_summary), HtmlCompat.FROM_HTML_MODE_COMPACT)
|
HtmlCompat.fromHtml(context.getString(R.string.open_debug_menu_summary), HtmlCompat.FROM_HTML_MODE_COMPACT)
|
||||||
.toAnnotatedString()
|
.toAnnotatedString()
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ import tachiyomi.presentation.core.util.ThemePreviews
|
|||||||
fun SwitchPreferenceWidget(
|
fun SwitchPreferenceWidget(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String? = null,
|
subtitle: CharSequence? = null,
|
||||||
icon: ImageVector? = null,
|
icon: ImageVector? = null,
|
||||||
checked: Boolean = false,
|
checked: Boolean = false,
|
||||||
onCheckedChanged: (Boolean) -> Unit,
|
onCheckedChanged: (Boolean) -> Unit,
|
||||||
|
@ -16,7 +16,6 @@ import androidx.compose.ui.text.AnnotatedString
|
|||||||
import androidx.compose.ui.text.SpanStyle
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.withStyle
|
import androidx.compose.ui.text.withStyle
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import eu.kanade.presentation.theme.TachiyomiTheme
|
import eu.kanade.presentation.theme.TachiyomiTheme
|
||||||
import tachiyomi.presentation.core.util.ThemePreviews
|
import tachiyomi.presentation.core.util.ThemePreviews
|
||||||
import tachiyomi.presentation.core.util.secondaryItemAlpha
|
import tachiyomi.presentation.core.util.secondaryItemAlpha
|
||||||
@ -25,7 +24,7 @@ import tachiyomi.presentation.core.util.secondaryItemAlpha
|
|||||||
fun TextPreferenceWidget(
|
fun TextPreferenceWidget(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: String? = null,
|
subtitle: CharSequence? = null,
|
||||||
icon: ImageVector? = null,
|
icon: ImageVector? = null,
|
||||||
iconTint: Color = MaterialTheme.colorScheme.primary,
|
iconTint: Color = MaterialTheme.colorScheme.primary,
|
||||||
widget: @Composable (() -> Unit)? = null,
|
widget: @Composable (() -> Unit)? = null,
|
||||||
@ -36,50 +35,8 @@ fun TextPreferenceWidget(
|
|||||||
title = title,
|
title = title,
|
||||||
subcomponent = if (!subtitle.isNullOrBlank()) {
|
subcomponent = if (!subtitle.isNullOrBlank()) {
|
||||||
{
|
{
|
||||||
Text(
|
|
||||||
text = subtitle,
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = PrefsHorizontalPadding)
|
|
||||||
.secondaryItemAlpha(),
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
maxLines = 10,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
},
|
|
||||||
icon = if (icon != null) {
|
|
||||||
{
|
|
||||||
Icon(
|
|
||||||
imageVector = icon,
|
|
||||||
tint = iconTint,
|
|
||||||
contentDescription = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
},
|
|
||||||
onClick = onPreferenceClick,
|
|
||||||
widget = widget,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
@Composable
|
if (subtitle is AnnotatedString) {
|
||||||
fun TextPreferenceWidget(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
title: String? = null,
|
|
||||||
subtitle: AnnotatedString?,
|
|
||||||
icon: ImageVector? = null,
|
|
||||||
iconTint: Color = MaterialTheme.colorScheme.primary,
|
|
||||||
widget: @Composable (() -> Unit)? = null,
|
|
||||||
onPreferenceClick: (() -> Unit)? = null,
|
|
||||||
) {
|
|
||||||
BasePreferenceWidget(
|
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
subcomponent = if (!subtitle.isNullOrBlank()) {
|
|
||||||
{
|
|
||||||
Text(
|
Text(
|
||||||
text = subtitle,
|
text = subtitle,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -88,6 +45,17 @@ fun TextPreferenceWidget(
|
|||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
maxLines = 10,
|
maxLines = 10,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
// SY <--
|
||||||
|
Text(
|
||||||
|
text = subtitle.toString(),
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(horizontal = PrefsHorizontalPadding)
|
||||||
|
.secondaryItemAlpha(),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
maxLines = 10,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@ -107,7 +75,6 @@ fun TextPreferenceWidget(
|
|||||||
widget = widget,
|
widget = widget,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// SY <--
|
|
||||||
|
|
||||||
@ThemePreviews
|
@ThemePreviews
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user