Comick: Localized title setting (#8111)

* Localized title preference

* lint
This commit is contained in:
BrutuZ 2025-03-17 11:47:21 -03:00 committed by Draff
parent 99c8f52676
commit 8a14edfd48
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
5 changed files with 51 additions and 7 deletions

View File

@ -12,6 +12,9 @@ group_tags_off=List all tags together
update_cover_title=Update Covers update_cover_title=Update Covers
update_cover_on=Keep cover updated update_cover_on=Keep cover updated
update_cover_off=Prefer first cover update_cover_off=Prefer first cover
local_title_title=Translated Title
local_title_on=if available
local_title_off=Use the default title from the site
score_position_title=Score Position in the Description score_position_title=Score Position in the Description
score_position_top=Top score_position_top=Top
score_position_middle=Middle score_position_middle=Middle

View File

@ -12,6 +12,9 @@ group_tags_off=Listar todas as tags juntas
update_cover_title=Atualizar Capas update_cover_title=Atualizar Capas
update_cover_on=Manter capas atualizadas update_cover_on=Manter capas atualizadas
update_cover_off=Usar apenas a primeira capa update_cover_off=Usar apenas a primeira capa
local_title_title=Título Traduzido
local_title_on=se disponível
local_title_off=Usar o título padrão do site
score_position_title=Posição da Nota na Descrição score_position_title=Posição da Nota na Descrição
score_position_top=Topo score_position_top=Topo
score_position_middle=Meio score_position_middle=Meio

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Comick' extName = 'Comick'
extClass = '.ComickFactory' extClass = '.ComickFactory'
extVersionCode = 54 extVersionCode = 55
isNsfw = true isNsfw = true
} }

View File

@ -135,6 +135,20 @@ abstract class Comick(
} }
}.also(screen::addPreference) }.also(screen::addPreference)
SwitchPreferenceCompat(screen.context).apply {
key = LOCAL_TITLE_PREF
title = intl["local_title_title"]
summaryOff = intl["local_title_off"]
summaryOn = intl["local_title_on"]
setDefaultValue(LOCAL_TITLE_DEFAULT)
setOnPreferenceChangeListener { _, newValue ->
preferences.edit()
.putBoolean(LOCAL_TITLE_PREF, newValue as Boolean)
.commit()
}
}.also(screen::addPreference)
ListPreference(screen.context).apply { ListPreference(screen.context).apply {
key = SCORE_POSITION_PREF key = SCORE_POSITION_PREF
title = intl["score_position_title"] title = intl["score_position_title"]
@ -182,6 +196,17 @@ abstract class Comick(
private val SharedPreferences.updateCover: Boolean private val SharedPreferences.updateCover: Boolean
get() = getBoolean(FIRST_COVER_PREF, FIRST_COVER_DEFAULT) get() = getBoolean(FIRST_COVER_PREF, FIRST_COVER_DEFAULT)
private val SharedPreferences.localTitle: String
get() = if (getBoolean(
LOCAL_TITLE_PREF,
LOCAL_TITLE_DEFAULT,
)
) {
comickLang.lowercase()
} else {
"all"
}
private val SharedPreferences.scorePosition: String private val SharedPreferences.scorePosition: String
get() = getString(SCORE_POSITION_PREF, SCORE_POSITION_DEFAULT) ?: SCORE_POSITION_DEFAULT get() = getString(SCORE_POSITION_PREF, SCORE_POSITION_DEFAULT) ?: SCORE_POSITION_DEFAULT
@ -437,6 +462,7 @@ abstract class Comick(
showAlternativeTitles = preferences.showAlternativeTitles, showAlternativeTitles = preferences.showAlternativeTitles,
covers = localCovers.ifEmpty { originalCovers }.ifEmpty { firstVol }, covers = localCovers.ifEmpty { originalCovers }.ifEmpty { firstVol },
groupTags = preferences.groupTags, groupTags = preferences.groupTags,
titleLang = preferences.localTitle,
) )
} }
return mangaData.toSManga( return mangaData.toSManga(
@ -444,6 +470,7 @@ abstract class Comick(
scorePosition = preferences.scorePosition, scorePosition = preferences.scorePosition,
showAlternativeTitles = preferences.showAlternativeTitles, showAlternativeTitles = preferences.showAlternativeTitles,
groupTags = preferences.groupTags, groupTags = preferences.groupTags,
titleLang = preferences.localTitle,
) )
} }
@ -571,6 +598,8 @@ abstract class Comick(
private const val FIRST_COVER_DEFAULT = true private const val FIRST_COVER_DEFAULT = true
private const val SCORE_POSITION_PREF = "ScorePosition" private const val SCORE_POSITION_PREF = "ScorePosition"
const val SCORE_POSITION_DEFAULT = "top" const val SCORE_POSITION_DEFAULT = "top"
private const val LOCAL_TITLE_PREF = "LocalTitle"
private const val LOCAL_TITLE_DEFAULT = false
private const val LIMIT = 20 private const val LIMIT = 20
private const val CHAPTERS_LIMIT = 99999 private const val CHAPTERS_LIMIT = 99999
} }

View File

@ -40,11 +40,17 @@ class Manga(
showAlternativeTitles: Boolean = SHOW_ALTERNATIVE_TITLES_DEFAULT, showAlternativeTitles: Boolean = SHOW_ALTERNATIVE_TITLES_DEFAULT,
covers: List<MDcovers>? = null, covers: List<MDcovers>? = null,
groupTags: Boolean = GROUP_TAGS_DEFAULT, groupTags: Boolean = GROUP_TAGS_DEFAULT,
) = titleLang: String,
SManga.create().apply { ): SManga {
val entryTitle = comic.altTitles.firstOrNull {
titleLang != "all" && !it.lang.isNullOrBlank() && titleLang.startsWith(it.lang)
}?.title ?: comic.title
val titles = listOf(Title(title = comic.title)) + comic.altTitles
return SManga.create().apply {
// appennding # at end as part of migration from slug to hid // appennding # at end as part of migration from slug to hid
url = "/comic/${comic.hid}#" url = "/comic/${comic.hid}#"
title = comic.title title = entryTitle
description = buildString { description = buildString {
if (scorePosition == "top") append(comic.fancyScore) if (scorePosition == "top") append(comic.fancyScore)
val desc = comic.desc?.beautifyDescription() val desc = comic.desc?.beautifyDescription()
@ -60,9 +66,10 @@ class Manga(
if (this.isNotEmpty()) append("\n\n") if (this.isNotEmpty()) append("\n\n")
append("Alternative Titles:\n") append("Alternative Titles:\n")
append( append(
comic.altTitles.mapNotNull { title -> titles.distinctBy { it.title }.filter { it.title != entryTitle }
title.title?.let { "$it" } .mapNotNull { title ->
}.joinToString("\n"), title.title?.let { "$it" }
}.joinToString("\n"),
) )
} }
if (scorePosition == "bottom") { if (scorePosition == "bottom") {
@ -97,6 +104,7 @@ class Manga(
.filterNot { it.name.isNullOrBlank() || it.group.isNullOrBlank() } .filterNot { it.name.isNullOrBlank() || it.group.isNullOrBlank() }
.joinToString { if (groupTags) "${it.group}:${it.name?.trim()}" else "${it.name?.trim()}" } .joinToString { if (groupTags) "${it.group}:${it.name?.trim()}" else "${it.name?.trim()}" }
} }
}
} }
@Serializable @Serializable
@ -171,6 +179,7 @@ class MDcovers(
@Serializable @Serializable
class Title( class Title(
val title: String?, val title: String?,
val lang: String? = null,
) )
@Serializable @Serializable