[Mangadex] Add setting to show alternative titles in manga description (#16607)
* [Mangadex] Add setting to show alternative titles in manga description Uses same-language and romanized titles only * [Mangadex] Bump build.gradle for previous * Only include romanized version of originalLanguage
This commit is contained in:
parent
d8ef062ba8
commit
812d904979
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'MangaDex'
|
||||
pkgNameSuffix = 'all.mangadex'
|
||||
extClass = '.MangaDexFactory'
|
||||
extVersionCode = 178
|
||||
extVersionCode = 179
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,11 @@ object MDConstants {
|
|||
return "${tryUsingFirstVolumeCoverPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val altTitlesInDescPref = "altTitlesInDesc"
|
||||
fun getAltTitlesInDescPrefKey(dexLang: String): String {
|
||||
return "${altTitlesInDescPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val tagGroupContent = "content"
|
||||
private const val tagGroupFormat = "format"
|
||||
private const val tagGroupGenre = "genre"
|
||||
|
@ -133,4 +138,11 @@ object MDConstants {
|
|||
|
||||
const val tagAnthologyUuid = "51d83883-4103-437c-b4b1-731cb73d786c"
|
||||
const val tagOneShotUuid = "0234a31e-a729-4e28-9d6a-3f87c4966b9e"
|
||||
|
||||
val romanizedLangCodes = mapOf(
|
||||
MangaDexIntl.JAPANESE to "ja-ro",
|
||||
MangaDexIntl.KOREAN to "ko-ro",
|
||||
MangaDexIntl.CHINESE to "zh-ro",
|
||||
"zh-hk" to "zh-ro",
|
||||
)
|
||||
}
|
||||
|
|
|
@ -402,6 +402,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
fetchFirstVolumeCover(manga),
|
||||
dexLang,
|
||||
preferences.coverQuality,
|
||||
preferences.altTitlesInDesc,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -727,10 +728,26 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
}
|
||||
}
|
||||
|
||||
val altTitlesInDescPref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getAltTitlesInDescPrefKey(dexLang)
|
||||
title = helper.intl.altTitlesInDesc
|
||||
summary = helper.intl.altTitlesInDescSummary
|
||||
setDefaultValue(false)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
|
||||
preferences.edit()
|
||||
.putBoolean(MDConstants.getAltTitlesInDescPrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(coverQualityPref)
|
||||
screen.addPreference(tryUsingFirstVolumeCoverPref)
|
||||
screen.addPreference(dataSaverPref)
|
||||
screen.addPreference(standardHttpsPortPref)
|
||||
screen.addPreference(altTitlesInDescPref)
|
||||
screen.addPreference(contentRatingPref)
|
||||
screen.addPreference(originalLanguagePref)
|
||||
screen.addPreference(blockedGroupsPref)
|
||||
|
@ -803,6 +820,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
|
|||
private val SharedPreferences.useDataSaver
|
||||
get() = getBoolean(MDConstants.getDataSaverPreferenceKey(dexLang), false)
|
||||
|
||||
private val SharedPreferences.altTitlesInDesc
|
||||
get() = getBoolean(MDConstants.getAltTitlesInDescPrefKey(dexLang), false)
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -294,6 +294,7 @@ class MangaDexHelper(lang: String) {
|
|||
firstVolumeCover: String?,
|
||||
lang: String,
|
||||
coverSuffix: String?,
|
||||
altTitlesInDesc: Boolean,
|
||||
): SManga {
|
||||
val attr = mangaDataDto.attributes!!
|
||||
|
||||
|
@ -334,10 +335,20 @@ class MangaDexHelper(lang: String) {
|
|||
|
||||
val genreList = MDConstants.tagGroupsOrder.flatMap { genresMap[it].orEmpty() } + nonGenres
|
||||
|
||||
val desc = attr.description
|
||||
var desc = attr.description[lang] ?: attr.description["en"] ?: ""
|
||||
|
||||
if (altTitlesInDesc) {
|
||||
val romanizedOriginalLang = MDConstants.romanizedLangCodes[attr.originalLanguage] ?: ""
|
||||
val altTitles = attr.altTitles.filter { it.containsKey(lang) || it.containsKey(romanizedOriginalLang) }
|
||||
.mapNotNull { it.values.singleOrNull() }
|
||||
if (altTitles.isNotEmpty()) {
|
||||
val altTitlesDesc = intl.altTitleText + altTitles.joinToString("\n", "\n")
|
||||
desc += (if (desc.isNullOrBlank()) "" else "\n\n") + altTitlesDesc
|
||||
}
|
||||
}
|
||||
|
||||
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang).apply {
|
||||
description = (desc[lang] ?: desc["en"] ?: "").removeEntitiesAndMarkdown()
|
||||
description = desc.removeEntitiesAndMarkdown()
|
||||
author = authors.joinToString(", ")
|
||||
artist = artists.joinToString(", ")
|
||||
status = getPublicationStatus(attr, chapters)
|
||||
|
|
|
@ -267,6 +267,17 @@ class MangaDexIntl(lang: String) {
|
|||
"Enter as a Comma-separated list of uploader UUIDs"
|
||||
}
|
||||
|
||||
val altTitlesInDesc: String = when (availableLang) {
|
||||
// TODO add other languages
|
||||
else -> "Alternative titles in description"
|
||||
}
|
||||
|
||||
val altTitlesInDescSummary: String = when (availableLang) {
|
||||
// TODO add other languages
|
||||
else ->
|
||||
"Include a manga's alternative titles at the end of its description"
|
||||
}
|
||||
|
||||
val tryUsingFirstVolumeCover: String = when (availableLang) {
|
||||
BRAZILIAN_PORTUGUESE, PORTUGUESE -> "Tentar usar a capa do primeiro volume como capa"
|
||||
else -> "Attempt to use the first volume cover as cover"
|
||||
|
@ -1008,6 +1019,11 @@ class MangaDexIntl(lang: String) {
|
|||
else -> "No Group"
|
||||
}
|
||||
|
||||
val altTitleText: String = when (availableLang) {
|
||||
// TODO fill in other languages
|
||||
else -> "Alternative Titles:"
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BRAZILIAN_PORTUGUESE = "pt-BR"
|
||||
const val CHINESE = "zh"
|
||||
|
|
Loading…
Reference in New Issue