From 2dac6dc8f77c710b410e17988777a922503a8969 Mon Sep 17 00:00:00 2001 From: NGB-Was-Taken <76197326+NGB-Was-Taken@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:39:55 +0000 Subject: [PATCH 1/2] Respect the `altTitlesInDesc` preference (MD) --- .../tachiyomi/source/online/all/MangaDex.kt | 13 ++++++++++--- .../main/java/exh/md/handlers/ApiMangaParser.kt | 15 +++++++++------ app/src/main/java/exh/md/handlers/MangaHandler.kt | 6 ++++-- app/src/main/java/exh/md/utils/MdUtil.kt | 10 ++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt index 8e422e7957fa..3bcefe2fce13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/MangaDex.kt @@ -89,6 +89,7 @@ class MangaDex(delegate: HttpSource, val context: Context) : private fun blockedUploaders() = sourcePreferences.getString(getBlockedUploaderPrefKey(mdLang.lang), "").orEmpty() private fun coverQuality() = sourcePreferences.getString(getCoverQualityPrefKey(mdLang.lang), "").orEmpty() private fun tryUsingFirstVolumeCover() = sourcePreferences.getBoolean(getTryUsingFirstVolumeCoverKey(mdLang.lang), false) + private fun altTitlesInDesc() = sourcePreferences.getBoolean(getAltTitlesInDescKey(mdLang.lang), false) private val mangadexService by lazy { MangaDexService(client) @@ -191,11 +192,11 @@ class MangaDex(delegate: HttpSource, val context: Context) : @Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getMangaDetails")) override fun fetchMangaDetails(manga: SManga): Observable { - return mangaHandler.fetchMangaDetailsObservable(manga, id, coverQuality(), tryUsingFirstVolumeCover()) + return mangaHandler.fetchMangaDetailsObservable(manga, id, coverQuality(), tryUsingFirstVolumeCover(), altTitlesInDesc()) } override suspend fun getMangaDetails(manga: SManga): SManga { - return mangaHandler.getMangaDetails(manga, id, coverQuality(), tryUsingFirstVolumeCover()) + return mangaHandler.getMangaDetails(manga, id, coverQuality(), tryUsingFirstVolumeCover(), altTitlesInDesc()) } @Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getChapterList")) @@ -241,7 +242,7 @@ class MangaDex(delegate: HttpSource, val context: Context) : override fun newMetaInstance() = MangaDexSearchMetadata() override suspend fun parseIntoMetadata(metadata: MangaDexSearchMetadata, input: Triple, StatisticsMangaDto>) { - apiMangaParser.parseIntoMetadata(metadata, input.first, input.second, input.third, null, coverQuality()) + apiMangaParser.parseIntoMetadata(metadata, input.first, input.second, input.third, null, coverQuality(), altTitlesInDesc()) } // LoginSource methods @@ -348,5 +349,11 @@ class MangaDex(delegate: HttpSource, val context: Context) : fun getTryUsingFirstVolumeCoverKey(dexLang: String): String { return "${tryUsingFirstVolumeCover}_$dexLang" } + + private const val altTitlesInDesc = "altTitlesInDesc" + + fun getAltTitlesInDescKey(dexLang: String): String { + return "${altTitlesInDesc}_$dexLang" + } } } diff --git a/app/src/main/java/exh/md/handlers/ApiMangaParser.kt b/app/src/main/java/exh/md/handlers/ApiMangaParser.kt index 5467335aadf0..1eebb1a53655 100644 --- a/app/src/main/java/exh/md/handlers/ApiMangaParser.kt +++ b/app/src/main/java/exh/md/handlers/ApiMangaParser.kt @@ -43,6 +43,7 @@ class ApiMangaParser( statistics: StatisticsMangaDto?, coverFileName: String?, coverQuality: String, + altTitlesInDesc: Boolean, ): SManga { val mangaId = getManga.await(manga.url, sourceId)?.id val metadata = if (mangaId != null) { @@ -52,7 +53,7 @@ class ApiMangaParser( newMetaInstance() } - parseIntoMetadata(metadata, input, simpleChapters, statistics, coverFileName, coverQuality) + parseIntoMetadata(metadata, input, simpleChapters, statistics, coverFileName, coverQuality, altTitlesInDesc) if (mangaId != null) { metadata.mangaId = mangaId insertFlatMetadata.await(metadata.flatten()) @@ -68,6 +69,7 @@ class ApiMangaParser( statistics: StatisticsMangaDto?, coverFileName: String?, coverQuality: String, + altTitlesInDesc: Boolean, ) { with(metadata) { try { @@ -88,13 +90,14 @@ class ApiMangaParser( MdUtil.cdnCoverUrl(mangaDto.data.id, "$coverFileName$coverQuality") } } + val rawDesc = MdUtil.getFromLangMap( + langMap = mangaAttributesDto.description.asMdMap(), + currentLang = lang, + originalLanguage = mangaAttributesDto.originalLanguage, + ).orEmpty() description = MdUtil.cleanDescription( - MdUtil.getFromLangMap( - langMap = mangaAttributesDto.description.asMdMap(), - currentLang = lang, - originalLanguage = mangaAttributesDto.originalLanguage, - ).orEmpty(), + if (altTitlesInDesc) MdUtil.addAltTitleToDesc(rawDesc, altTitles) else rawDesc, ) authors = mangaRelationshipsDto.filter { relationshipDto -> diff --git a/app/src/main/java/exh/md/handlers/MangaHandler.kt b/app/src/main/java/exh/md/handlers/MangaHandler.kt index 90163daa551e..9bd9d8165023 100644 --- a/app/src/main/java/exh/md/handlers/MangaHandler.kt +++ b/app/src/main/java/exh/md/handlers/MangaHandler.kt @@ -28,6 +28,7 @@ class MangaHandler( sourceId: Long, coverQuality: String, tryUsingFirstVolumeCover: Boolean, + altTitlesInDesc: Boolean, ): SManga { return coroutineScope { val mangaId = MdUtil.getMangaId(manga.url) @@ -53,13 +54,14 @@ class MangaHandler( statistics.await(), coverFileName?.await(), coverQuality, + altTitlesInDesc, ) } } - fun fetchMangaDetailsObservable(manga: SManga, sourceId: Long, coverQuality: String, tryUsingFirstVolumeCover: Boolean): Observable { + fun fetchMangaDetailsObservable(manga: SManga, sourceId: Long, coverQuality: String, tryUsingFirstVolumeCover: Boolean, altTitlesInDesc: Boolean): Observable { return runAsObservable { - getMangaDetails(manga, sourceId, coverQuality, tryUsingFirstVolumeCover) + getMangaDetails(manga, sourceId, coverQuality, tryUsingFirstVolumeCover, altTitlesInDesc) } } diff --git a/app/src/main/java/exh/md/utils/MdUtil.kt b/app/src/main/java/exh/md/utils/MdUtil.kt index e8fccd2644fc..4b0d08fb3e02 100644 --- a/app/src/main/java/exh/md/utils/MdUtil.kt +++ b/app/src/main/java/exh/md/utils/MdUtil.kt @@ -256,5 +256,15 @@ class MdUtil { return jsonParser.encodeToString(body) .toRequestBody("application/json".toMediaType()) } + + fun addAltTitleToDesc(description: String, altTitles: List?): String { + return if (altTitles.isNullOrEmpty()) { + description + } else { + val altTitlesDesc = altTitles + .joinToString("\n", "Alternative Titles:\n") { "• $it" } + description + (if (description.isBlank()) "" else "\n\n") + altTitlesDesc + } + } } } From 3f1ff1f45367a533b04ffe20e38dedf8c5a2184a Mon Sep 17 00:00:00 2001 From: NGB-Was-Taken <76197326+NGB-Was-Taken@users.noreply.github.com> Date: Mon, 14 Oct 2024 03:09:35 +0000 Subject: [PATCH 2/2] Replace hardcoded "Alternative Titles" with localized string --- app/src/main/java/exh/md/utils/MdUtil.kt | 4 +++- i18n-sy/src/commonMain/moko-resources/base/strings.xml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/exh/md/utils/MdUtil.kt b/app/src/main/java/exh/md/utils/MdUtil.kt index 4b0d08fb3e02..709957929885 100644 --- a/app/src/main/java/exh/md/utils/MdUtil.kt +++ b/app/src/main/java/exh/md/utils/MdUtil.kt @@ -1,7 +1,9 @@ package exh.md.utils +import android.app.Application import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.track.service.TrackPreferences +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.mdlist.MdList import eu.kanade.tachiyomi.data.track.myanimelist.OAuth import eu.kanade.tachiyomi.network.POST @@ -262,7 +264,7 @@ class MdUtil { description } else { val altTitlesDesc = altTitles - .joinToString("\n", "Alternative Titles:\n") { "• $it" } + .joinToString("\n", "${Injekt.get().getString(R.string.alt_titles)}:\n") { "• $it" } description + (if (description.isBlank()) "" else "\n\n") + altTitlesDesc } } diff --git a/i18n-sy/src/commonMain/moko-resources/base/strings.xml b/i18n-sy/src/commonMain/moko-resources/base/strings.xml index 05f6d333ed3e..2a6ffe33e08d 100644 --- a/i18n-sy/src/commonMain/moko-resources/base/strings.xml +++ b/i18n-sy/src/commonMain/moko-resources/base/strings.xml @@ -679,6 +679,7 @@ Syncs any non MdList tracked entries to MangaDex as reading. MangaDex similar Community recommendations + Alternative Titles Scanlator groups to show