From 7b48737ba8428cb38334b976f5d1f0b0acea731d Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Sat, 5 Aug 2023 10:30:45 -0300 Subject: [PATCH] Fix original language filter in MangaDex (#17369) * Fix original language filter in MangaDex. * Add new languages. --- .../java/eu/kanade/tachiyomi/lib/i18n/Intl.kt | 6 ++ src/all/mangadex/build.gradle | 2 +- .../extension/all/mangadex/MangaDex.kt | 6 +- .../extension/all/mangadex/MangaDexFactory.kt | 18 +++++ .../extension/all/mangadex/MangaDexFilters.kt | 67 +++++++++++-------- .../extension/all/mangadex/MangaDexHelper.kt | 4 +- .../all/mangadex/MangadexUrlActivity.kt | 16 ++--- 7 files changed, 76 insertions(+), 43 deletions(-) diff --git a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt index e8878a3d2..7899da8ca 100644 --- a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt +++ b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt @@ -53,6 +53,12 @@ class Intl( 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 = Locale.forLanguageTag(localeCode) .getDisplayName(locale) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index aa05acdd5..bfedc6091 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangaDexFactory' - extVersionCode = 185 + extVersionCode = 186 isNsfw = true } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt index 7cdefb18f..132694b73 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt @@ -213,7 +213,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St .asObservable() .map { response -> 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().data!!.relationships @@ -760,8 +760,8 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St override fun getFilterList(): FilterList = helper.mdFilters.getMDFilterList(preferences, dexLang, helper.intl) - private fun HttpUrl.Builder.addQueryParameter(name: String, value: Set?): HttpUrl.Builder { - return apply { value?.forEach { addQueryParameter(name, it) } } + private fun HttpUrl.Builder.addQueryParameter(name: String, value: Set?) = apply { + value?.forEach { addQueryParameter(name, it) } } private inline fun Response.parseAs(): T = use { diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFactory.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFactory.kt index f41813667..6cbce884e 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFactory.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFactory.kt @@ -6,19 +6,25 @@ import eu.kanade.tachiyomi.source.SourceFactory class MangaDexFactory : SourceFactory { override fun createSources(): List = listOf( MangaDexEnglish(), + MangaDexAlbanian(), MangaDexArabic(), + MangaDexAzerbaijani(), MangaDexBengali(), MangaDexBulgarian(), MangaDexBurmese(), MangaDexCatalan(), MangaDexChineseSimplified(), MangaDexChineseTraditional(), + MangaDexCroatian(), MangaDexCzech(), MangaDexDanish(), MangaDexDutch(), + MangaDexEsperanto(), + MangaDexEstonian(), MangaDexFilipino(), MangaDexFinnish(), MangaDexFrench(), + MangaDexGeorgian(), MangaDexGerman(), MangaDexGreek(), MangaDexHebrew(), @@ -41,11 +47,14 @@ class MangaDexFactory : SourceFactory { MangaDexPortuguesePortugal(), MangaDexRomanian(), MangaDexRussian(), + MangaDexSerbian(), MangaDexSerboCroatian(), + MangaDexSlovak(), MangaDexSpanishLatinAmerica(), MangaDexSpanishSpain(), MangaDexSwedish(), MangaDexTamil(), + MangaDexTelugu(), MangaDexThai(), MangaDexTurkish(), MangaDexUkrainian(), @@ -53,20 +62,26 @@ class MangaDexFactory : SourceFactory { ) } +class MangaDexAlbanian : MangaDex("sq") class MangaDexArabic : MangaDex("ar") +class MangaDexAzerbaijani : MangaDex("az") class MangaDexBengali : MangaDex("bn") class MangaDexBulgarian : MangaDex("bg") class MangaDexBurmese : MangaDex("my") class MangaDexCatalan : MangaDex("ca") class MangaDexChineseSimplified : MangaDex("zh-Hans", "zh") class MangaDexChineseTraditional : MangaDex("zh-Hant", "zh-hk") +class MangaDexCroatian : MangaDex("hr") class MangaDexCzech : MangaDex("cs") class MangaDexDanish : MangaDex("da") class MangaDexDutch : MangaDex("nl") class MangaDexEnglish : MangaDex("en") +class MangaDexEsperanto : MangaDex("eo") +class MangaDexEstonian : MangaDex("et") class MangaDexFilipino : MangaDex("fil", "tl") class MangaDexFinnish : MangaDex("fi") class MangaDexFrench : MangaDex("fr") +class MangaDexGeorgian : MangaDex("ka") class MangaDexGerman : MangaDex("de") class MangaDexGreek : MangaDex("el") class MangaDexHebrew : MangaDex("he") @@ -89,11 +104,14 @@ class MangaDexPortugueseBrazil : MangaDex("pt-BR", "pt-br") class MangaDexPortuguesePortugal : MangaDex("pt") class MangaDexRomanian : MangaDex("ro") class MangaDexRussian : MangaDex("ru") +class MangaDexSerbian : MangaDex("sr") class MangaDexSerboCroatian : MangaDex("sh") +class MangaDexSlovak : MangaDex("sk") class MangaDexSpanishLatinAmerica : MangaDex("es-419", "es-la") class MangaDexSpanishSpain : MangaDex("es") class MangaDexSwedish : MangaDex("sv") class MangaDexTamil : MangaDex("ta") +class MangaDexTelugu : MangaDex("te") class MangaDexThai : MangaDex("th") class MangaDexTurkish : MangaDex("tr") class MangaDexUkrainian : MangaDex("uk") diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt index b8dff948c..05b452a01 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt @@ -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) : Filter.Group(intl["original_language"], originalLanguage), UrlQueryFilter { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { - state.forEach { lang -> - if (lang.state) { + state.filter(OriginalLanguage::state) + .forEach { lang -> // dex has zh and zh-hk for chinese manhua if (lang.isoCode == MDConstants.originalLanguagePrefValChinese) { url.addQueryParameter( @@ -63,7 +67,6 @@ class MangaDexFilters { url.addQueryParameter("originalLanguage[]", lang.isoCode) } - } } } @@ -78,12 +81,30 @@ class MangaDexFilters { )!! return listOf( - OriginalLanguage(intl["original_language_filter_japanese"], MDConstants.originalLanguagePrefValJapanese) - .apply { state = MDConstants.originalLanguagePrefValJapanese in originalLanguages }, - OriginalLanguage(intl["original_language_filter_chinese"], MDConstants.originalLanguagePrefValChinese) - .apply { state = MDConstants.originalLanguagePrefValChinese in originalLanguages }, - OriginalLanguage(intl["original_language_filter_korean"], MDConstants.originalLanguagePrefValKorean) - .apply { state = MDConstants.originalLanguagePrefValKorean in originalLanguages }, + OriginalLanguage( + name = intl.format( + "original_language_filter_japanese", + intl.languageDisplayName(MangaDexIntl.JAPANESE), + ), + 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 { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { - state.forEach { rating -> - if (rating.state) { - url.addQueryParameter("contentRating[]", rating.value) - } - } + state.filter(ContentRating::state) + .forEach { url.addQueryParameter("contentRating[]", it.value) } } } @@ -133,11 +151,8 @@ class MangaDexFilters { UrlQueryFilter { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { - state.forEach { demographic -> - if (demographic.state) { - url.addQueryParameter("publicationDemographic[]", demographic.value) - } - } + state.filter(Demographic::state) + .forEach { url.addQueryParameter("publicationDemographic[]", it.value) } } } @@ -155,11 +170,8 @@ class MangaDexFilters { UrlQueryFilter { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { - state.forEach { status -> - if (status.state) { - url.addQueryParameter("status[]", status.value) - } - } + state.filter(Status::state) + .forEach { url.addQueryParameter("status[]", it.value) } } } @@ -196,10 +208,7 @@ class MangaDexFilters { override fun addQueryParameter(url: HttpUrl.Builder, dexLang: String) { if (state != null) { val query = sortables[state!!.index].value - val value = when (state!!.ascending) { - true -> "asc" - false -> "desc" - } + val value = if (state!!.ascending) "asc" else "desc" url.addQueryParameter("order[$query]", value) } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt index 555d544ed..eae3f4eb8 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt @@ -315,7 +315,7 @@ class MangaDexHelper(lang: String) { ?.let { intl["publication_demographic_${it.name.lowercase()}"] }, attr.contentRating .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 ?.let { Locale.forLanguageTag(it) } ?.getDisplayName(dexLocale) @@ -390,7 +390,7 @@ class MangaDexHelper(lang: String) { val users = chapterDataDto.relationships .filterIsInstance() .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 diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt index fc473bdf6..2d0256a87 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangadexUrlActivity.kt @@ -22,17 +22,17 @@ class MangadexUrlActivity : Activity() { super.onCreate(savedInstanceState) val pathSegments = intent?.data?.pathSegments if (pathSegments != null && pathSegments.size > 1) { - val titleid = pathSegments[1] + val titleId = pathSegments[1] val mainIntent = Intent().apply { action = "eu.kanade.tachiyomi.SEARCH" with(pathSegments[0]) { when { - equals("chapter") -> putExtra("query", "${MDConstants.prefixChSearch}$titleid") - equals("group") -> putExtra("query", "${MDConstants.prefixGrpSearch}$titleid") - equals("user") -> putExtra("query", "${MDConstants.prefixUsrSearch}$titleid") - equals("author") -> putExtra("query", "${MDConstants.prefixAuthSearch}$titleid") - equals("list") -> putExtra("query", "${MDConstants.prefixListSearch}$titleid") - else -> putExtra("query", "${MDConstants.prefixIdSearch}$titleid") + equals("chapter") -> putExtra("query", MDConstants.prefixChSearch + titleId) + equals("group") -> putExtra("query", MDConstants.prefixGrpSearch + titleId) + equals("user") -> putExtra("query", MDConstants.prefixUsrSearch + titleId) + equals("author") -> putExtra("query", MDConstants.prefixAuthSearch + titleId) + equals("list") -> putExtra("query", MDConstants.prefixListSearch + titleId) + else -> putExtra("query", MDConstants.prefixIdSearch + titleId) } } putExtra("filter", packageName) @@ -44,7 +44,7 @@ class MangadexUrlActivity : Activity() { Log.e("MangadexUrlActivity", e.toString()) } } else { - Log.e("MangadexUrlActivity", "could not parse uri from intent $intent") + Log.e("MangadexUrlActivity", "Could not parse URI from intent $intent") } finish()