Minor cleanup

This commit is contained in:
arkon 2022-05-19 17:43:27 -04:00
parent 64da16f58f
commit 9a75232ca4
12 changed files with 75 additions and 71 deletions

View File

@ -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

View File

@ -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,

View File

@ -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) },
)

View File

@ -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<Extension.Untrusted?>(null) }
var trustState by remember { mutableStateOf<Extension.Untrusted?>(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,

View File

@ -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),

View File

@ -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)
},
)
}

View File

@ -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<Source?>(null) }
var sourceState by remember { mutableStateOf<Source?>(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()

View File

@ -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),
)
}

View File

@ -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<HistoryWithRelations?>(null) }
var removeState by remember { mutableStateOf<HistoryWithRelations?>(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))
}
},
)

View File

@ -24,4 +24,4 @@ class ExtensionFilterController : ComposeController<ExtensionFilterPresenter>()
}
}
data class FilterUiModel(val lang: String, val isEnabled: Boolean)
data class FilterUiModel(val lang: String, val enabled: Boolean)

View File

@ -29,6 +29,6 @@ class SourceFilterController : ComposeController<SourcesFilterPresenter>() {
}
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()
}

View File

@ -273,8 +273,7 @@
<string name="ext_info_language">Language</string>
<string name="ext_info_age_rating">Age rating</string>
<string name="ext_nsfw_short">18+</string>
<string name="ext_nsfw_warning">May contain NSFW (18+) content</string>
<string name="ext_nsfw_warning_dismiss">Got it</string>
<string name="ext_nsfw_warning">Sources from this extension may contain NSFW (18+) content</string>
<string name="ext_install_service_notif">Installing extension…</string>
<string name="ext_installer_pref">Installer</string>
<string name="ext_installer_legacy">Legacy</string>