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

View file

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

View file

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

View file

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

View file

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