Fix original language filter in MangaDex (#17369)
* Fix original language filter in MangaDex. * Add new languages.
This commit is contained in:
parent
59f296a02d
commit
7b48737ba8
|
@ -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)
|
||||
|
|
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'MangaDex'
|
||||
pkgNameSuffix = 'all.mangadex'
|
||||
extClass = '.MangaDexFactory'
|
||||
extVersionCode = 185
|
||||
extVersionCode = 186
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ChapterDto>().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<String>?): HttpUrl.Builder {
|
||||
return apply { value?.forEach { addQueryParameter(name, it) } }
|
||||
private fun HttpUrl.Builder.addQueryParameter(name: String, value: Set<String>?) = apply {
|
||||
value?.forEach { addQueryParameter(name, it) }
|
||||
}
|
||||
|
||||
private inline fun <reified T> Response.parseAs(): T = use {
|
||||
|
|
|
@ -6,19 +6,25 @@ import eu.kanade.tachiyomi.source.SourceFactory
|
|||
class MangaDexFactory : SourceFactory {
|
||||
override fun createSources(): List<Source> = 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")
|
||||
|
|
|
@ -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>) :
|
||||
Filter.Group<OriginalLanguage>(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)
|
||||
}
|
||||
|
|
|
@ -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<UserDto>()
|
||||
.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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue