Skip to content

Commit 08b419e

Browse files
Improved the scanning process and added a progress bar
1 parent 7a37011 commit 08b419e

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434
"sv",
3535
"bg",
3636
"pl",
37-
"uk"
37+
"uk",
3838
)
3939
vectorDrawables {
4040
useSupportLibrary = true

app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeComposable.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.material3.ButtonDefaults
3636
import androidx.compose.material3.Card
3737
import androidx.compose.material3.CardDefaults
3838
import androidx.compose.material3.Checkbox
39+
import androidx.compose.material3.CircularProgressIndicator
3940
import androidx.compose.material3.FilledTonalButton
4041
import androidx.compose.material3.FilterChip
4142
import androidx.compose.material3.Icon
@@ -242,7 +243,7 @@ fun HomeComposable() {
242243
fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>, imageLoader: ImageLoader) {
243244
val viewModel: HomeViewModel = viewModel()
244245
val files by viewModel.scannedFiles.asFlow().collectAsState(initial = listOf())
245-
246+
val isAnalyzing by viewModel.isAnalyzing.observeAsState(false)
246247
val allFilesSelected by viewModel.allFilesSelected
247248
val selectedFileCount by viewModel.selectedFileCount.collectAsState()
248249

@@ -267,14 +268,20 @@ fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>, imageLoader: Ima
267268
.weight(1f)
268269
.fillMaxWidth(),
269270
) {
270-
LazyVerticalGrid(
271-
columns = GridCells.Fixed(3),
272-
verticalArrangement = Arrangement.spacedBy(8.dp),
273-
horizontalArrangement = Arrangement.spacedBy(8.dp),
274-
modifier = Modifier.padding(8.dp),
275-
) {
276-
items(files, key = { file -> file.absolutePath }) { file ->
277-
FileCard(file = file, viewModel = viewModel, imageLoader = imageLoader)
271+
if (isAnalyzing && files.isEmpty()) {
272+
Box (modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
273+
CircularProgressIndicator()
274+
}
275+
} else {
276+
LazyVerticalGrid(
277+
columns = GridCells.Fixed(3),
278+
verticalArrangement = Arrangement.spacedBy(8.dp),
279+
horizontalArrangement = Arrangement.spacedBy(8.dp),
280+
modifier = Modifier.padding(8.dp),
281+
) {
282+
items(files, key = { file -> file.absolutePath }) { file ->
283+
FileCard(file = file, viewModel = viewModel, imageLoader = imageLoader)
284+
}
278285
}
279286
}
280287
}

app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
127127
isAnalyzing.value = true
128128
showCleaningComposable.value = true
129129
viewModelScope.launch {
130-
fileScanner.startScanning()
131-
withContext(Dispatchers.Main) {
132-
scannedFiles.value = fileScanner.getFilteredFiles()
133-
isAnalyzing.value = false
134-
hasScanned.value = true
130+
withContext(Dispatchers.IO) {
131+
fileScanner.startScanning()
132+
withContext(Dispatchers.Main) {
133+
scannedFiles.value = fileScanner.getFilteredFiles()
134+
isAnalyzing.value = false
135+
hasScanned.value = true
136+
}
135137
}
136138
}
137139
}

0 commit comments

Comments
 (0)