mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Use Set for ids
This commit is contained in:
parent
529ffab5bc
commit
dc582e852b
3 changed files with 18 additions and 16 deletions
|
@ -32,7 +32,7 @@ object DownloadButtonSetup {
|
|||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
VideoDownloadManager.deleteFilesAndUpdateSettings(
|
||||
ctx,
|
||||
listOf(id),
|
||||
setOf(id),
|
||||
MainScope()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ class DownloadViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun removeItems(idsToRemove: List<Int>) = viewModelScope.launchSafe {
|
||||
private fun removeItems(idsToRemove: Set<Int>) = viewModelScope.launchSafe {
|
||||
val updatedHeaders = headerCards.value.orEmpty().filter { it.data.id !in idsToRemove }
|
||||
val updatedChildren = childCards.value.orEmpty().filter { it.data.id !in idsToRemove }
|
||||
_headerCards.postValue(updatedHeaders)
|
||||
|
@ -274,10 +274,12 @@ class DownloadViewModel : ViewModel() {
|
|||
context: Context,
|
||||
selectedItemsList: List<VisualDownloadCached>
|
||||
): DeleteData {
|
||||
val ids = mutableListOf<Int>()
|
||||
val parentIds = mutableListOf<Int>()
|
||||
val seriesNames = mutableListOf<String>()
|
||||
val names = mutableListOf<String>()
|
||||
val seriesNames = mutableListOf<String>()
|
||||
|
||||
val ids = mutableSetOf<Int>()
|
||||
val parentIds = mutableSetOf<Int>()
|
||||
|
||||
var parentName: String? = null
|
||||
|
||||
selectedItemsList.forEach { item ->
|
||||
|
@ -368,8 +370,8 @@ class DownloadViewModel : ViewModel() {
|
|||
private fun showDeleteConfirmationDialog(
|
||||
context: Context,
|
||||
message: String,
|
||||
ids: List<Int>,
|
||||
parentIds: List<Int>
|
||||
ids: Set<Int>,
|
||||
parentIds: Set<Int>
|
||||
) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
val dialogClickListener =
|
||||
|
@ -424,8 +426,8 @@ class DownloadViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private data class DeleteData(
|
||||
val ids: List<Int>,
|
||||
val parentIds: List<Int>,
|
||||
val ids: Set<Int>,
|
||||
val parentIds: Set<Int>,
|
||||
val seriesNames: List<String>,
|
||||
val names: List<String>,
|
||||
val parentName: String?
|
||||
|
|
|
@ -1740,9 +1740,9 @@ object VideoDownloadManager {
|
|||
|
||||
fun deleteFilesAndUpdateSettings(
|
||||
context: Context,
|
||||
ids: List<Int>,
|
||||
ids: Set<Int>,
|
||||
scope: CoroutineScope,
|
||||
onComplete: (List<Int>) -> Unit = {}
|
||||
onComplete: (Set<Int>) -> Unit = {}
|
||||
) {
|
||||
scope.launchSafe(Dispatchers.IO) {
|
||||
val deleteJobs = ids.map { id ->
|
||||
|
@ -1752,11 +1752,11 @@ object VideoDownloadManager {
|
|||
}
|
||||
val results = deleteJobs.awaitAll()
|
||||
|
||||
val successfulDeletes = results.filter { it.second }.map { it.first }
|
||||
val failedDeletes = results.filterNot { it.second }
|
||||
val (successfulResults, failedResults) = results.partition { it.second }
|
||||
val successfulIds = successfulResults.map { it.first }.toSet()
|
||||
|
||||
if (failedDeletes.isNotEmpty()) {
|
||||
failedDeletes.forEach { (id, _) ->
|
||||
if (failedResults.isNotEmpty()) {
|
||||
failedResults.forEach { (id, _) ->
|
||||
// TODO show a toast if some failed?
|
||||
Log.e("FileDeletion", "Failed to delete file with ID: $id")
|
||||
}
|
||||
|
@ -1764,7 +1764,7 @@ object VideoDownloadManager {
|
|||
Log.i("FileDeletion", "All files deleted successfully")
|
||||
}
|
||||
|
||||
onComplete.invoke(successfulDeletes)
|
||||
onComplete.invoke(successfulIds)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue