fix: correctly using language flag in source name to avoid it appears in folder name (#313)

* fix: correctly using language flag in source name to avoid it appears in folder name

* using flag language in PreMigration list
This commit is contained in:
Tran M. Cuong 2024-08-28 23:54:39 +07:00 committed by GitHub
parent 9def7e7380
commit ce727d6d42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 23 deletions

View file

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source
import eu.kanade.domain.source.service.SourcePreferences
import tachiyomi.domain.source.model.StubSource
import tachiyomi.presentation.core.icons.FlagEmoji
import tachiyomi.source.local.isLocal
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -9,10 +10,11 @@ import uy.kohesive.injekt.api.get
fun Source.getNameForMangaInfo(
// SY -->
mergeSources: List<Source>?,
enabledLanguages: List<String> = Injekt.get<SourcePreferences>().enabledLanguages().get()
.filterNot { it in listOf("all", "other") },
// SY <--
): String {
val preferences = Injekt.get<SourcePreferences>()
val enabledLanguages = preferences.enabledLanguages().get()
.filterNot { it in listOf("all", "other") }
val hasOneActiveLanguages = enabledLanguages.size == 1
val isInEnabledLanguages = lang in enabledLanguages
return when {
@ -23,11 +25,20 @@ fun Source.getNameForMangaInfo(
hasOneActiveLanguages,
)
// SY <--
// KMK -->
this is StubSource -> toString()
// KMK <--
// For edge cases where user disables a source they got manga of in their library.
hasOneActiveLanguages && !isInEnabledLanguages -> toString()
hasOneActiveLanguages && !isInEnabledLanguages ->
// KMK -->
"$name (${FlagEmoji.getEmojiLangFlag(lang)})"
// KMK <--
// Hide the language tag when only one language is used.
hasOneActiveLanguages && isInEnabledLanguages -> name
else -> toString()
else ->
// KMK -->
"$name (${FlagEmoji.getEmojiLangFlag(lang)})"
// KMK <--
}
}
@ -39,14 +50,28 @@ private fun getMergedSourcesString(
): String {
return if (onlyName) {
mergeSources.joinToString { source ->
if (source.lang !in enabledLangs) {
source.toString()
} else {
when {
// KMK -->
source is StubSource -> source.toString()
// KMK <--
source.lang !in enabledLangs ->
// KMK -->
"${source.name} (${FlagEmoji.getEmojiLangFlag(source.lang)})"
// KMK <--
else ->
source.name
}
}
} else {
mergeSources.joinToString()
mergeSources.joinToString { source ->
// KMK -->
if (source is StubSource) {
source.toString()
} else {
"${source.name} (${FlagEmoji.getEmojiLangFlag(source.lang)})"
}
// KMK <--
}
}
}
// SY <--

View file

@ -5,8 +5,8 @@ import android.view.View
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.databinding.MigrationSourceItemBinding
import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.source.getNameForMangaInfo
import eu.kanade.tachiyomi.source.online.HttpSource
import exh.util.capitalize
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -18,9 +18,11 @@ class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter) :
}
fun bind(source: HttpSource, sourceEnabled: Boolean) {
val isMultiLanguage = adapter.sourcePreferences.enabledLanguages().get().size > 1
// Set capitalized title.
val sourceName = if (isMultiLanguage) source.toString() else source.name.capitalize()
val sourceName =
// KMK -->
source.getNameForMangaInfo(null)
// KMK <--
binding.title.text = sourceName
// Update circle letter image.
itemView.post {

View file

@ -995,8 +995,6 @@ class MangaScreenModel(
val isLocal = manga.isLocal()
// SY -->
val isExhManga = manga.isEhBasedManga()
val enabledLanguages = sourcePreferences.enabledLanguages().get()
.filterNot { it in listOf("all", "other") }
// SY <--
return map { chapter ->
val activeDownload = if (isLocal) {
@ -1034,7 +1032,7 @@ class MangaScreenModel(
downloadProgress = activeDownload?.progress ?: 0,
selected = chapter.id in selectedChapterIds,
// SY -->
sourceName = source?.getNameForMangaInfo(null, enabledLanguages = enabledLanguages),
sourceName = source?.getNameForMangaInfo(null),
showScanlator = !isExhManga,
// SY <--
)

View file

@ -46,10 +46,6 @@ android {
}
}
dependencies {
implementation(project(":presentation-core"))
}
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions.freeCompilerArgs.addAll(

View file

@ -24,7 +24,6 @@ import okhttp3.Request
import okhttp3.Response
import rx.Observable
import tachiyomi.core.common.util.lang.awaitSingle
import tachiyomi.presentation.core.icons.FlagEmoji
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.net.URI
@ -140,9 +139,7 @@ abstract class HttpSource : CatalogueSource {
/**
* Visible name of the source.
*/
override fun toString() = "$name (${
FlagEmoji.getEmojiLangFlag(lang)
})"
override fun toString() = "$name (${lang.uppercase()})"
/**
* Get a page with a list of manga.