From d3c418bacc3e06399cfeafa73076423acf81f4fc Mon Sep 17 00:00:00 2001 From: Syer10 Date: Sat, 16 Sep 2023 13:04:30 -0400 Subject: [PATCH] Add new downloader settings --- .../tachidesk/launcher/LauncherViewModel.kt | 2 ++ .../tachidesk/launcher/config/ServerConfig.kt | 2 ++ .../tachidesk/launcher/ui/Downloader.kt | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/kotlin/suwayomi/tachidesk/launcher/LauncherViewModel.kt b/src/main/kotlin/suwayomi/tachidesk/launcher/LauncherViewModel.kt index f072399..20f1087 100644 --- a/src/main/kotlin/suwayomi/tachidesk/launcher/LauncherViewModel.kt +++ b/src/main/kotlin/suwayomi/tachidesk/launcher/LauncherViewModel.kt @@ -69,6 +69,8 @@ class LauncherViewModel { val downloadAsCbz = config.asStateFlow { it.downloadAsCbz } val downloadsPath = config.asStateFlow { it.downloadsPath } val autoDownloadNewChapters = config.asStateFlow { it.autoDownloadNewChapters } + val excludeEntryWithUnreadChapters = config.asStateFlow { it.excludeEntryWithUnreadChapters } + val autoDownloadAheadLimit = config.asStateFlow { it.autoDownloadAheadLimit } // Updater val excludeUnreadChapters = config.asStateFlow { it.excludeUnreadChapters } diff --git a/src/main/kotlin/suwayomi/tachidesk/launcher/config/ServerConfig.kt b/src/main/kotlin/suwayomi/tachidesk/launcher/config/ServerConfig.kt index 7c11639..d75b249 100644 --- a/src/main/kotlin/suwayomi/tachidesk/launcher/config/ServerConfig.kt +++ b/src/main/kotlin/suwayomi/tachidesk/launcher/config/ServerConfig.kt @@ -69,6 +69,8 @@ class ServerConfig( val downloadAsCbz: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) val downloadsPath: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) val autoDownloadNewChapters: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) + val excludeEntryWithUnreadChapters: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) + val autoDownloadAheadLimit: MutableStateFlow by OverrideConfigValue(IntConfigAdapter) // updater val excludeUnreadChapters: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) diff --git a/src/main/kotlin/suwayomi/tachidesk/launcher/ui/Downloader.kt b/src/main/kotlin/suwayomi/tachidesk/launcher/ui/Downloader.kt index 0670bf9..5f75e1a 100644 --- a/src/main/kotlin/suwayomi/tachidesk/launcher/ui/Downloader.kt +++ b/src/main/kotlin/suwayomi/tachidesk/launcher/ui/Downloader.kt @@ -22,13 +22,16 @@ import suwayomi.tachidesk.launcher.KeyListenerEvent import suwayomi.tachidesk.launcher.LauncherViewModel import suwayomi.tachidesk.launcher.actions import suwayomi.tachidesk.launcher.bind +import suwayomi.tachidesk.launcher.changes import suwayomi.tachidesk.launcher.jCheckBox +import suwayomi.tachidesk.launcher.jSpinner import suwayomi.tachidesk.launcher.jTextArea import suwayomi.tachidesk.launcher.jTextField import suwayomi.tachidesk.launcher.jbutton import suwayomi.tachidesk.launcher.jpanel import suwayomi.tachidesk.launcher.keyListener import javax.swing.JFileChooser +import javax.swing.SpinnerNumberModel import javax.swing.UIManager import kotlin.io.path.Path import kotlin.io.path.createDirectories @@ -97,4 +100,27 @@ fun Downloader(vm: LauncherViewModel, scope: CoroutineScope) = jpanel( .flowOn(Dispatchers.Default) .launchIn(scope) }.bind(CC().wrap()) + + jCheckBox("Exclude unread entries", selected = vm.excludeEntryWithUnreadChapters.value) { + toolTipText = "Ignore automatic chapter downloads of entries with unread chapters." // todo improve + actions() + .onEach { + vm.excludeEntryWithUnreadChapters.value = isSelected + } + .flowOn(Dispatchers.Default) + .launchIn(scope) + }.bind(CC().wrap()) + + jTextArea("Download ahead limit") { + isEditable = false + }.bind() + jSpinner(SpinnerNumberModel(vm.autoDownloadAheadLimit.value.coerceAtLeast(0), 0, Int.MAX_VALUE, 1)) { + toolTipText = "0 to disable it - How many unread downloaded chapters should be available - If the limit is reached, new chapters won't be downloaded automatically" + changes() + .onEach { + vm.autoDownloadAheadLimit.value = (value as Int) + } + .flowOn(Dispatchers.Default) + .launchIn(scope) + }.bind(CC().grow().spanX().wrap()) }