MangaDex: Show final chapter in description (#7314)

* Show final chapter in description

* Make it a preference
This commit is contained in:
DokterKaj 2025-01-26 20:45:23 +08:00 committed by Draff
parent 944586408e
commit 07c6de7cf6
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
5 changed files with 51 additions and 7 deletions

View File

@ -23,6 +23,9 @@ data_saver_summary=Enables smaller, more compressed images
excluded_tags_mode=Excluded tags mode
filter_original_languages=Filter original languages
filter_original_languages_summary=Only show content that was originally published in the selected languages in both latest and browse
final_chapter=Final chapter:
final_chapter_in_description=Final chapter in description
final_chapter_in_description_summary=Include a manga's final chapter number at the end of its description
format=Format
format_adaptation=Adaptation
format_anthology=Anthology
@ -76,8 +79,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
prefer_title_in_extension_language=Use alternative titles
prefer_title_in_extension_language_summary=If there is an alternative title available which matches the extension language, it will be used
publication_demographic=Publication demographic
publication_demographic_josei=Josei
publication_demographic_none=None

View File

@ -1,7 +1,7 @@
ext {
extName = 'MangaDex'
extClass = '.MangaDexFactory'
extVersionCode = 196
extVersionCode = 197
isNsfw = true
}

View File

@ -143,6 +143,11 @@ object MDConstants {
return "${preferExtensionLangTitlePref}_$dexLang"
}
private const val finalChapterInDescPref = "finalChapterInDesc"
fun getFinalChapterInDescPrefKey(dexLang: String): String {
return "${finalChapterInDescPref}_$dexLang"
}
private const val tagGroupContent = "content"
private const val tagGroupFormat = "format"
private const val tagGroupGenre = "genre"

View File

@ -424,6 +424,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
preferences.coverQuality,
preferences.altTitlesInDesc,
preferences.preferExtensionLangTitle,
preferences.finalChapterInDesc,
)
}
@ -773,12 +774,28 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
}
}
val finalChapterInDescPref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getFinalChapterInDescPrefKey(dexLang)
title = helper.intl["final_chapter_in_description"]
summary = helper.intl["final_chapter_in_description_summary"]
setDefaultValue(true)
setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean
preferences.edit()
.putBoolean(MDConstants.getFinalChapterInDescPrefKey(dexLang), checkValue)
.commit()
}
}
screen.addPreference(coverQualityPref)
screen.addPreference(tryUsingFirstVolumeCoverPref)
screen.addPreference(dataSaverPref)
screen.addPreference(standardHttpsPortPref)
screen.addPreference(altTitlesInDescPref)
screen.addPreference(preferExtensionLangTitlePref)
screen.addPreference(finalChapterInDescPref)
screen.addPreference(contentRatingPref)
screen.addPreference(originalLanguagePref)
screen.addPreference(blockedGroupsPref)
@ -860,6 +877,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
private val SharedPreferences.preferExtensionLangTitle
get() = getBoolean(MDConstants.getPreferExtensionLangTitlePrefKey(dexLang), true)
private val SharedPreferences.finalChapterInDesc
get() = getBoolean(MDConstants.getFinalChapterInDescPrefKey(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

View File

@ -324,6 +324,7 @@ class MangaDexHelper(lang: String) {
coverSuffix: String?,
altTitlesInDesc: Boolean,
preferExtensionLangTitle: Boolean,
finalChapterInDesc: Boolean,
): SManga {
val attr = mangaDataDto.attributes!!
@ -365,9 +366,12 @@ class MangaDexHelper(lang: String) {
val genreList = MDConstants.tagGroupsOrder.flatMap { genresMap[it].orEmpty() } + nonGenres
var desc = (attr.description[lang] ?: attr.description["en"])
// Build description
val desc = mutableListOf<String>()
(attr.description[lang] ?: attr.description["en"])
?.removeEntitiesAndMarkdown()
.orEmpty()
?.let { desc.add(it) }
if (altTitlesInDesc) {
val romanizedOriginalLang = MDConstants.romanizedLangCodes[attr.originalLanguage].orEmpty()
@ -379,12 +383,24 @@ class MangaDexHelper(lang: String) {
if (altTitles.isNotEmpty()) {
val altTitlesDesc = altTitles
.joinToString("\n", "${intl["alternative_titles"]}\n") { "$it" }
desc += (if (desc.isBlank()) "" else "\n\n") + altTitlesDesc.removeEntities()
desc.add(altTitlesDesc.removeEntities())
}
}
if (finalChapterInDesc) {
val finalChapter = mutableListOf<String>()
attr.lastVolume?.takeIf { it.isNotEmpty() }?.let { finalChapter.add("Vol.$it") }
attr.lastChapter?.takeIf { it.isNotEmpty() }?.let { finalChapter.add("Ch.$it") }
if (finalChapter.isNotEmpty()) {
val finalChapterDesc = finalChapter
.joinToString(" ", "${intl["final_chapter"]}\n")
desc.add(finalChapterDesc.removeEntities())
}
}
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang, preferExtensionLangTitle).apply {
description = desc
description = desc.joinToString("\n\n")
author = authors.joinToString()
artist = artists.joinToString()
status = getPublicationStatus(attr, chapters)