DbFeaturePreferences.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/database/DbFeaturePreferences.kt
1package eu.friedcutlet.yokan.database23import kotlinx.serialization.ExperimentalSerializationApi4import kotlinx.serialization.Serializable5import kotlinx.serialization.json.JsonElement6import kotlinx.serialization.json.JsonObject7import kotlinx.serialization.json.JsonTransformingSerializer89/** Group new feature settings: DbSettings is already at the JVM method-parameter limit. */10@Serializable11data class DbFeaturePreferences(12 val home: DbHomePreferences = DbHomePreferences(),13 val downloads: DbDownloadPolicy = DbDownloadPolicy(),14 val imageDataSaver: DbImageDataSaver = DbImageDataSaver(),15 val externalDownloads: DbExternalDownloads = DbExternalDownloads(),16 val library: DbLibraryPreferences = DbLibraryPreferences(),17 val activity: DbActivityPreferences = DbActivityPreferences(),18 val tracking: DbTrackingPreferences = DbTrackingPreferences(),19 val browse: DbBrowsePreferences = DbBrowsePreferences(),20 val syncTriggers: DbSyncTriggerPreferences = DbSyncTriggerPreferences(),21 val player: DbPlayerPreferences = DbPlayerPreferences(),22 val reader: DbReaderPreferences = DbReaderPreferences(),23 val discord: DbDiscordPreferences = DbDiscordPreferences(),24 val privacy: DbPrivacyPreferences = DbPrivacyPreferences(),25 val torrent: DbTorrentPreferences = DbTorrentPreferences(),26)2728@Serializable29data class DbTrackingPreferences(30 /** Opt-in: bind logged-in trackers whose search has exactly one same-title result when a title is added to the library. */31 val autoBindOnAdd: Boolean = false,32)3334/** Read prerelease Home-only settings without losing their layout or installation-local token. */35@OptIn(ExperimentalSerializationApi::class)36class DbFeaturePreferencesSerializer : JsonTransformingSerializer<DbFeaturePreferences>(DbFeaturePreferences.serializer()) {37 private val legacyHomeKeys = DbHomePreferences.serializer().descriptor.let { descriptor ->38 (0 until descriptor.elementsCount).mapTo(mutableSetOf()) { descriptor.getElementName(it) }39 }40 override fun transformDeserialize(element: JsonElement): JsonElement {41 val obj = element as? JsonObject ?: return element42 return if ("home" !in obj && obj.keys.any(legacyHomeKeys::contains)) JsonObject(mapOf("home" to obj)) else obj43 }44}4546@Serializable47data class DbDownloadPolicy(48 val splitTallImages: Boolean = false,49 val splitImageHeight: Int = 4096,50 val autoDownloadNew: Boolean = false,51 val includeCategoryIds: Set<Long> = emptySet(),52 val excludeCategoryIds: Set<Long> = emptySet(),53 val unreadOnly: Boolean = true,54 val includeFiller: Boolean = false,55 val aheadManga: Int = 0,56 val aheadAnime: Int = 0,57 val aheadNovel: Int = 0,58 val cleanupAfterConsumption: Boolean = false,59 val cleanupAfterManualMark: Boolean = false,60 val keepLastConsumed: Int = 0,61 val protectBookmarks: Boolean = true,62 val cleanupExcludedCategoryIds: Set<Long> = emptySet(),63 /** Durable handoff from a library-update transaction to the persisted download queue. */64 val pendingNewChapterIds: Set<Long> = emptySet(),65 /** Consumption provenance keeps automatic cleanup separate from manually marking read. */66 val consumedChapterIds: Set<Long> = emptySet(),67 val manuallyMarkedChapterIds: Set<Long> = emptySet(),68) {69 fun ahead(type: DbItemType): Int = when (type) {70 DbItemType.Manga -> aheadManga71 DbItemType.Anime -> aheadAnime72 DbItemType.Novel -> aheadNovel73 }.coerceIn(0, 100)74}75