From bdd1a3f25a80b10e2a1f938cf66e60e204968c24 Mon Sep 17 00:00:00 2001 From: d4rk7355608 Date: Tue, 9 Jul 2024 11:34:50 +0300 Subject: [PATCH] Added the cleaning functionality --- .../com/d4rk/cleaner/ui/home/HomeViewModel.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt b/app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt index 4a9ff2c..afb96e1 100644 --- a/app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt +++ b/app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt @@ -162,7 +162,22 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) { return } - // TODO: Implement your cleaning logic here + viewModelScope.launch(Dispatchers.IO) { + val filesToDelete = fileSelectionStates.filter { it.value }.keys + filesToDelete.forEach { file -> + if (file.exists()) { + file.deleteRecursively() + } + } + + withContext(Dispatchers.Main) { + scannedFiles.value = scannedFiles.value?.filterNot { filesToDelete.contains(it) } + fileSelectionStates.clear() + selectAllFiles(false) + _selectedFileCount.value = 0 + updateStorageInfo() + } + } } /**