Yokan / rebuild
Course 1 8624561

DbChapterReleasePreference.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/database/DbChapterReleasePreference.kt

implementation41 lines
1package eu.friedcutlet.yokan.database23import eu.friedcutlet.yokan.domain.ChapterReleasePreferences4import eu.friedcutlet.yokan.domain.normalizeScanlator5import kotlinx.serialization.Serializable67@Serializable8data class DbChapterReleasePreference(9    val mangaId: Long? = null,10    val scanlatorPriority: List<String> = emptyList(),11    val skipDuplicateReleases: Boolean = false,12) {13    fun toPolicy() = ChapterReleasePreferences(scanlatorPriority, skipDuplicateReleases)14}1516fun DbSettings.chapterReleasePreference(mangaId: Long?): DbChapterReleasePreference =17    chapterReleasePreferences.firstOrNull { it.mangaId == mangaId }18        ?: chapterReleasePreferences.firstOrNull { it.mangaId == null }?.copy(mangaId = mangaId)19        ?: DbChapterReleasePreference(mangaId)2021fun DbSettings.withChapterReleasePreference(preference: DbChapterReleasePreference): DbSettings = copy(22    chapterReleasePreferences = chapterReleasePreferences.filterNot { it.mangaId == preference.mangaId } +23        preference.copy(scanlatorPriority = preference.scanlatorPriority.map(::normalizeScanlator).distinct()),24)2526fun DbSettings.withoutChapterReleaseOverride(mangaId: Long): DbSettings = copy(27    chapterReleasePreferences = chapterReleasePreferences.filterNot { it.mangaId == mangaId },28)2930fun orderedScanlators(priority: List<String>, available: List<String>): List<String> =31    (priority.map(::normalizeScanlator) + available.map(::normalizeScanlator).distinct().sorted()).distinct()3233fun movedScanlator(priority: List<String>, available: List<String>, scanlator: String, direction: Int): List<String> {34    val ordered = orderedScanlators(priority, available).toMutableList()35    val index = ordered.indexOf(normalizeScanlator(scanlator))36    val target = index + direction37    if (index < 0 || target !in ordered.indices) return ordered38    val value = ordered.removeAt(index)39    ordered.add(target, value)40    return ordered41}42

Search chapters, reference and source filenames.