From bbe16080062c2bee725226c5196e2800b4ba16ef Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Tue, 4 Oct 2022 09:05:37 +0600 Subject: [PATCH] Show correct language string in browse screens (#8136) --- .../presentation/browse/MigrateSourceScreen.kt | 7 +++---- .../eu/kanade/presentation/browse/SourcesScreen.kt | 2 +- .../browse/components/BaseSourceItem.kt | 14 ++++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) 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 790473260..10a81636e 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt @@ -41,7 +41,6 @@ import eu.kanade.presentation.util.plus import eu.kanade.presentation.util.topPaddingValues import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter -import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.copyToClipboard @Composable @@ -145,7 +144,7 @@ private fun MigrateSourceItem( Badge(text = "$count") } }, - content = { source, showLanguageInContent -> + content = { _, sourceLangString -> Column( modifier = Modifier .padding(horizontal = horizontalPadding) @@ -161,9 +160,9 @@ private fun MigrateSourceItem( horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, ) { - if (showLanguageInContent) { + if (sourceLangString != null) { Text( - text = LocaleHelper.getDisplayName(source.lang), + text = sourceLangString, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall, 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 3dfccc6d4..1dc0135ec 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt @@ -161,7 +161,7 @@ private fun SourceItem( source = source, onClickItem = { onClickItem(source, GetRemoteManga.QUERY_POPULAR) }, onLongClickItem = { onLongClickItem(source) }, - action = { source -> + action = { if (source.supportsLatest) { TextButton(onClick = { onClickItem(source, GetRemoteManga.QUERY_LATEST) }) { Text( diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt index 9fc9254ab..7f2e7f8e2 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt @@ -7,6 +7,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow import eu.kanade.domain.source.model.Source import eu.kanade.presentation.util.horizontalPadding @@ -21,15 +22,16 @@ fun BaseSourceItem( onLongClickItem: () -> Unit = {}, icon: @Composable RowScope.(Source) -> Unit = defaultIcon, action: @Composable RowScope.(Source) -> Unit = {}, - content: @Composable RowScope.(Source, Boolean) -> Unit = defaultContent, + content: @Composable RowScope.(Source, String?) -> Unit = defaultContent, ) { + val sourceLangString = LocaleHelper.getSourceDisplayName(source.lang, LocalContext.current).takeIf { showLanguageInContent } BaseBrowseItem( modifier = modifier, onClickItem = onClickItem, onLongClickItem = onLongClickItem, icon = { icon.invoke(this, source) }, action = { action.invoke(this, source) }, - content = { content.invoke(this, source, showLanguageInContent) }, + content = { content.invoke(this, source, sourceLangString) }, ) } @@ -37,21 +39,21 @@ private val defaultIcon: @Composable RowScope.(Source) -> Unit = { source -> SourceIcon(source = source) } -private val defaultContent: @Composable RowScope.(Source, Boolean) -> Unit = { source, showLanguageInContent -> +private val defaultContent: @Composable RowScope.(Source, String?) -> Unit = { source, sourceLangString -> Column( modifier = Modifier .padding(horizontal = horizontalPadding) .weight(1f), ) { Text( - text = source.name.ifBlank { source.id.toString() }, + text = source.name, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodyMedium, ) - if (showLanguageInContent) { + if (sourceLangString != null) { Text( - text = LocaleHelper.getDisplayName(source.lang), + text = sourceLangString, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall,