Refactor title selection logic (#14649)

most data in dex should be more stable than when this code was written
this is also how their Front-end does it

next refactor will be when the alt-title/title rework
This commit is contained in:
nicki 2022-12-23 16:08:59 -06:00 committed by GitHub
parent 9aa3d12aff
commit 26ed286526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -264,14 +264,11 @@ class MangaDexHelper(lang: String) {
return SManga.create().apply {
url = "/manga/${mangaDataDto.id}"
val titleMap = mangaDataDto.attributes!!.title
val dirtyTitle = titleMap[lang]
?: titleMap["en"]
?: titleMap["ja-ro"]
val dirtyTitle =
titleMap.values.firstOrNull() // use literally anything from title as first resort
?: mangaDataDto.attributes.altTitles
.find { (it[lang] ?: it["en"]) !== null }
?.values?.singleOrNull()
?: titleMap["ja"] // romaji titles are sometimes ja (and are not altTitles)
?: titleMap.values.firstOrNull() // use literally anything from title as a last resort
?.values?.singleOrNull() // find something else from alt titles
title = cleanString(dirtyTitle ?: "")
coverFileName?.let {