Support deleting all episodes in a series

This commit is contained in:
Luna712 2024-07-09 16:32:22 -06:00 committed by GitHub
parent 14d16590a1
commit 7f50f0ca14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -241,7 +241,20 @@ class DownloadViewModel : ViewModel() {
fun handleMultiDelete(context: Context) = viewModelScope.launchSafe { fun handleMultiDelete(context: Context) = viewModelScope.launchSafe {
val selectedItemsList = selectedItems.value ?: mutableListOf() val selectedItemsList = selectedItems.value ?: mutableListOf()
val ids = selectedItemsList.map { it.data.id } val ids = selectedItemsList.flatMap { item ->
when (item) {
is VisualDownloadCached.Header -> {
if (item.data.type.isEpisodeBased()) {
context.getKeys(DOWNLOAD_EPISODE_CACHE)
.mapNotNull { context.getKey<VideoDownloadHelper.DownloadEpisodeCached>(it) }
.filter { it.parentId == item.data.id }
.map { it.id }
} else listOf(item.data.id)
}
is VisualDownloadCached.Child -> listOf(item.data.id)
}
}
val (seriesNames, names) = selectedItemsList.map { item -> val (seriesNames, names) = selectedItemsList.map { item ->
when (item) { when (item) {