From 49abfdbb8136e541553f66d54d54e0bce916130b Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Wed, 9 Jul 2025 13:41:17 -0400 Subject: [PATCH] feat: add filtering files being downloaded [#66] --- .../variant/android/view/server/FileItemView.kt | 2 +- .../iosVariant/Views/Servers/FileItemView.swift | 3 +++ .../variant/model/state/DownloadingState.kt | 1 + .../variant/viewmodel/VariantViewModel.kt | 12 ++++++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt b/androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt index 07823507..f998a026 100644 --- a/androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt +++ b/androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt @@ -178,7 +178,7 @@ fun FileItemViewPreviewDownloading() { listOf(), listOf( DownloadingState( - fileEntry.path, + fileEntry.path, fileEntry.filename, 50, 100 ) ), diff --git a/iosVariant/iosVariant/Views/Servers/FileItemView.swift b/iosVariant/iosVariant/Views/Servers/FileItemView.swift index 5de161a4..372a5a68 100644 --- a/iosVariant/iosVariant/Views/Servers/FileItemView.swift +++ b/iosVariant/iosVariant/Views/Servers/FileItemView.swift @@ -118,6 +118,9 @@ struct FileItemView: View { DownloadingState( path: DIRECTORY_LIST.filter { $0.isDirectory == false }.first! .path, + filename: DIRECTORY_LIST.filter { $0.isDirectory == false } + .first! + .path, received: 50, total: 100 ) diff --git a/shared/src/commonMain/kotlin/org/comixedproject/variant/model/state/DownloadingState.kt b/shared/src/commonMain/kotlin/org/comixedproject/variant/model/state/DownloadingState.kt index 38c35ce4..e786af81 100644 --- a/shared/src/commonMain/kotlin/org/comixedproject/variant/model/state/DownloadingState.kt +++ b/shared/src/commonMain/kotlin/org/comixedproject/variant/model/state/DownloadingState.kt @@ -20,6 +20,7 @@ package org.comixedproject.variant.model.state data class DownloadingState( val path: String, + val filename: String, var received: Long, var total: Long ) diff --git a/shared/src/commonMain/kotlin/org/comixedproject/variant/viewmodel/VariantViewModel.kt b/shared/src/commonMain/kotlin/org/comixedproject/variant/viewmodel/VariantViewModel.kt index dcd48652..30c84172 100644 --- a/shared/src/commonMain/kotlin/org/comixedproject/variant/viewmodel/VariantViewModel.kt +++ b/shared/src/commonMain/kotlin/org/comixedproject/variant/viewmodel/VariantViewModel.kt @@ -197,7 +197,7 @@ open class VariantViewModel( val password = this.password viewModelScope.launch(Dispatchers.Main) { - val downloadingState = DownloadingState(path, 0, 0) + val downloadingState = DownloadingState(path, filename, 0, 0) val state = mutableListOf() state.addAll(_browsingState.value.downloadingState) state.add(downloadingState) @@ -217,7 +217,7 @@ open class VariantViewModel( output, onProgress = { received, total -> viewModelScope.launch(Dispatchers.Main) { - val downloadingState = DownloadingState(path, received, total) + val downloadingState = DownloadingState(path, filename, received, total) val state = _browsingState.value.downloadingState.filter { !(it.path == path) } .toMutableList() @@ -259,8 +259,16 @@ open class VariantViewModel( Log.debug(TAG, "Loading library contents: ${_libraryDirectory}") val path = File(_libraryDirectory) + val ignored = this._browsingState.value.downloadingState.map { it.filename }.toList() val contents = path.directoryFiles() + .filter { + if (!ignored.contains(it.name)) { + true + } else { + false + } + } .filter { !it.isDirectory } .filter { it.size.toLong() > 0L } .filter { it.extension.equals("cbz") || it.extension.equals("cbr") }