From 9a75232ca40e8f6f3dd6a6f73cc0c2f3912e3ced Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 19 May 2022 17:43:27 -0400 Subject: [PATCH] Minor cleanup --- .../source/interactor/ToggleLanguage.kt | 4 +-- .../browse/ExtensionDetailsScreen.kt | 26 +++++++++-------- .../browse/ExtensionLangFilterScreen.kt | 10 +++---- .../presentation/browse/ExtensionsScreen.kt | 28 ++++++++++--------- .../browse/MigrateSourceScreen.kt | 2 +- .../browse/SourcesFilterScreen.kt | 12 ++++---- .../presentation/browse/SourcesScreen.kt | 24 ++++++++-------- .../presentation/components/Preferences.kt | 4 ++- .../presentation/history/HistoryScreen.kt | 27 +++++++++--------- .../extension/ExtensionFilterController.kt | 2 +- .../browse/source/SourcesFilterController.kt | 4 +-- app/src/main/res/values/strings.xml | 3 +- 12 files changed, 75 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt index c05559837..508bc7335 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleLanguage.kt @@ -9,8 +9,8 @@ class ToggleLanguage( ) { fun await(language: String) { - val isEnabled = language in preferences.enabledLanguages().get() - if (isEnabled) { + val enabled = language in preferences.enabledLanguages().get() + if (enabled) { preferences.enabledLanguages() -= language } else { preferences.enabledLanguages() += language diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt index ad9a35f37..c3e83b6c1 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt @@ -37,6 +37,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.NestedScrollConnection @@ -47,6 +48,7 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import eu.kanade.presentation.browse.components.ExtensionIcon +import eu.kanade.presentation.components.DIVIDER_ALPHA import eu.kanade.presentation.components.Divider import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.PreferenceRow @@ -76,7 +78,7 @@ fun ExtensionDetailsScreen( val sources by presenter.sourcesState.collectAsState() - val (showNsfwWarning, setShowNsfwWarning) = remember { mutableStateOf(false) } + var showNsfwWarning by remember { mutableStateOf(false) } LazyColumn( modifier = Modifier.nestedScroll(nestedScrollInterop), @@ -99,7 +101,7 @@ fun ExtensionDetailsScreen( onClickUninstall = onClickUninstall, onClickAppInfo = onClickAppInfo, onClickAgeRating = { - setShowNsfwWarning(true) + showNsfwWarning = true }, ) } @@ -119,7 +121,7 @@ fun ExtensionDetailsScreen( if (showNsfwWarning) { NsfwWarningDialog( onClickConfirm = { - setShowNsfwWarning(false) + showNsfwWarning = false }, ) } @@ -214,7 +216,7 @@ private fun DetailsHeader( fontWeight = FontWeight.Medium, ), secondaryText = stringResource(R.string.ext_info_age_rating), - onCLick = onClickAgeRating, + onClick = onClickAgeRating, ) } } @@ -256,12 +258,12 @@ private fun InfoText( primaryText: String, primaryTextStyle: TextStyle = MaterialTheme.typography.bodyLarge, secondaryText: String, - onCLick: (() -> Unit)? = null, + onClick: (() -> Unit)? = null, ) { val interactionSource = remember { MutableInteractionSource() } - val modifier = if (onCLick != null) { - Modifier.clickable(interactionSource, indication = null) { onCLick() } + val modifier = if (onClick != null) { + Modifier.clickable(interactionSource, indication = null) { onClick() } } else Modifier Column( @@ -275,9 +277,9 @@ private fun InfoText( ) Text( - text = secondaryText + if (onCLick != null) " ⓘ" else "", + text = secondaryText + if (onClick != null) " ⓘ" else "", style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5F), + color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f), ) } } @@ -288,7 +290,7 @@ private fun InfoDivider() { modifier = Modifier .height(20.dp) .width(1.dp), - color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5F), + color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA), ) } @@ -335,11 +337,11 @@ fun NsfwWarningDialog( ) { AlertDialog( text = { - Text(text = stringResource(id = R.string.ext_nsfw_warning)) + Text(text = stringResource(R.string.ext_nsfw_warning)) }, confirmButton = { TextButton(onClick = onClickConfirm) { - Text(text = stringResource(id = R.string.ext_nsfw_warning_dismiss)) + Text(text = stringResource(android.R.string.ok)) } }, onDismissRequest = onClickConfirm, diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionLangFilterScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionLangFilterScreen.kt index 9fd777dce..c24484b67 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionLangFilterScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionLangFilterScreen.kt @@ -1,7 +1,5 @@ package eu.kanade.presentation.browse -import androidx.compose.animation.core.LinearOutSlowInEasing -import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.navigationBars @@ -64,9 +62,9 @@ fun SourceFilterContent( items = items, ) { model -> ExtensionFilterItem( - modifier = Modifier.animateItemPlacement(tween(1000, easing = LinearOutSlowInEasing)), + modifier = Modifier.animateItemPlacement(), lang = model.lang, - isEnabled = model.isEnabled, + enabled = model.enabled, onClickItem = onClickLang, ) } @@ -77,14 +75,14 @@ fun SourceFilterContent( fun ExtensionFilterItem( modifier: Modifier, lang: String, - isEnabled: Boolean, + enabled: Boolean, onClickItem: (String) -> Unit, ) { PreferenceRow( modifier = modifier, title = LocaleHelper.getSourceDisplayName(lang, LocalContext.current), action = { - Switch(checked = isEnabled, onCheckedChange = null) + Switch(checked = enabled, onCheckedChange = null) }, onClick = { onClickItem(lang) }, ) diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt index 02d7f5595..6aaef39e4 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt @@ -28,6 +28,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.NestedScrollConnection @@ -110,7 +111,8 @@ fun ExtensionContent( onClickUpdateAll: () -> Unit, onLaunched: () -> Unit, ) { - val (trustState, setTrustState) = remember { mutableStateOf(null) } + var trustState by remember { mutableStateOf(null) } + LazyColumn( contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues, ) { @@ -137,7 +139,7 @@ fun ExtensionContent( { Button(onClick = { onClickUpdateAll() }) { Text( - text = stringResource(id = R.string.ext_update_all), + text = stringResource(R.string.ext_update_all), style = LocalTextStyle.current.copy( color = MaterialTheme.colorScheme.onPrimary, ), @@ -173,7 +175,7 @@ fun ExtensionContent( onOpenExtension(it) } } - is Extension.Untrusted -> setTrustState(it) + is Extension.Untrusted -> { trustState = it } } }, onLongClickItem = onLongClickItem, @@ -188,7 +190,7 @@ fun ExtensionContent( onOpenExtension(it) } } - is Extension.Untrusted -> setTrustState(it) + is Extension.Untrusted -> { trustState = it } } }, ) @@ -202,15 +204,15 @@ fun ExtensionContent( if (trustState != null) { ExtensionTrustDialog( onClickConfirm = { - onTrustExtension(trustState) - setTrustState(null) + onTrustExtension(trustState!!) + trustState = null }, onClickDismiss = { - onUninstallExtension(trustState) - setTrustState(null) + onUninstallExtension(trustState!!) + trustState = null }, onDismissRequest = { - setTrustState(null) + trustState = null }, ) } @@ -403,19 +405,19 @@ fun ExtensionTrustDialog( ) { AlertDialog( title = { - Text(text = stringResource(id = R.string.untrusted_extension)) + Text(text = stringResource(R.string.untrusted_extension)) }, text = { - Text(text = stringResource(id = R.string.untrusted_extension_message)) + Text(text = stringResource(R.string.untrusted_extension_message)) }, confirmButton = { TextButton(onClick = onClickConfirm) { - Text(text = stringResource(id = R.string.ext_trust)) + Text(text = stringResource(R.string.ext_trust)) } }, dismissButton = { TextButton(onClick = onClickDismiss) { - Text(text = stringResource(id = R.string.ext_uninstall)) + Text(text = stringResource(R.string.ext_uninstall)) } }, onDismissRequest = onDismissRequest, diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt index b2dad5c44..58c07e2cf 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt @@ -68,7 +68,7 @@ fun MigrateSourceList( ) { item(key = "title") { Text( - text = stringResource(id = R.string.migration_selection_prompt), + text = stringResource(R.string.migration_selection_prompt), modifier = Modifier .animateItemPlacement() .padding(horizontal = horizontalPadding, vertical = 8.dp), diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt index 3f29287a1..2fcf3c7c1 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt @@ -84,14 +84,14 @@ fun SourcesFilterContent( SourcesFilterHeader( modifier = Modifier.animateItemPlacement(), language = model.language, - isEnabled = model.isEnabled, + enabled = model.enabled, onClickItem = onClickLang, ) } is FilterUiModel.Item -> SourcesFilterItem( modifier = Modifier.animateItemPlacement(), source = model.source, - isEnabled = model.isEnabled, + enabled = model.enabled, onClickItem = onClickSource, ) } @@ -103,14 +103,14 @@ fun SourcesFilterContent( fun SourcesFilterHeader( modifier: Modifier, language: String, - isEnabled: Boolean, + enabled: Boolean, onClickItem: (String) -> Unit, ) { PreferenceRow( modifier = modifier, title = LocaleHelper.getSourceDisplayName(language, LocalContext.current), action = { - Switch(checked = isEnabled, onCheckedChange = null) + Switch(checked = enabled, onCheckedChange = null) }, onClick = { onClickItem(language) }, ) @@ -120,7 +120,7 @@ fun SourcesFilterHeader( fun SourcesFilterItem( modifier: Modifier, source: Source, - isEnabled: Boolean, + enabled: Boolean, onClickItem: (Source) -> Unit, ) { BaseSourceItem( @@ -129,7 +129,7 @@ fun SourcesFilterItem( showLanguageInContent = false, onClickItem = { onClickItem(source) }, action = { - Checkbox(checked = isEnabled, onCheckedChange = null) + Checkbox(checked = enabled, onCheckedChange = null) }, ) } diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt index b581a772e..2e8d703e9 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt @@ -24,6 +24,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.nestedScroll @@ -84,7 +85,8 @@ fun SourceList( return } - val (sourceState, setSourceState) = remember { mutableStateOf(null) } + var sourceState by remember { mutableStateOf(null) } + LazyColumn( modifier = Modifier.nestedScroll(nestedScrollConnection), contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues, @@ -115,9 +117,7 @@ fun SourceList( modifier = Modifier.animateItemPlacement(), source = model.source, onClickItem = onClickItem, - onLongClickItem = { - setSourceState(it) - }, + onLongClickItem = { sourceState = it }, onClickLatest = onClickLatest, onClickPin = onClickPin, ) @@ -127,16 +127,16 @@ fun SourceList( if (sourceState != null) { SourceOptionsDialog( - source = sourceState, + source = sourceState!!, onClickPin = { - onClickPin(sourceState) - setSourceState(null) + onClickPin(sourceState!!) + sourceState = null }, onClickDisable = { - onClickDisable(sourceState) - setSourceState(null) + onClickDisable(sourceState!!) + sourceState = null }, - onDismiss = { setSourceState(null) }, + onDismiss = { sourceState = null }, ) } } @@ -173,7 +173,7 @@ fun SourceItem( if (source.supportsLatest) { TextButton(onClick = { onClickLatest(source) }) { Text( - text = stringResource(id = R.string.latest), + text = stringResource(R.string.latest), style = LocalTextStyle.current.copy( color = MaterialTheme.colorScheme.primary, ), @@ -227,7 +227,7 @@ fun SourceOptionsDialog( ) if (source.id != LocalSource.ID) { Text( - text = stringResource(id = R.string.action_disable), + text = stringResource(R.string.action_disable), modifier = Modifier .clickable(onClick = onClickDisable) .fillMaxWidth() diff --git a/app/src/main/java/eu/kanade/presentation/components/Preferences.kt b/app/src/main/java/eu/kanade/presentation/components/Preferences.kt index d50796d2c..774b5f6c8 100644 --- a/app/src/main/java/eu/kanade/presentation/components/Preferences.kt +++ b/app/src/main/java/eu/kanade/presentation/components/Preferences.kt @@ -21,13 +21,15 @@ import androidx.compose.ui.unit.dp import eu.kanade.core.prefs.PreferenceMutableState 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 = 0.2f), + color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA), ) } diff --git a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt index 9726e0329..719974120 100644 --- a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt @@ -27,6 +27,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.NestedScrollConnection @@ -103,7 +104,7 @@ fun HistoryContent( val relativeTime: Int = remember { preferences.relativeTime().get() } val dateFormat: DateFormat = remember { preferences.dateFormat() } - val (removeState, setRemoveState) = remember { mutableStateOf(null) } + var removeState by remember { mutableStateOf(null) } val scrollState = rememberLazyListState() LazyColumn( @@ -130,7 +131,7 @@ fun HistoryContent( history = value, onClickCover = { onClickCover(value) }, onClickResume = { onClickResume(value) }, - onClickDelete = { setRemoveState(value) }, + onClickDelete = { removeState = value }, ) } null -> {} @@ -141,10 +142,10 @@ fun HistoryContent( if (removeState != null) { RemoveHistoryDialog( onPositive = { all -> - onClickDelete(removeState, all) - setRemoveState(null) + onClickDelete(removeState!!, all) + removeState = null }, - onNegative = { setRemoveState(null) }, + onNegative = { removeState = null }, ) } } @@ -224,7 +225,7 @@ fun HistoryItem( IconButton(onClick = onClickDelete) { Icon( imageVector = Icons.Outlined.Delete, - contentDescription = stringResource(id = R.string.action_delete), + contentDescription = stringResource(R.string.action_delete), tint = MaterialTheme.colorScheme.onSurface, ) } @@ -236,15 +237,15 @@ fun RemoveHistoryDialog( onPositive: (Boolean) -> Unit, onNegative: () -> Unit, ) { - val (removeEverything, removeEverythingState) = remember { mutableStateOf(false) } + var removeEverything by remember { mutableStateOf(false) } AlertDialog( title = { - Text(text = stringResource(id = R.string.action_remove)) + Text(text = stringResource(R.string.action_remove)) }, text = { Column { - Text(text = stringResource(id = R.string.dialog_with_checkbox_remove_description)) + Text(text = stringResource(R.string.dialog_with_checkbox_remove_description)) Row( modifier = Modifier .padding(top = 16.dp) @@ -252,7 +253,7 @@ fun RemoveHistoryDialog( interactionSource = remember { MutableInteractionSource() }, indication = null, value = removeEverything, - onValueChange = removeEverythingState, + onValueChange = { removeEverything = it }, ), verticalAlignment = Alignment.CenterVertically, ) { @@ -262,7 +263,7 @@ fun RemoveHistoryDialog( ) Text( modifier = Modifier.padding(start = 4.dp), - text = stringResource(id = R.string.dialog_with_checkbox_reset), + text = stringResource(R.string.dialog_with_checkbox_reset), ) } } @@ -270,12 +271,12 @@ fun RemoveHistoryDialog( onDismissRequest = onNegative, confirmButton = { TextButton(onClick = { onPositive(removeEverything) }) { - Text(text = stringResource(id = R.string.action_remove)) + Text(text = stringResource(R.string.action_remove)) } }, dismissButton = { TextButton(onClick = onNegative) { - Text(text = stringResource(id = R.string.action_cancel)) + Text(text = stringResource(R.string.action_cancel)) } }, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt index 59b3d5250..2254da3ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt @@ -24,4 +24,4 @@ class ExtensionFilterController : ComposeController() } } -data class FilterUiModel(val lang: String, val isEnabled: Boolean) +data class FilterUiModel(val lang: String, val enabled: Boolean) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterController.kt index 327bf1adb..c46880af5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterController.kt @@ -29,6 +29,6 @@ class SourceFilterController : ComposeController() { } sealed class FilterUiModel { - data class Header(val language: String, val isEnabled: Boolean) : FilterUiModel() - data class Item(val source: Source, val isEnabled: Boolean) : FilterUiModel() + data class Header(val language: String, val enabled: Boolean) : FilterUiModel() + data class Item(val source: Source, val enabled: Boolean) : FilterUiModel() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58ff4e1e6..236830076 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -273,8 +273,7 @@ Language Age rating 18+ - May contain NSFW (18+) content - Got it + Sources from this extension may contain NSFW (18+) content Installing extension… Installer Legacy