From 494abe905bea3c8fcb23f0a620eb9b4c6c3f612c Mon Sep 17 00:00:00 2001 From: Mihai-Cristian Condrea Date: Sun, 3 Nov 2024 10:47:36 +0200 Subject: [PATCH] A fix --- .../cleaner/ui/screens/home/HomeViewModel.kt | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/d4rk/cleaner/ui/screens/home/HomeViewModel.kt b/app/src/main/kotlin/com/d4rk/cleaner/ui/screens/home/HomeViewModel.kt index 58c3564..f44faeb 100644 --- a/app/src/main/kotlin/com/d4rk/cleaner/ui/screens/home/HomeViewModel.kt +++ b/app/src/main/kotlin/com/d4rk/cleaner/ui/screens/home/HomeViewModel.kt @@ -151,10 +151,21 @@ class HomeViewModel(application : Application) : BaseViewModel(application) { fileSelectionMap = updatedFileSelectionStates , selectedFilesCount = newSelectedCount , areAllFilesSelected = when { - newSelectedCount == currentUiState.analyzeState.scannedFileList.size && newSelectedCount > 0 -> true - newSelectedCount == 0 -> false - isChecked -> currentUiState.analyzeState.areAllFilesSelected - else -> false + newSelectedCount == currentUiState.analyzeState.scannedFileList.size && newSelectedCount > 0 -> { + true + } + + newSelectedCount == 0 -> { + false + } + + isChecked -> { + currentUiState.analyzeState.areAllFilesSelected + } + + else -> { + false + } } ) ) @@ -170,14 +181,17 @@ class HomeViewModel(application : Application) : BaseViewModel(application) { val newState = ! _uiState.value.analyzeState.areAllFilesSelected _uiState.update { currentUiState -> currentUiState.copy(analyzeState = currentUiState.analyzeState.copy(areAllFilesSelected = newState , - fileSelectionMap = if (newState) { - currentUiState.analyzeState.scannedFileList.associateWith { true } - } - else { - emptyMap() + fileSelectionMap = when { + newState -> { + (currentUiState.analyzeState.scannedFileList + currentUiState.analyzeState.emptyFolderList).associateWith { true } + } + + else -> { + emptyMap() + } } , selectedFilesCount = if (newState) { - currentUiState.analyzeState.scannedFileList.size + (currentUiState.analyzeState.scannedFileList.size + currentUiState.analyzeState.emptyFolderList.size) } else { 0