Re-add debug menu button styling
This commit is contained in:
parent
856e18d7a2
commit
2961202d05
@ -203,6 +203,14 @@ internal fun PreferenceItem(
|
||||
},
|
||||
)
|
||||
}
|
||||
is Preference.PreferenceItem.AnnotatedTextPreference -> {
|
||||
TextPreferenceWidget(
|
||||
title = item.title,
|
||||
subtitle = item.annotatedSubtitle,
|
||||
icon = item.icon,
|
||||
onPreferenceClick = item.onClick,
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.presentation.more.settings
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import eu.kanade.domain.ui.model.AppTheme
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.core.preference.Preference as PreferenceData
|
||||
@ -150,6 +151,21 @@ sealed class Preference {
|
||||
override val icon: ImageVector? = null
|
||||
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 <--
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.text.HtmlCompat
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import eu.kanade.domain.UnsortedPreferences
|
||||
@ -88,6 +89,7 @@ import exh.pref.DelegateSourcePreferences
|
||||
import exh.source.BlacklistedSources
|
||||
import exh.source.EH_SOURCE_ID
|
||||
import exh.source.EXH_SOURCE_ID
|
||||
import exh.util.toAnnotatedString
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import logcat.LogPriority
|
||||
@ -729,9 +731,12 @@ class SettingsAdvancedScreen : SearchableSettings {
|
||||
stringResource(R.string.app_name),
|
||||
),
|
||||
),
|
||||
Preference.PreferenceItem.TextPreference(
|
||||
Preference.PreferenceItem.AnnotatedTextPreference(
|
||||
title = stringResource(R.string.open_debug_menu),
|
||||
subtitle = stringResource(R.string.open_debug_menu_summary), // todo make red
|
||||
annotatedSubtitle = remember {
|
||||
HtmlCompat.fromHtml(context.getString(R.string.open_debug_menu_summary), HtmlCompat.FROM_HTML_MODE_COMPACT)
|
||||
.toAnnotatedString()
|
||||
},
|
||||
onClick = { router.pushController(SettingsDebugController()) },
|
||||
),
|
||||
),
|
||||
|
@ -12,6 +12,10 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import eu.kanade.presentation.util.secondaryItemAlpha
|
||||
|
||||
@ -58,6 +62,47 @@ fun TextPreferenceWidget(
|
||||
)
|
||||
}
|
||||
|
||||
// SY -->
|
||||
@Composable
|
||||
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 = {
|
||||
Text(
|
||||
text = subtitle,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = HorizontalPadding)
|
||||
.secondaryItemAlpha(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = 10,
|
||||
)
|
||||
},
|
||||
icon = if (icon != null) {
|
||||
{
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
tint = iconTint,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
onClick = onPreferenceClick,
|
||||
widget = widget,
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun TextPreferenceWidgetPreview() {
|
||||
@ -75,6 +120,19 @@ private fun TextPreferenceWidgetPreview() {
|
||||
subtitle = "Text preference summary",
|
||||
onPreferenceClick = {},
|
||||
)
|
||||
// SY -->
|
||||
TextPreferenceWidget(
|
||||
title = "Text preference",
|
||||
subtitle = buildAnnotatedString {
|
||||
append("Text preference ")
|
||||
|
||||
withStyle(SpanStyle(Color.Red)) {
|
||||
append("summary")
|
||||
}
|
||||
},
|
||||
onPreferenceClick = {},
|
||||
)
|
||||
// SY <--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
app/src/main/java/exh/util/AnnotatedString.kt
Normal file
37
app/src/main/java/exh/util/AnnotatedString.kt
Normal file
@ -0,0 +1,37 @@
|
||||
package exh.util
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.text.Spanned
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.text.style.UnderlineSpan
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
|
||||
/**
|
||||
* Converts a [Spanned] into an [AnnotatedString] trying to keep as much formatting as possible.
|
||||
*
|
||||
* Currently supports `bold`, `italic`, `underline` and `color`.
|
||||
*/
|
||||
fun Spanned.toAnnotatedString(): AnnotatedString = buildAnnotatedString {
|
||||
val spanned = this@toAnnotatedString
|
||||
append(spanned.toString())
|
||||
getSpans(0, spanned.length, Any::class.java).forEach { span ->
|
||||
val start = getSpanStart(span)
|
||||
val end = getSpanEnd(span)
|
||||
when (span) {
|
||||
is StyleSpan -> when (span.style) {
|
||||
Typeface.BOLD -> addStyle(SpanStyle(fontWeight = FontWeight.Bold), start, end)
|
||||
Typeface.ITALIC -> addStyle(SpanStyle(fontStyle = FontStyle.Italic), start, end)
|
||||
Typeface.BOLD_ITALIC -> addStyle(SpanStyle(fontWeight = FontWeight.Bold, fontStyle = FontStyle.Italic), start, end)
|
||||
}
|
||||
is UnderlineSpan -> addStyle(SpanStyle(textDecoration = TextDecoration.Underline), start, end)
|
||||
is ForegroundColorSpan -> addStyle(SpanStyle(color = Color(span.foregroundColor)), start, end)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user