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_chinese=%s (Manhua)
|
||||||
original_language_filter_japanese=%s (Manga)
|
original_language_filter_japanese=%s (Manga)
|
||||||
original_language_filter_korean=%s (Manhwa)
|
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=Publication demographic
|
||||||
publication_demographic_josei=Josei
|
publication_demographic_josei=Josei
|
||||||
publication_demographic_none=None
|
publication_demographic_none=None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'MangaDex'
|
extName = 'MangaDex'
|
||||||
extClass = '.MangaDexFactory'
|
extClass = '.MangaDexFactory'
|
||||||
extVersionCode = 195
|
extVersionCode = 196
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,11 @@ object MDConstants {
|
||||||
return "${altTitlesInDescPref}_$dexLang"
|
return "${altTitlesInDescPref}_$dexLang"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val preferExtensionLangTitlePref = "preferExtensionLangTitle"
|
||||||
|
fun getPreferExtensionLangTitlePrefKey(dexLang: String): String {
|
||||||
|
return "${preferExtensionLangTitlePref}_$dexLang"
|
||||||
|
}
|
||||||
|
|
||||||
private const val tagGroupContent = "content"
|
private const val tagGroupContent = "content"
|
||||||
private const val tagGroupFormat = "format"
|
private const val tagGroupFormat = "format"
|
||||||
private const val tagGroupGenre = "genre"
|
private const val tagGroupGenre = "genre"
|
||||||
|
|
|
@ -113,7 +113,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
||||||
.firstInstanceOrNull<CoverArtDto>()
|
.firstInstanceOrNull<CoverArtDto>()
|
||||||
?.attributes?.fileName
|
?.attributes?.fileName
|
||||||
}
|
}
|
||||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
return MangasPage(mangaList, mangaListDto.hasNextPage)
|
return MangasPage(mangaList, mangaListDto.hasNextPage)
|
||||||
|
@ -177,7 +177,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
||||||
.firstInstanceOrNull<CoverArtDto>()
|
.firstInstanceOrNull<CoverArtDto>()
|
||||||
?.attributes?.fileName
|
?.attributes?.fileName
|
||||||
}
|
}
|
||||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
return MangasPage(mangaList, chapterListDto.hasNextPage)
|
return MangasPage(mangaList, chapterListDto.hasNextPage)
|
||||||
|
@ -360,7 +360,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
||||||
.firstInstanceOrNull<CoverArtDto>()
|
.firstInstanceOrNull<CoverArtDto>()
|
||||||
?.attributes?.fileName
|
?.attributes?.fileName
|
||||||
}
|
}
|
||||||
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
|
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang, preferences.preferExtensionLangTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mangaList
|
return mangaList
|
||||||
|
@ -423,6 +423,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
||||||
dexLang,
|
dexLang,
|
||||||
preferences.coverQuality,
|
preferences.coverQuality,
|
||||||
preferences.altTitlesInDesc,
|
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(coverQualityPref)
|
||||||
screen.addPreference(tryUsingFirstVolumeCoverPref)
|
screen.addPreference(tryUsingFirstVolumeCoverPref)
|
||||||
screen.addPreference(dataSaverPref)
|
screen.addPreference(dataSaverPref)
|
||||||
screen.addPreference(standardHttpsPortPref)
|
screen.addPreference(standardHttpsPortPref)
|
||||||
screen.addPreference(altTitlesInDescPref)
|
screen.addPreference(altTitlesInDescPref)
|
||||||
|
screen.addPreference(preferExtensionLangTitlePref)
|
||||||
screen.addPreference(contentRatingPref)
|
screen.addPreference(contentRatingPref)
|
||||||
screen.addPreference(originalLanguagePref)
|
screen.addPreference(originalLanguagePref)
|
||||||
screen.addPreference(blockedGroupsPref)
|
screen.addPreference(blockedGroupsPref)
|
||||||
|
@ -840,6 +857,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
||||||
private val SharedPreferences.altTitlesInDesc
|
private val SharedPreferences.altTitlesInDesc
|
||||||
get() = getBoolean(MDConstants.getAltTitlesInDescPrefKey(dexLang), false)
|
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
|
* 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
|
* 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)
|
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.
|
* Create a [SManga] from the JSON element with only basic attributes filled.
|
||||||
*/
|
*/
|
||||||
|
@ -283,15 +286,24 @@ class MangaDexHelper(lang: String) {
|
||||||
coverFileName: String?,
|
coverFileName: String?,
|
||||||
coverSuffix: String?,
|
coverSuffix: String?,
|
||||||
lang: String,
|
lang: String,
|
||||||
|
preferExtensionLangTitle: Boolean,
|
||||||
): SManga = SManga.create().apply {
|
): SManga = SManga.create().apply {
|
||||||
url = "/manga/${mangaDataDto.id}"
|
url = "/manga/${mangaDataDto.id}"
|
||||||
|
|
||||||
val titleMap = mangaDataDto.attributes!!.title
|
val titleMap = mangaDataDto.attributes!!.title
|
||||||
val dirtyTitle =
|
title = with(mangaDataDto.attributes) {
|
||||||
titleMap.values.firstOrNull() // use literally anything from title as first resort
|
titleMap[lang] ?: altTitles.run {
|
||||||
?: mangaDataDto.attributes.altTitles
|
val mainTitle = titleMap.values.firstOrNull()
|
||||||
.find { (it[lang] ?: it["en"]) !== null }
|
val langTitle = findTitleByLang(lang)
|
||||||
?.values?.singleOrNull() // find something else from alt titles
|
val enTitle = findTitleByLang("en")
|
||||||
title = dirtyTitle?.removeEntities().orEmpty()
|
|
||||||
|
if (preferExtensionLangTitle) {
|
||||||
|
listOf(langTitle, mainTitle, enTitle)
|
||||||
|
} else {
|
||||||
|
listOf(mainTitle, langTitle, enTitle)
|
||||||
|
}.firstNotNullOfOrNull { it }
|
||||||
|
}
|
||||||
|
}?.removeEntities().orEmpty()
|
||||||
|
|
||||||
coverFileName?.let {
|
coverFileName?.let {
|
||||||
thumbnail_url = when (!coverSuffix.isNullOrEmpty()) {
|
thumbnail_url = when (!coverSuffix.isNullOrEmpty()) {
|
||||||
|
@ -311,6 +323,7 @@ class MangaDexHelper(lang: String) {
|
||||||
lang: String,
|
lang: String,
|
||||||
coverSuffix: String?,
|
coverSuffix: String?,
|
||||||
altTitlesInDesc: Boolean,
|
altTitlesInDesc: Boolean,
|
||||||
|
preferExtensionLangTitle: Boolean,
|
||||||
): SManga {
|
): SManga {
|
||||||
val attr = mangaDataDto.attributes!!
|
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
|
description = desc
|
||||||
author = authors.joinToString()
|
author = authors.joinToString()
|
||||||
artist = artists.joinToString()
|
artist = artists.joinToString()
|
||||||
|
|
Loading…
Reference in New Issue