mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Improve source lang handling
This commit is contained in:
@@ -19,7 +19,15 @@ data class Source(
|
|||||||
val isNsfw: Boolean,
|
val isNsfw: Boolean,
|
||||||
val displayName: String
|
val displayName: String
|
||||||
) {
|
) {
|
||||||
|
val displayLang: String
|
||||||
|
get() = if (id == LOCAL_SOURCE_ID) {
|
||||||
|
"other"
|
||||||
|
} else {
|
||||||
|
lang
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val LOCAL_SOURCE_LANG = "localsourcelang"
|
const val LOCAL_SOURCE_LANG = "localsourcelang"
|
||||||
|
const val LOCAL_SOURCE_ID = 0L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ca.gosyer.ui.base.components
|
||||||
|
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
fun localeToString(locale: String) = Locale.forLanguageTag(locale)
|
||||||
|
?.getDisplayLanguage(Locale.getDefault())
|
||||||
|
?.ifBlank { null }
|
||||||
|
?: locale.uppercase()
|
||||||
@@ -38,7 +38,7 @@ class SourceHomeScreenViewModel @Inject constructor(
|
|||||||
|
|
||||||
val sources = combine(installedSources, languages) { installedSources, languages ->
|
val sources = combine(installedSources, languages) { installedSources, languages ->
|
||||||
installedSources.filter {
|
installedSources.filter {
|
||||||
it.lang in languages || it.lang == Source.LOCAL_SOURCE_LANG
|
it.lang in languages || it.id == Source.LOCAL_SOURCE_ID
|
||||||
}
|
}
|
||||||
}.stateIn(scope, SharingStarted.Eagerly, emptyList())
|
}.stateIn(scope, SharingStarted.Eagerly, emptyList())
|
||||||
|
|
||||||
@@ -53,7 +53,12 @@ class SourceHomeScreenViewModel @Inject constructor(
|
|||||||
private fun getSources() {
|
private fun getSources() {
|
||||||
sourceHandler.getSourceList()
|
sourceHandler.getSourceList()
|
||||||
.onEach {
|
.onEach {
|
||||||
installedSources.value = it
|
installedSources.value = it.sortedWith(
|
||||||
|
compareBy<Source, String>(String.CASE_INSENSITIVE_ORDER) { it.displayLang }
|
||||||
|
.thenBy(String.CASE_INSENSITIVE_ORDER) {
|
||||||
|
it.name
|
||||||
|
}
|
||||||
|
)
|
||||||
_isLoading.value = false
|
_isLoading.value = false
|
||||||
}
|
}
|
||||||
.catch {
|
.catch {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import ca.gosyer.data.models.Source
|
|||||||
import ca.gosyer.i18n.MR
|
import ca.gosyer.i18n.MR
|
||||||
import ca.gosyer.ui.base.components.TooltipArea
|
import ca.gosyer.ui.base.components.TooltipArea
|
||||||
import ca.gosyer.ui.base.components.VerticalScrollbar
|
import ca.gosyer.ui.base.components.VerticalScrollbar
|
||||||
|
import ca.gosyer.ui.base.components.localeToString
|
||||||
import ca.gosyer.ui.base.components.rememberScrollbarAdapter
|
import ca.gosyer.ui.base.components.rememberScrollbarAdapter
|
||||||
import ca.gosyer.ui.base.navigation.ActionItem
|
import ca.gosyer.ui.base.navigation.ActionItem
|
||||||
import ca.gosyer.ui.base.navigation.Toolbar
|
import ca.gosyer.ui.base.navigation.Toolbar
|
||||||
@@ -55,7 +56,6 @@ import ca.gosyer.uicore.image.KamelImage
|
|||||||
import ca.gosyer.uicore.resources.stringResource
|
import ca.gosyer.uicore.resources.stringResource
|
||||||
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
|
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
|
||||||
import io.kamel.image.lazyPainterResource
|
import io.kamel.image.lazyPainterResource
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SourceHomeScreenContent(
|
fun SourceHomeScreenContent(
|
||||||
@@ -173,7 +173,7 @@ fun WideSourceItem(
|
|||||||
KamelImage(lazyPainterResource(source, filterQuality = FilterQuality.Medium), source.displayName, Modifier.size(96.dp))
|
KamelImage(lazyPainterResource(source, filterQuality = FilterQuality.Medium), source.displayName, Modifier.size(96.dp))
|
||||||
Spacer(Modifier.height(4.dp))
|
Spacer(Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
"${source.name} (${source.lang.uppercase()})",
|
"${source.name} (${source.displayLang.uppercase()})",
|
||||||
color = MaterialTheme.colors.onBackground,
|
color = MaterialTheme.colors.onBackground,
|
||||||
maxLines = 2,
|
maxLines = 2,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
@@ -210,10 +210,7 @@ fun ThinSourceItem(
|
|||||||
fontSize = 14.sp
|
fontSize = 14.sp
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
Locale.forLanguageTag(source.lang)
|
localeToString(source.displayLang),
|
||||||
?.getDisplayLanguage(Locale.getDefault())
|
|
||||||
?.ifBlank { null }
|
|
||||||
?: source.lang.uppercase(),
|
|
||||||
color = MaterialTheme.colors.onBackground,
|
color = MaterialTheme.colors.onBackground,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
|||||||
Reference in New Issue
Block a user