Skip to content

Commit

Permalink
Improved the scanning process and added a progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
D4rK7355608 committed Jul 10, 2024
1 parent 7a37011 commit 08b419e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
"sv",
"bg",
"pl",
"uk"
"uk",
)
vectorDrawables {
useSupportLibrary = true
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -242,7 +243,7 @@ fun HomeComposable() {
fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>, imageLoader: ImageLoader) {
val viewModel: HomeViewModel = viewModel()
val files by viewModel.scannedFiles.asFlow().collectAsState(initial = listOf())

val isAnalyzing by viewModel.isAnalyzing.observeAsState(false)
val allFilesSelected by viewModel.allFilesSelected
val selectedFileCount by viewModel.selectedFileCount.collectAsState()

Expand All @@ -267,14 +268,20 @@ fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>, imageLoader: Ima
.weight(1f)
.fillMaxWidth(),
) {
LazyVerticalGrid(
columns = GridCells.Fixed(3),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(8.dp),
) {
items(files, key = { file -> file.absolutePath }) { file ->
FileCard(file = file, viewModel = viewModel, imageLoader = imageLoader)
if (isAnalyzing && files.isEmpty()) {
Box (modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
} else {
LazyVerticalGrid(
columns = GridCells.Fixed(3),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(8.dp),
) {
items(files, key = { file -> file.absolutePath }) { file ->
FileCard(file = file, viewModel = viewModel, imageLoader = imageLoader)
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
isAnalyzing.value = true
showCleaningComposable.value = true
viewModelScope.launch {
fileScanner.startScanning()
withContext(Dispatchers.Main) {
scannedFiles.value = fileScanner.getFilteredFiles()
isAnalyzing.value = false
hasScanned.value = true
withContext(Dispatchers.IO) {
fileScanner.startScanning()
withContext(Dispatchers.Main) {
scannedFiles.value = fileScanner.getFilteredFiles()
isAnalyzing.value = false
hasScanned.value = true
}
}
}
}
Expand Down

0 comments on commit 08b419e

Please sign in to comment.