From 812d904979b8e321a2ceffe11ec905f3cafbde2d Mon Sep 17 00:00:00 2001 From: FlaminSarge Date: Wed, 7 Jun 2023 02:17:23 -0700 Subject: [PATCH] [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 --- src/all/mangadex/build.gradle | 2 +- .../extension/all/mangadex/MDConstants.kt | 12 +++++++++++ .../extension/all/mangadex/MangaDex.kt | 20 +++++++++++++++++++ .../extension/all/mangadex/MangaDexHelper.kt | 15 ++++++++++++-- .../extension/all/mangadex/MangaDexIntl.kt | 16 +++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index 75e7ca77a..b36741aec 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 = 178 + extVersionCode = 179 isNsfw = true } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt index 9ca1c4707..b7f8eaa11 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt @@ -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", + ) } 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 4d1f2fc45..2bb9a1495 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 @@ -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 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 29f289a6a..afffb530f 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 @@ -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) diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexIntl.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexIntl.kt index 0468d394b..03183eb3f 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexIntl.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexIntl.kt @@ -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"