Minor cleanup

This commit is contained in:
Jobobby04 2023-12-25 20:17:14 -05:00
parent 526ee7dda9
commit 22d8711cee
3 changed files with 16 additions and 13 deletions

View File

@ -225,7 +225,7 @@ object SettingsSecurityScreen : SearchableSettings {
onDaysSelected: (Int) -> Unit, onDaysSelected: (Int) -> Unit,
) { ) {
val selected = remember(initialSelection) { val selected = remember(initialSelection) {
DayOption.values().filter { it.day and initialSelection == it.day } DayOption.entries.filter { it.day and initialSelection == it.day }
.toMutableStateList() .toMutableStateList()
} }
AlertDialog( AlertDialog(
@ -233,7 +233,7 @@ object SettingsSecurityScreen : SearchableSettings {
title = { Text(text = stringResource(SYMR.strings.biometric_lock_days)) }, title = { Text(text = stringResource(SYMR.strings.biometric_lock_days)) },
text = { text = {
LazyColumn { LazyColumn {
DayOption.values().forEach { day -> DayOption.entries.forEach { day ->
item { item {
val isSelected = selected.contains(day) val isSelected = selected.contains(day)
val onSelectionChanged = { val onSelectionChanged = {

View File

@ -862,7 +862,7 @@ class LibraryScreenModel(
} else { } else {
categoryName categoryName
} }
LibraryGroup.BY_TRACK_STATUS -> TrackStatus.values() LibraryGroup.BY_TRACK_STATUS -> TrackStatus.entries
.find { it.int.toLong() == category?.id } .find { it.int.toLong() == category?.id }
.let { it ?: TrackStatus.OTHER } .let { it ?: TrackStatus.OTHER }
.let { context.stringResource(it.res) } .let { context.stringResource(it.res) }
@ -1171,11 +1171,11 @@ class LibraryScreenModel(
}.mapKeys { (id) -> }.mapKeys { (id) ->
Category( Category(
id = id.toLong(), id = id.toLong(),
name = TrackStatus.values() name = TrackStatus.entries
.find { it.int == id } .find { it.int == id }
.let { it ?: TrackStatus.OTHER } .let { it ?: TrackStatus.OTHER }
.let { context.stringResource(it.res) }, .let { context.stringResource(it.res) },
order = TrackStatus.values().indexOfFirst { order = TrackStatus.entries.indexOfFirst {
it.int == id it.int == id
}.takeUnless { it == -1 }?.toLong() ?: TrackStatus.OTHER.ordinal.toLong(), }.takeUnless { it == -1 }?.toLong() ?: TrackStatus.OTHER.ordinal.toLong(),
flags = 0, flags = 0,

View File

@ -52,6 +52,9 @@ import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
import eu.kanade.presentation.more.settings.widget.TrailingWidgetBuffer import eu.kanade.presentation.more.settings.widget.TrailingWidgetBuffer
import eu.kanade.presentation.util.Screen import eu.kanade.presentation.util.Screen
import exh.util.capitalize import exh.util.capitalize
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -77,7 +80,7 @@ class SettingsDebugScreen : Screen() {
DisposableEffect(Unit) { DisposableEffect(Unit) {
onDispose { navigator.pop() } onDispose { navigator.pop() }
} }
val functions by produceState<List<Pair<KFunction<*>, String>>?>(initialValue = null) { val functions by produceState<ImmutableList<Pair<KFunction<*>, String>>?>(initialValue = null) {
value = withContext(Dispatchers.Default) { value = withContext(Dispatchers.Default) {
DebugFunctions::class.declaredFunctions.filter { DebugFunctions::class.declaredFunctions.filter {
it.visibility == KVisibility.PUBLIC it.visibility == KVisibility.PUBLIC
@ -85,12 +88,12 @@ class SettingsDebugScreen : Screen() {
it to it.name.replace("(.)(\\p{Upper})".toRegex(), "$1 $2") it to it.name.replace("(.)(\\p{Upper})".toRegex(), "$1 $2")
.lowercase(Locale.getDefault()) .lowercase(Locale.getDefault())
.capitalize(Locale.getDefault()) .capitalize(Locale.getDefault())
} }.toImmutableList()
} }
} }
val toggles by produceState(initialValue = emptyList()) { val toggles by produceState(initialValue = persistentListOf()) {
value = withContext(Dispatchers.Default) { value = withContext(Dispatchers.Default) {
DebugToggles.values().map { DebugToggle(it.name, it.asPref(scope), it.default) } DebugToggles.entries.map { DebugToggle(it.name, it.asPref(scope), it.default) }.toImmutableList()
} }
} }
Scaffold( Scaffold(
@ -101,10 +104,10 @@ class SettingsDebugScreen : Screen() {
) )
}, },
) { paddingValues -> ) { paddingValues ->
Crossfade(functions == null) { Crossfade(functions == null, label = "debug_functions") {
when (it) { when (it) {
true -> LoadingScreen() true -> LoadingScreen()
false -> FunctionList(paddingValues, functions.orEmpty(), toggles, scope) false -> FunctionList(paddingValues, functions ?: persistentListOf(), toggles, scope)
} }
} }
} }
@ -113,8 +116,8 @@ class SettingsDebugScreen : Screen() {
@Composable @Composable
fun FunctionList( fun FunctionList(
paddingValues: PaddingValues, paddingValues: PaddingValues,
functions: List<Pair<KFunction<*>, String>>, functions: ImmutableList<Pair<KFunction<*>, String>>,
toggles: List<DebugToggle>, toggles: ImmutableList<DebugToggle>,
scope: CoroutineScope, scope: CoroutineScope,
) { ) {
Box(Modifier.fillMaxSize()) { Box(Modifier.fillMaxSize()) {