Skip to content

Commit ba9aa66

Browse files
committed
feat: add filtering files being downloaded [#66]
1 parent 15227fa commit ba9aa66

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fun FileItemViewPreviewDownloading() {
178178
listOf(),
179179
listOf(
180180
DownloadingState(
181-
fileEntry.path,
181+
fileEntry.path, fileEntry.filename,
182182
50, 100
183183
)
184184
),

iosVariant/iosVariant/Views/Servers/FileItemView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ struct FileItemView: View {
118118
DownloadingState(
119119
path: DIRECTORY_LIST.filter { $0.isDirectory == false }.first!
120120
.path,
121+
filename: DIRECTORY_LIST.filter { $0.isDirectory == false }
122+
.first!
123+
.path,
121124
received: 50,
122125
total: 100
123126
)

shared/src/commonMain/kotlin/org/comixedproject/variant/model/state/DownloadingState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package org.comixedproject.variant.model.state
2020

2121
data class DownloadingState(
2222
val path: String,
23+
val filename: String,
2324
var received: Long,
2425
var total: Long
2526
)

shared/src/commonMain/kotlin/org/comixedproject/variant/viewmodel/VariantViewModel.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ open class VariantViewModel(
197197
val password = this.password
198198

199199
viewModelScope.launch(Dispatchers.Main) {
200-
val downloadingState = DownloadingState(path, 0, 0)
200+
val downloadingState = DownloadingState(path, filename, 0, 0)
201201
val state = mutableListOf<DownloadingState>()
202202
state.addAll(_browsingState.value.downloadingState)
203203
state.add(downloadingState)
@@ -217,7 +217,7 @@ open class VariantViewModel(
217217
output,
218218
onProgress = { received, total ->
219219
viewModelScope.launch(Dispatchers.Main) {
220-
val downloadingState = DownloadingState(path, received, total)
220+
val downloadingState = DownloadingState(path, filename, received, total)
221221
val state =
222222
_browsingState.value.downloadingState.filter { !(it.path == path) }
223223
.toMutableList()
@@ -259,8 +259,16 @@ open class VariantViewModel(
259259
Log.debug(TAG, "Loading library contents: ${_libraryDirectory}")
260260

261261
val path = File(_libraryDirectory)
262+
val ignored = this._browsingState.value.downloadingState.map { it.filename }.toList()
262263
val contents =
263264
path.directoryFiles()
265+
.filter {
266+
if (!ignored.contains(it.name)) {
267+
true
268+
} else {
269+
false
270+
}
271+
}
264272
.filter { !it.isDirectory }
265273
.filter { it.size.toLong() > 0L }
266274
.filter { it.extension.equals("cbz") || it.extension.equals("cbr") }

0 commit comments

Comments
 (0)