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 { return SManga.create().apply {
url = "/manga/${mangaDataDto.id}" url = "/manga/${mangaDataDto.id}"
val titleMap = mangaDataDto.attributes!!.title val titleMap = mangaDataDto.attributes!!.title
val dirtyTitle = titleMap[lang] val dirtyTitle =
?: titleMap["en"] titleMap.values.firstOrNull() // use literally anything from title as first resort
?: titleMap["ja-ro"]
?: mangaDataDto.attributes.altTitles ?: mangaDataDto.attributes.altTitles
.find { (it[lang] ?: it["en"]) !== null } .find { (it[lang] ?: it["en"]) !== null }
?.values?.singleOrNull() ?.values?.singleOrNull() // find something else from alt titles
?: titleMap["ja"] // romaji titles are sometimes ja (and are not altTitles)
?: titleMap.values.firstOrNull() // use literally anything from title as a last resort
title = cleanString(dirtyTitle ?: "") title = cleanString(dirtyTitle ?: "")
coverFileName?.let { coverFileName?.let {