Skip to content

Commit

Permalink
Comick: Add Tag Grouping setting (#5816)
Browse files Browse the repository at this point in the history
Add Tag Grouping setting
  • Loading branch information
BrutuZ authored and cuong-tran committed Nov 1, 2024
1 parent 92d847d commit b89f4a3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/all/comickfun/assets/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ ignored_groups_summary=Chapters from these groups won't be shown.\nOne group nam
include_tags_title=Include Tags
include_tags_on=More specific, but might contain spoilers!
include_tags_off=Only the broader genres
group_tags_title=Group Tags (fork must support grouping)
group_tags_on=Will prefix tags with their type
group_tags_off=List all tags together
update_cover_title=Update Covers
update_cover_on=Keep cover updated
update_cover_off=Prefer first cover
Expand Down
3 changes: 3 additions & 0 deletions src/all/comickfun/assets/i18n/messages_pt_br.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ ignored_groups_summary=Capítulos desses grupos não aparecerão.\nUm grupo por
include_tags_title=Incluir Tags
include_tags_on=Mais detalhadas, mas podem conter spoilers
include_tags_off=Apenas os gêneros básicos
group_tags_title=Agrupar Tags (necessário fork compatível)
group_tags_on=Prefixar tags com o respectivo tipo
group_tags_off=Listar todas as tags juntas
update_cover_title=Atualizar Capas
update_cover_on=Manter capas atualizadas
update_cover_off=Usar apenas a primeira capa
Expand Down
2 changes: 1 addition & 1 deletion src/all/comickfun/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
kmkVersionCode = 1
extName = 'Comick'
extClass = '.ComickFactory'
extVersionCode = 48
extVersionCode = 49
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ abstract class Comick(
}
}.also(screen::addPreference)

SwitchPreferenceCompat(screen.context).apply {
key = GROUP_TAGS_PREF
title = intl["group_tags_title"]
summaryOn = intl["group_tags_on"]
summaryOff = intl["group_tags_off"]
setDefaultValue(GROUP_TAGS_DEFAULT)

setOnPreferenceChangeListener { _, newValue ->
preferences.edit()
.putBoolean(GROUP_TAGS_PREF, newValue as Boolean)
.commit()
}
}.also(screen::addPreference)

SwitchPreferenceCompat(screen.context).apply {
key = FIRST_COVER_PREF
title = intl["update_cover_title"]
Expand Down Expand Up @@ -149,6 +163,9 @@ abstract class Comick(
private val SharedPreferences.includeMuTags: Boolean
get() = getBoolean(INCLUDE_MU_TAGS_PREF, INCLUDE_MU_TAGS_DEFAULT)

private val SharedPreferences.groupTags: Boolean
get() = getBoolean(GROUP_TAGS_PREF, GROUP_TAGS_DEFAULT)

private val SharedPreferences.updateCover: Boolean
get() = getBoolean(FIRST_COVER_PREF, FIRST_COVER_DEFAULT)

Expand Down Expand Up @@ -393,11 +410,13 @@ abstract class Comick(
includeMuTags = preferences.includeMuTags,
scorePosition = preferences.scorePosition,
covers = covers,
groupTags = preferences.groupTags,
)
}
return mangaData.toSManga(
includeMuTags = preferences.includeMuTags,
scorePosition = preferences.scorePosition,
groupTags = preferences.groupTags,
)
}

Expand Down Expand Up @@ -537,6 +556,8 @@ abstract class Comick(
private const val IGNORED_GROUPS_PREF = "IgnoredGroups"
private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags"
const val INCLUDE_MU_TAGS_DEFAULT = false
private const val GROUP_TAGS_PREF = "GroupTags"
const val GROUP_TAGS_DEFAULT = false
private const val MIGRATED_IGNORED_GROUPS = "MigratedIgnoredGroups"
private const val FIRST_COVER_PREF = "DefaultCover"
private const val FIRST_COVER_DEFAULT = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.extension.all.comickfun

import eu.kanade.tachiyomi.extension.all.comickfun.Comick.Companion.GROUP_TAGS_DEFAULT
import eu.kanade.tachiyomi.extension.all.comickfun.Comick.Companion.INCLUDE_MU_TAGS_DEFAULT
import eu.kanade.tachiyomi.extension.all.comickfun.Comick.Companion.SCORE_POSITION_DEFAULT
import eu.kanade.tachiyomi.source.model.SChapter
Expand Down Expand Up @@ -29,13 +30,14 @@ class Manga(
val comic: Comic,
private val artists: List<Name> = emptyList(),
private val authors: List<Name> = emptyList(),
private val genres: List<Name> = emptyList(),
private val genres: List<Genre> = emptyList(),
private val demographic: String? = null,
) {
fun toSManga(
includeMuTags: Boolean = INCLUDE_MU_TAGS_DEFAULT,
scorePosition: String = SCORE_POSITION_DEFAULT,
covers: List<MDcovers>? = null,
groupTags: Boolean = GROUP_TAGS_DEFAULT,
) =
SManga.create().apply {
// appennding # at end as part of migration from slug to hid
Expand Down Expand Up @@ -75,19 +77,23 @@ class Manga(
artist = artists.joinToString { it.name.trim() }
author = authors.joinToString { it.name.trim() }
genre = buildList {
comic.origination?.let(::add)
demographic?.let { add(Name(it)) }
addAll(genres)
addAll(comic.mdGenres.mapNotNull { it.name })
comic.origination?.let { add(Genre("Origination", it.name)) }
demographic?.let { add(Genre("Demographic", it)) }
addAll(
comic.mdGenres.mapNotNull { it.genre }.sortedBy { it.group }
.sortedBy { it.name },
)
addAll(genres.sortedBy { it.group }.sortedBy { it.name })
if (includeMuTags) {
comic.muGenres.categories.forEach { category ->
category?.category?.title?.let { add(Name(it)) }
}
addAll(
comic.muGenres.categories.mapNotNull { it?.category?.title }.sorted()
.map { Genre("Category", it) },
)
}
}
.distinctBy { it.name }
.filter { it.name.isNotBlank() }
.joinToString { it.name.trim() }
.filterNot { it.name.isNullOrBlank() || it.group.isNullOrBlank() }
.joinToString { if (groupTags) "${it.group}:${it.name?.trim()}" else "${it.name?.trim()}" }
}
}

Expand Down Expand Up @@ -128,7 +134,13 @@ class Comic(

@Serializable
class MdGenres(
@SerialName("md_genres") val name: Name? = null,
@SerialName("md_genres") val genre: Genre? = null,
)

@Serializable
class Genre(
val group: String? = null,
val name: String? = null,
)

@Serializable
Expand Down

0 comments on commit b89f4a3

Please sign in to comment.