mangadex: add option to use source language for title (#6471)
* mangadex: add option to use source language for title closes #5747 * use 'extension' instead of 'source' for variable names & translations * simplify title selection
This commit is contained in:
parent
614165b64c
commit
ac8b118d90
|
@ -76,6 +76,8 @@ original_language=Original language
|
|||
original_language_filter_chinese=%s (Manhua)
|
||||
original_language_filter_japanese=%s (Manga)
|
||||
original_language_filter_korean=%s (Manhwa)
|
||||
prefer_title_in_extension_language=Use Alternate Titles
|
||||
prefer_title_in_extension_language_summary=If there is an alternate title available which matches the extension language, it will be used
|
||||
publication_demographic=Publication demographic
|
||||
publication_demographic_josei=Josei
|
||||
publication_demographic_none=None
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'MangaDex'
|
||||
extClass = '.MangaDexFactory'
|
||||
extVersionCode = 195
|
||||
extVersionCode = 196
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -138,6 +138,11 @@ object MDConstants {
|
|||
return "${altTitlesInDescPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val preferExtensionLangTitlePref = "preferExtensionLangTitle"
|
||||
fun getPreferExtensionLangTitlePrefKey(dexLang: String): String {
|
||||
return "${preferExtensionLangTitlePref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val tagGroupContent = "content"
|
||||
private const val tagGroupFormat = "format"
|
||||
private const val tagGroupGenre = "genre"
|
||||
|
|
|
@ -113,7 +113,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
.firstInstanceOrNull<CoverArtDto>()
|
||||
?.attributes?.fileName
|
||||
}
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||
}
|
||||
|
||||
return MangasPage(mangaList, mangaListDto.hasNextPage)
|
||||
|
@ -177,7 +177,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
.firstInstanceOrNull<CoverArtDto>()
|
||||
?.attributes?.fileName
|
||||
}
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||
}
|
||||
|
||||
return MangasPage(mangaList, chapterListDto.hasNextPage)
|
||||
|
@ -360,7 +360,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
.firstInstanceOrNull<CoverArtDto>()
|
||||
?.attributes?.fileName
|
||||
}
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||
}
|
||||
|
||||
return mangaList
|
||||
|
@ -423,6 +423,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
dexLang,
|
||||
preferences.coverQuality,
|
||||
preferences.altTitlesInDesc,
|
||||
preferences.preferExtensionLangTitle,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -757,11 +758,27 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
}
|
||||
}
|
||||
|
||||
val preferExtensionLangTitlePref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getPreferExtensionLangTitlePrefKey(dexLang)
|
||||
title = helper.intl["prefer_title_in_extension_language"]
|
||||
summary = helper.intl["prefer_title_in_extension_language_summary"]
|
||||
setDefaultValue(true)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
|
||||
preferences.edit()
|
||||
.putBoolean(MDConstants.getPreferExtensionLangTitlePrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(coverQualityPref)
|
||||
screen.addPreference(tryUsingFirstVolumeCoverPref)
|
||||
screen.addPreference(dataSaverPref)
|
||||
screen.addPreference(standardHttpsPortPref)
|
||||
screen.addPreference(altTitlesInDescPref)
|
||||
screen.addPreference(preferExtensionLangTitlePref)
|
||||
screen.addPreference(contentRatingPref)
|
||||
screen.addPreference(originalLanguagePref)
|
||||
screen.addPreference(blockedGroupsPref)
|
||||
|
@ -840,6 +857,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
private val SharedPreferences.altTitlesInDesc
|
||||
get() = getBoolean(MDConstants.getAltTitlesInDescPrefKey(dexLang), false)
|
||||
|
||||
private val SharedPreferences.preferExtensionLangTitle
|
||||
get() = getBoolean(MDConstants.getPreferExtensionLangTitlePrefKey(dexLang), true)
|
||||
|
||||
/**
|
||||
* Previous versions of the extension allowed invalid UUID values to be stored in the
|
||||
* preferences. This method clear invalid UUIDs in case the user have updated from
|
||||
|
|
|
@ -275,6 +275,9 @@ class MangaDexHelper(lang: String) {
|
|||
return GET(tokenRequestUrl, headers, cacheControl)
|
||||
}
|
||||
|
||||
private fun List<Map<String, String>>.findTitleByLang(lang: String): String? =
|
||||
firstOrNull { it[lang] != null }?.values?.singleOrNull()
|
||||
|
||||
/**
|
||||
* Create a [SManga] from the JSON element with only basic attributes filled.
|
||||
*/
|
||||
|
@ -283,15 +286,24 @@ class MangaDexHelper(lang: String) {
|
|||
coverFileName: String?,
|
||||
coverSuffix: String?,
|
||||
lang: String,
|
||||
preferExtensionLangTitle: Boolean,
|
||||
): SManga = SManga.create().apply {
|
||||
url = "/manga/${mangaDataDto.id}"
|
||||
|
||||
val titleMap = mangaDataDto.attributes!!.title
|
||||
val dirtyTitle =
|
||||
titleMap.values.firstOrNull() // use literally anything from title as first resort
|
||||
?: mangaDataDto.attributes.altTitles
|
||||
.find { (it[lang] ?: it["en"]) !== null }
|
||||
?.values?.singleOrNull() // find something else from alt titles
|
||||
title = dirtyTitle?.removeEntities().orEmpty()
|
||||
title = with(mangaDataDto.attributes) {
|
||||
titleMap[lang] ?: altTitles.run {
|
||||
val mainTitle = titleMap.values.firstOrNull()
|
||||
val langTitle = findTitleByLang(lang)
|
||||
val enTitle = findTitleByLang("en")
|
||||
|
||||
if (preferExtensionLangTitle) {
|
||||
listOf(langTitle, mainTitle, enTitle)
|
||||
} else {
|
||||
listOf(mainTitle, langTitle, enTitle)
|
||||
}.firstNotNullOfOrNull { it }
|
||||
}
|
||||
}?.removeEntities().orEmpty()
|
||||
|
||||
coverFileName?.let {
|
||||
thumbnail_url = when (!coverSuffix.isNullOrEmpty()) {
|
||||
|
@ -311,6 +323,7 @@ class MangaDexHelper(lang: String) {
|
|||
lang: String,
|
||||
coverSuffix: String?,
|
||||
altTitlesInDesc: Boolean,
|
||||
preferExtensionLangTitle: Boolean,
|
||||
): SManga {
|
||||
val attr = mangaDataDto.attributes!!
|
||||
|
||||
|
@ -370,7 +383,7 @@ class MangaDexHelper(lang: String) {
|
|||
}
|
||||
}
|
||||
|
||||
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang).apply {
|
||||
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang, preferExtensionLangTitle).apply {
|
||||
description = desc
|
||||
author = authors.joinToString()
|
||||
artist = artists.joinToString()
|
||||
|
|
Loading…
Reference in New Issue