Fix original language filter in MangaDex (#17369)

* Fix original language filter in MangaDex.

* Add new languages.
This commit is contained in:
Alessandro Jean 2023-08-05 10:30:45 -03:00 committed by GitHub
parent 59f296a02d
commit 7b48737ba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 43 deletions

View File

@ -53,6 +53,12 @@ class Intl(
else -> "[$key]" else -> "[$key]"
} }
/**
* Uses the string as a format string and returns a string obtained by
* substituting the specified arguments, using the instance locale.
*/
fun format(key: String, vararg args: Any?) = get(key).format(locale, *args)
fun languageDisplayName(localeCode: String): String = fun languageDisplayName(localeCode: String): String =
Locale.forLanguageTag(localeCode) Locale.forLanguageTag(localeCode)
.getDisplayName(locale) .getDisplayName(locale)

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex' extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex' pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory' extClass = '.MangaDexFactory'
extVersionCode = 185 extVersionCode = 186
isNsfw = true isNsfw = true
} }

View File

@ -213,7 +213,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
.asObservable() .asObservable()
.map { response -> .map { response ->
if (response.isSuccessful.not()) { if (response.isSuccessful.not()) {
throw Exception(helper.intl["unable_to_process_chapter_request"].format(response.code)) throw Exception(helper.intl.format("unable_to_process_chapter_request", response.code))
} }
response.parseAs<ChapterDto>().data!!.relationships response.parseAs<ChapterDto>().data!!.relationships
@ -760,8 +760,8 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
override fun getFilterList(): FilterList = override fun getFilterList(): FilterList =
helper.mdFilters.getMDFilterList(preferences, dexLang, helper.intl) helper.mdFilters.getMDFilterList(preferences, dexLang, helper.intl)
private fun HttpUrl.Builder.addQueryParameter(name: String, value: Set<String>?): HttpUrl.Builder { private fun HttpUrl.Builder.addQueryParameter(name: String, value: Set<String>?) = apply {
return apply { value?.forEach { addQueryParameter(name, it) } } value?.forEach { addQueryParameter(name, it) }
} }
private inline fun <reified T> Response.parseAs(): T = use { private inline fun <reified T> Response.parseAs(): T = use {

View File

@ -6,19 +6,25 @@ import eu.kanade.tachiyomi.source.SourceFactory
class MangaDexFactory : SourceFactory { class MangaDexFactory : SourceFactory {
override fun createSources(): List<Source> = listOf( override fun createSources(): List<Source> = listOf(
MangaDexEnglish(), MangaDexEnglish(),
MangaDexAlbanian(),
MangaDexArabic(), MangaDexArabic(),
MangaDexAzerbaijani(),
MangaDexBengali(), MangaDexBengali(),
MangaDexBulgarian(), MangaDexBulgarian(),
MangaDexBurmese(), MangaDexBurmese(),
MangaDexCatalan(), MangaDexCatalan(),
MangaDexChineseSimplified(), MangaDexChineseSimplified(),
MangaDexChineseTraditional(), MangaDexChineseTraditional(),
MangaDexCroatian(),
MangaDexCzech(), MangaDexCzech(),
MangaDexDanish(), MangaDexDanish(),
MangaDexDutch(), MangaDexDutch(),
MangaDexEsperanto(),
MangaDexEstonian(),
MangaDexFilipino(), MangaDexFilipino(),
MangaDexFinnish(), MangaDexFinnish(),
MangaDexFrench(), MangaDexFrench(),
MangaDexGeorgian(),
MangaDexGerman(), MangaDexGerman(),
MangaDexGreek(), MangaDexGreek(),
MangaDexHebrew(), MangaDexHebrew(),
@ -41,11 +47,14 @@ class MangaDexFactory : SourceFactory {
MangaDexPortuguesePortugal(), MangaDexPortuguesePortugal(),
MangaDexRomanian(), MangaDexRomanian(),
MangaDexRussian(), MangaDexRussian(),
MangaDexSerbian(),
MangaDexSerboCroatian(), MangaDexSerboCroatian(),
MangaDexSlovak(),
MangaDexSpanishLatinAmerica(), MangaDexSpanishLatinAmerica(),
MangaDexSpanishSpain(), MangaDexSpanishSpain(),
MangaDexSwedish(), MangaDexSwedish(),
MangaDexTamil(), MangaDexTamil(),
MangaDexTelugu(),
MangaDexThai(), MangaDexThai(),
MangaDexTurkish(), MangaDexTurkish(),
MangaDexUkrainian(), MangaDexUkrainian(),
@ -53,20 +62,26 @@ class MangaDexFactory : SourceFactory {
) )
} }
class MangaDexAlbanian : MangaDex("sq")
class MangaDexArabic : MangaDex("ar") class MangaDexArabic : MangaDex("ar")
class MangaDexAzerbaijani : MangaDex("az")
class MangaDexBengali : MangaDex("bn") class MangaDexBengali : MangaDex("bn")
class MangaDexBulgarian : MangaDex("bg") class MangaDexBulgarian : MangaDex("bg")
class MangaDexBurmese : MangaDex("my") class MangaDexBurmese : MangaDex("my")
class MangaDexCatalan : MangaDex("ca") class MangaDexCatalan : MangaDex("ca")
class MangaDexChineseSimplified : MangaDex("zh-Hans", "zh") class MangaDexChineseSimplified : MangaDex("zh-Hans", "zh")
class MangaDexChineseTraditional : MangaDex("zh-Hant", "zh-hk") class MangaDexChineseTraditional : MangaDex("zh-Hant", "zh-hk")
class MangaDexCroatian : MangaDex("hr")
class MangaDexCzech : MangaDex("cs") class MangaDexCzech : MangaDex("cs")
class MangaDexDanish : MangaDex("da") class MangaDexDanish : MangaDex("da")
class MangaDexDutch : MangaDex("nl") class MangaDexDutch : MangaDex("nl")
class MangaDexEnglish : MangaDex("en") class MangaDexEnglish : MangaDex("en")
class MangaDexEsperanto : MangaDex("eo")
class MangaDexEstonian : MangaDex("et")
class MangaDexFilipino : MangaDex("fil", "tl") class MangaDexFilipino : MangaDex("fil", "tl")
class MangaDexFinnish : MangaDex("fi") class MangaDexFinnish : MangaDex("fi")
class MangaDexFrench : MangaDex("fr") class MangaDexFrench : MangaDex("fr")
class MangaDexGeorgian : MangaDex("ka")
class MangaDexGerman : MangaDex("de") class MangaDexGerman : MangaDex("de")
class MangaDexGreek : MangaDex("el") class MangaDexGreek : MangaDex("el")
class MangaDexHebrew : MangaDex("he") class MangaDexHebrew : MangaDex("he")
@ -89,11 +104,14 @@ class MangaDexPortugueseBrazil : MangaDex("pt-BR", "pt-br")
class MangaDexPortuguesePortugal : MangaDex("pt") class MangaDexPortuguesePortugal : MangaDex("pt")
class MangaDexRomanian : MangaDex("ro") class MangaDexRomanian : MangaDex("ro")
class MangaDexRussian : MangaDex("ru") class MangaDexRussian : MangaDex("ru")
class MangaDexSerbian : MangaDex("sr")
class MangaDexSerboCroatian : MangaDex("sh") class MangaDexSerboCroatian : MangaDex("sh")
class MangaDexSlovak : MangaDex("sk")
class MangaDexSpanishLatinAmerica : MangaDex("es-419", "es-la") class MangaDexSpanishLatinAmerica : MangaDex("es-419", "es-la")
class MangaDexSpanishSpain : MangaDex("es") class MangaDexSpanishSpain : MangaDex("es")
class MangaDexSwedish : MangaDex("sv") class MangaDexSwedish : MangaDex("sv")
class MangaDexTamil : MangaDex("ta") class MangaDexTamil : MangaDex("ta")
class MangaDexTelugu : MangaDex("te")
class MangaDexThai : MangaDex("th") class MangaDexThai : MangaDex("th")
class MangaDexTurkish : MangaDex("tr") class MangaDexTurkish : MangaDex("tr")
class MangaDexUkrainian : MangaDex("uk") class MangaDexUkrainian : MangaDex("uk")

View File

@ -45,14 +45,18 @@ class MangaDexFilters {
} }
} }
private class OriginalLanguage(name: String, val isoCode: String) : Filter.CheckBox(name) private class OriginalLanguage(
name: String,
val isoCode: String,
state: Boolean = false,
) : Filter.CheckBox(name, state)
private class OriginalLanguageList(intl: Intl, originalLanguage: List<OriginalLanguage>) : private class OriginalLanguageList(intl: Intl, originalLanguage: List<OriginalLanguage>) :
Filter.Group<OriginalLanguage>(intl["original_language"], originalLanguage), Filter.Group<OriginalLanguage>(intl["original_language"], originalLanguage),
UrlQueryFilter { UrlQueryFilter {
override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) {
state.forEach { lang -> state.filter(OriginalLanguage::state)
if (lang.state) { .forEach { lang ->
// dex has zh and zh-hk for chinese manhua // dex has zh and zh-hk for chinese manhua
if (lang.isoCode == MDConstants.originalLanguagePrefValChinese) { if (lang.isoCode == MDConstants.originalLanguagePrefValChinese) {
url.addQueryParameter( url.addQueryParameter(
@ -65,7 +69,6 @@ class MangaDexFilters {
} }
} }
} }
}
private fun getOriginalLanguage( private fun getOriginalLanguage(
preferences: SharedPreferences, preferences: SharedPreferences,
@ -78,12 +81,30 @@ class MangaDexFilters {
)!! )!!
return listOf( return listOf(
OriginalLanguage(intl["original_language_filter_japanese"], MDConstants.originalLanguagePrefValJapanese) OriginalLanguage(
.apply { state = MDConstants.originalLanguagePrefValJapanese in originalLanguages }, name = intl.format(
OriginalLanguage(intl["original_language_filter_chinese"], MDConstants.originalLanguagePrefValChinese) "original_language_filter_japanese",
.apply { state = MDConstants.originalLanguagePrefValChinese in originalLanguages }, intl.languageDisplayName(MangaDexIntl.JAPANESE),
OriginalLanguage(intl["original_language_filter_korean"], MDConstants.originalLanguagePrefValKorean) ),
.apply { state = MDConstants.originalLanguagePrefValKorean in originalLanguages }, isoCode = MDConstants.originalLanguagePrefValJapanese,
state = MDConstants.originalLanguagePrefValJapanese in originalLanguages,
),
OriginalLanguage(
name = intl.format(
"original_language_filter_chinese",
intl.languageDisplayName(MangaDexIntl.CHINESE),
),
isoCode = MDConstants.originalLanguagePrefValChinese,
state = MDConstants.originalLanguagePrefValChinese in originalLanguages,
),
OriginalLanguage(
name = intl.format(
"original_language_filter_korean",
intl.languageDisplayName(MangaDexIntl.KOREAN),
),
isoCode = MDConstants.originalLanguagePrefValKorean,
state = MDConstants.originalLanguagePrefValKorean in originalLanguages,
),
) )
} }
@ -93,11 +114,8 @@ class MangaDexFilters {
UrlQueryFilter { UrlQueryFilter {
override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) {
state.forEach { rating -> state.filter(ContentRating::state)
if (rating.state) { .forEach { url.addQueryParameter("contentRating[]", it.value) }
url.addQueryParameter("contentRating[]", rating.value)
}
}
} }
} }
@ -133,11 +151,8 @@ class MangaDexFilters {
UrlQueryFilter { UrlQueryFilter {
override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) {
state.forEach { demographic -> state.filter(Demographic::state)
if (demographic.state) { .forEach { url.addQueryParameter("publicationDemographic[]", it.value) }
url.addQueryParameter("publicationDemographic[]", demographic.value)
}
}
} }
} }
@ -155,11 +170,8 @@ class MangaDexFilters {
UrlQueryFilter { UrlQueryFilter {
override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) {
state.forEach { status -> state.filter(Status::state)
if (status.state) { .forEach { url.addQueryParameter("status[]", it.value) }
url.addQueryParameter("status[]", status.value)
}
}
} }
} }
@ -196,10 +208,7 @@ class MangaDexFilters {
override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) {
if (state != null) { if (state != null) {
val query = sortables[state!!.index].value val query = sortables[state!!.index].value
val value = when (state!!.ascending) { val value = if (state!!.ascending) "asc" else "desc"
true -> "asc"
false -> "desc"
}
url.addQueryParameter("order[$query]", value) url.addQueryParameter("order[$query]", value)
} }

View File

@ -315,7 +315,7 @@ class MangaDexHelper(lang: String) {
?.let { intl["publication_demographic_${it.name.lowercase()}"] }, ?.let { intl["publication_demographic_${it.name.lowercase()}"] },
attr.contentRating attr.contentRating
.takeIf { it != ContentRatingDto.SAFE } .takeIf { it != ContentRatingDto.SAFE }
?.let { intl["content_rating_genre"].format(intl["content_rating_${it.name.lowercase()}"]) }, ?.let { intl.format("content_rating_genre", intl["content_rating_${it.name.lowercase()}"]) },
attr.originalLanguage attr.originalLanguage
?.let { Locale.forLanguageTag(it) } ?.let { Locale.forLanguageTag(it) }
?.getDisplayName(dexLocale) ?.getDisplayName(dexLocale)
@ -390,7 +390,7 @@ class MangaDexHelper(lang: String) {
val users = chapterDataDto.relationships val users = chapterDataDto.relationships
.filterIsInstance<UserDto>() .filterIsInstance<UserDto>()
.mapNotNull { it.attributes?.username } .mapNotNull { it.attributes?.username }
if (users.isNotEmpty()) intl["uploaded_by"].format(users.joinToString(" & ")) else "" if (users.isNotEmpty()) intl.format("uploaded_by", users.joinToString(" & ")) else ""
} }
.ifEmpty { intl["no_group"] } // "No Group" as final resort .ifEmpty { intl["no_group"] } // "No Group" as final resort

View File

@ -22,17 +22,17 @@ class MangadexUrlActivity : Activity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size > 1) { if (pathSegments != null && pathSegments.size > 1) {
val titleid = pathSegments[1] val titleId = pathSegments[1]
val mainIntent = Intent().apply { val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH" action = "eu.kanade.tachiyomi.SEARCH"
with(pathSegments[0]) { with(pathSegments[0]) {
when { when {
equals("chapter") -> putExtra("query", "${MDConstants.prefixChSearch}$titleid") equals("chapter") -> putExtra("query", MDConstants.prefixChSearch + titleId)
equals("group") -> putExtra("query", "${MDConstants.prefixGrpSearch}$titleid") equals("group") -> putExtra("query", MDConstants.prefixGrpSearch + titleId)
equals("user") -> putExtra("query", "${MDConstants.prefixUsrSearch}$titleid") equals("user") -> putExtra("query", MDConstants.prefixUsrSearch + titleId)
equals("author") -> putExtra("query", "${MDConstants.prefixAuthSearch}$titleid") equals("author") -> putExtra("query", MDConstants.prefixAuthSearch + titleId)
equals("list") -> putExtra("query", "${MDConstants.prefixListSearch}$titleid") equals("list") -> putExtra("query", MDConstants.prefixListSearch + titleId)
else -> putExtra("query", "${MDConstants.prefixIdSearch}$titleid") else -> putExtra("query", MDConstants.prefixIdSearch + titleId)
} }
} }
putExtra("filter", packageName) putExtra("filter", packageName)
@ -44,7 +44,7 @@ class MangadexUrlActivity : Activity() {
Log.e("MangadexUrlActivity", e.toString()) Log.e("MangadexUrlActivity", e.toString())
} }
} else { } else {
Log.e("MangadexUrlActivity", "could not parse uri from intent $intent") Log.e("MangadexUrlActivity", "Could not parse URI from intent $intent")
} }
finish() finish()