Yokan / rebuild
Course 1 8624561

DbLibraryPreferences.kt

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

implementation105 lines
1package eu.friedcutlet.yokan.database23import kotlinx.serialization.Serializable45@Serializable6data class DbLibraryPreferences(7    /** Missing = ask, zero = uncategorized, positive = a category of the same media type. */8    val defaultCategoryIds: Map<DbItemType, Long> = emptyMap(),9    val groupingByType: Map<DbItemType, DbLibraryGrouping> = emptyMap(),10    val categoryPreferences: Map<DbItemType, Map<Long, DbCategoryLibraryPreferences>> = emptyMap(),11    val extraFilters: Map<DbItemType, DbLibraryExtraFilters> = emptyMap(),12    val randomSeeds: Map<DbItemType, Long> = emptyMap(),13    val updateRulesByType: Map<DbItemType, DbSmartUpdateRules> = emptyMap(),14    val updateGroupModes: Map<DbItemType, DbGroupUpdateMode> = emptyMap(),15    val deviceConstraints: DbAutomaticUpdateConstraints = DbAutomaticUpdateConstraints(),16    /** Animetail "Set as default" chapter/episode list settings; missing = built-in default. */17    val chapterListDefaults: Map<DbItemType, DbChapterListDefaults> = emptyMap(),18    /** Per-title episode filler filter (title id → 1 only filler, 2 hide filler); missing = media type default. */19    val chapterFillerFilters: Map<Long, Int> = emptyMap(),20) {21    fun chapterListDefault(type: DbItemType) = chapterListDefaults[type] ?: DbChapterListDefaults()22    fun withChapterListDefault(type: DbItemType, defaults: DbChapterListDefaults) = copy(23        chapterListDefaults = if (defaults == DbChapterListDefaults()) chapterListDefaults - type else chapterListDefaults + (type to defaults),24    )25    fun updateRules(type: DbItemType) = updateRulesByType[type] ?: DbSmartUpdateRules()26    fun updateGroupMode(type: DbItemType) = updateGroupModes[type] ?: DbGroupUpdateMode.Global27    fun withUpdateRules(type: DbItemType, rules: DbSmartUpdateRules) = copy(28        updateRulesByType = if (rules == DbSmartUpdateRules()) updateRulesByType - type else updateRulesByType + (type to rules),29    )30    fun withUpdateGroupMode(type: DbItemType, mode: DbGroupUpdateMode) = copy(31        updateGroupModes = if (mode == DbGroupUpdateMode.Global) updateGroupModes - type else updateGroupModes + (type to mode),32    )33    fun grouping(type: DbItemType): DbLibraryGrouping = groupingByType[type] ?: DbLibraryGrouping.Categories34    fun categories(type: DbItemType): Map<Long, DbCategoryLibraryPreferences> = categoryPreferences[type].orEmpty()35    fun filters(type: DbItemType): DbLibraryExtraFilters = extraFilters[type] ?: DbLibraryExtraFilters()36    fun withFilters(type: DbItemType, filters: DbLibraryExtraFilters): DbLibraryPreferences = copy(37        extraFilters = if (filters == DbLibraryExtraFilters()) extraFilters - type else extraFilters + (type to filters),38    )3940    fun withGrouping(type: DbItemType, grouping: DbLibraryGrouping): DbLibraryPreferences = copy(41        groupingByType = if (grouping == DbLibraryGrouping.Categories) groupingByType - type else groupingByType + (type to grouping),42    )4344    fun withCategory(type: DbItemType, id: Long, preferences: DbCategoryLibraryPreferences?): DbLibraryPreferences {45        val updated = if (preferences == null) categories(type) - id else categories(type) + (id to preferences)46        return copy(categoryPreferences = if (updated.isEmpty()) categoryPreferences - type else categoryPreferences + (type to updated))47    }4849    fun defaultCategory(type: DbItemType): Long? = defaultCategoryIds[type]?.takeIf { it >= 0 }5051    fun withDefaultCategory(type: DbItemType, id: Long?): DbLibraryPreferences = copy(52        defaultCategoryIds = if (id == null || id < 0) defaultCategoryIds - type else defaultCategoryIds + (type to id),53    )54}5556@Serializable57data class DbSmartUpdateRules(58    val skipCompleted: Boolean = false,59    val onlyCaughtUp: Boolean = false,60    val onlyStarted: Boolean = false,61    /** Preserve Yokan's existing automatic/manual cadence by default. */62    val respectExpectedReleasePeriod: Boolean = true,63)6465/** Used by titles without their own sort/filter entry. Filters: 0 off, 1 only matching, 2 exclude matching. */66@Serializable67data class DbChapterListDefaults(68    val sortIndex: Int = 1,69    val sortReverse: Boolean = false,70    val downloaded: Int = 0,71    val unread: Int = 0,72    val bookmarked: Int = 0,73    val filler: Int = 0,74)7576@Serializable77enum class DbGroupUpdateMode { Global, CurrentGroup, CurrentExceptUngrouped }7879@Serializable80data class DbLibraryExtraFilters(81    /** Off = absent; 1 = include any selected provider, 2 = exclude every selected provider. */82    val providerTracking: Map<Int, Int> = emptyMap(),83    val customInterval: Int = 0,84)8586@Serializable87enum class DbLibraryGrouping { Categories, Source, Status, TrackerStatus, Tags, Ungrouped }8889@Serializable90data class DbCategoryLibraryPreferences(91    val sort: DbSortLibraryManga? = null,92    val display: DbCategoryLibraryDisplay? = null,93)9495/** Tabs and library-wide counts remain global; these options affect cards in one category. */96@Serializable97data class DbCategoryLibraryDisplay(98    val displayType: DbDisplayType = DbDisplayType.ComfortableGrid,99    val gridSize: Int = 0,100    val downloadBadges: Boolean = true,101    val language: Boolean = false,102    val source: Boolean = false,103    val localBadge: Boolean = true,104    val continueButton: Boolean = true,105)106

Search chapters, reference and source filenames.