Show correct language string in browse screens (#8136)

This commit is contained in:
AntsyLich 2022-10-04 09:05:37 +06:00 committed by GitHub
parent b8fa326c21
commit bbe1608006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 11 deletions

View File

@ -41,7 +41,6 @@ import eu.kanade.presentation.util.plus
import eu.kanade.presentation.util.topPaddingValues import eu.kanade.presentation.util.topPaddingValues
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.copyToClipboard
@Composable @Composable
@ -145,7 +144,7 @@ private fun MigrateSourceItem(
Badge(text = "$count") Badge(text = "$count")
} }
}, },
content = { source, showLanguageInContent -> content = { _, sourceLangString ->
Column( Column(
modifier = Modifier modifier = Modifier
.padding(horizontal = horizontalPadding) .padding(horizontal = horizontalPadding)
@ -161,9 +160,9 @@ private fun MigrateSourceItem(
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
if (showLanguageInContent) { if (sourceLangString != null) {
Text( Text(
text = LocaleHelper.getDisplayName(source.lang), text = sourceLangString,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,

View File

@ -161,7 +161,7 @@ private fun SourceItem(
source = source, source = source,
onClickItem = { onClickItem(source, GetRemoteManga.QUERY_POPULAR) }, onClickItem = { onClickItem(source, GetRemoteManga.QUERY_POPULAR) },
onLongClickItem = { onLongClickItem(source) }, onLongClickItem = { onLongClickItem(source) },
action = { source -> action = {
if (source.supportsLatest) { if (source.supportsLatest) {
TextButton(onClick = { onClickItem(source, GetRemoteManga.QUERY_LATEST) }) { TextButton(onClick = { onClickItem(source, GetRemoteManga.QUERY_LATEST) }) {
Text( Text(

View File

@ -7,6 +7,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.Source
import eu.kanade.presentation.util.horizontalPadding import eu.kanade.presentation.util.horizontalPadding
@ -21,15 +22,16 @@ fun BaseSourceItem(
onLongClickItem: () -> Unit = {}, onLongClickItem: () -> Unit = {},
icon: @Composable RowScope.(Source) -> Unit = defaultIcon, icon: @Composable RowScope.(Source) -> Unit = defaultIcon,
action: @Composable RowScope.(Source) -> Unit = {}, 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( BaseBrowseItem(
modifier = modifier, modifier = modifier,
onClickItem = onClickItem, onClickItem = onClickItem,
onLongClickItem = onLongClickItem, onLongClickItem = onLongClickItem,
icon = { icon.invoke(this, source) }, icon = { icon.invoke(this, source) },
action = { action.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) SourceIcon(source = source)
} }
private val defaultContent: @Composable RowScope.(Source, Boolean) -> Unit = { source, showLanguageInContent -> private val defaultContent: @Composable RowScope.(Source, String?) -> Unit = { source, sourceLangString ->
Column( Column(
modifier = Modifier modifier = Modifier
.padding(horizontal = horizontalPadding) .padding(horizontal = horizontalPadding)
.weight(1f), .weight(1f),
) { ) {
Text( Text(
text = source.name.ifBlank { source.id.toString() }, text = source.name,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
) )
if (showLanguageInContent) { if (sourceLangString != null) {
Text( Text(
text = LocaleHelper.getDisplayName(source.lang), text = sourceLangString,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,