Skip to content

Commit

Permalink
Respect the altTitlesInDesc preference (MD) (#1283)
Browse files Browse the repository at this point in the history
* Respect the `altTitlesInDesc` preference (MD)

* Replace hardcoded "Alternative Titles" with localized string
  • Loading branch information
NGB-Was-Taken authored Oct 14, 2024
1 parent 788d379 commit dee543c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<SManga> {
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"))
Expand Down Expand Up @@ -241,7 +242,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
override fun newMetaInstance() = MangaDexSearchMetadata()

override suspend fun parseIntoMetadata(metadata: MangaDexSearchMetadata, input: Triple<MangaDto, List<String>, 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
Expand Down Expand Up @@ -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"
}
}
}
15 changes: 9 additions & 6 deletions app/src/main/java/exh/md/handlers/ApiMangaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
Expand All @@ -68,6 +69,7 @@ class ApiMangaParser(
statistics: StatisticsMangaDto?,
coverFileName: String?,
coverQuality: String,
altTitlesInDesc: Boolean,
) {
with(metadata) {
try {
Expand All @@ -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 ->
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/exh/md/handlers/MangaHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MangaHandler(
sourceId: Long,
coverQuality: String,
tryUsingFirstVolumeCover: Boolean,
altTitlesInDesc: Boolean,
): SManga {
return coroutineScope {
val mangaId = MdUtil.getMangaId(manga.url)
Expand All @@ -53,13 +54,14 @@ class MangaHandler(
statistics.await(),
coverFileName?.await(),
coverQuality,
altTitlesInDesc,
)
}
}

fun fetchMangaDetailsObservable(manga: SManga, sourceId: Long, coverQuality: String, tryUsingFirstVolumeCover: Boolean): Observable<SManga> {
fun fetchMangaDetailsObservable(manga: SManga, sourceId: Long, coverQuality: String, tryUsingFirstVolumeCover: Boolean, altTitlesInDesc: Boolean): Observable<SManga> {
return runAsObservable {
getMangaDetails(manga, sourceId, coverQuality, tryUsingFirstVolumeCover)
getMangaDetails(manga, sourceId, coverQuality, tryUsingFirstVolumeCover, altTitlesInDesc)
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/exh/md/utils/MdUtil.kt
Original file line number Diff line number Diff line change
@@ -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.dto.MALOAuth
import eu.kanade.tachiyomi.network.POST
Expand Down Expand Up @@ -256,5 +258,15 @@ class MdUtil {
return jsonParser.encodeToString(body)
.toRequestBody("application/json".toMediaType())
}

fun addAltTitleToDesc(description: String, altTitles: List<String>?): String {
return if (altTitles.isNullOrEmpty()) {
description
} else {
val altTitlesDesc = altTitles
.joinToString("\n", "${Injekt.get<Application>().getString(R.string.alt_titles)}:\n") { "$it" }
description + (if (description.isBlank()) "" else "\n\n") + altTitlesDesc
}
}
}
}
1 change: 1 addition & 0 deletions i18n-sy/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@
<string name="mangadex_push_favorites_to_mangadex_summary">Syncs any non MdList tracked entries to MangaDex as reading.</string>
<string name="mangadex_similar">MangaDex similar</string>
<string name="community_recommendations">Community recommendations</string>
<string name="alt_titles">Alternative Titles</string>

<!-- Scanlator filters -->
<string name="select_scanlators">Scanlator groups to show</string>
Expand Down

0 comments on commit dee543c

Please sign in to comment.