Skip to content

Commit e4d62eb

Browse files
Added rescan dialog
1 parent e119ab6 commit e4d62eb

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.d4rk.cleaner.ui.dialogs
2+
3+
import androidx.compose.material3.AlertDialog
4+
import androidx.compose.material3.Text
5+
import androidx.compose.material3.TextButton
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.res.stringResource
8+
9+
10+
@Composable
11+
fun RescanAlertDialog(
12+
onYes: () -> Unit,
13+
onDismiss: () -> Unit
14+
) {
15+
AlertDialog(
16+
onDismissRequest = onDismiss,
17+
title = { Text("Rescan?") },
18+
text = { Text("Are you sure you want to scan again?") },
19+
confirmButton = {
20+
TextButton(onClick = onYes) {
21+
Text(stringResource(android.R.string.ok))
22+
}
23+
},
24+
dismissButton = {
25+
TextButton(onClick = onDismiss) {
26+
Text(stringResource(android.R.string.cancel))
27+
}
28+
}
29+
)
30+
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import coil.disk.DiskCache
6868
import coil.memory.MemoryCache
6969
import coil.request.ImageRequest
7070
import com.d4rk.cleaner.R
71+
import com.d4rk.cleaner.ui.dialogs.RescanAlertDialog
7172
import com.d4rk.cleaner.utils.CircularDeterminateIndicator
7273
import com.d4rk.cleaner.utils.bounceClick
7374
import com.d4rk.cleaner.utils.getFileIcon
@@ -102,6 +103,18 @@ fun HomeComposable() {
102103

103104
val launchScanningKey = remember { mutableStateOf(false) }
104105

106+
if (viewModel.showRescanDialog.value) {
107+
RescanAlertDialog(
108+
onYes = {
109+
viewModel.rescan(
110+
context as Activity
111+
)
112+
viewModel.showRescanDialog.value = false
113+
},
114+
onDismiss = { viewModel.showRescanDialog.value = false }
115+
)
116+
}
117+
105118
Column(
106119
modifier = Modifier.fillMaxSize()
107120
) {
@@ -195,9 +208,7 @@ fun HomeComposable() {
195208
.animateContentSize()
196209
.padding(start = if (showCleaningComposable) 8.dp else 16.dp, end = 16.dp)
197210
.bounceClick(), onClick = {
198-
if (!showCleaningComposable) {
199-
viewModel.analyze(activity = context as Activity)
200-
}
211+
viewModel.analyze(activity = context as Activity)
201212
}, shape = MaterialTheme.shapes.medium
202213
) {
203214
Column(

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
4343
private val dataStoreInstance: DataStore = DataStore(application)
4444
val showCleaningComposable = MutableLiveData(false)
4545
val isAnalyzing = MutableLiveData(false)
46+
var showRescanDialog = mutableStateOf(false)
47+
private var hasScanned = mutableStateOf(false)
48+
private var isUserConfirmedRescan = mutableStateOf(false)
4649
val _selectedFileCount = MutableStateFlow(0)
4750
val selectedFileCount: StateFlow<Int> = _selectedFileCount.asStateFlow()
4851

@@ -124,17 +127,30 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
124127
requestPermissions(activity)
125128
return
126129
}
130+
131+
if (hasScanned.value && !isUserConfirmedRescan.value) {
132+
showRescanDialog.value = true
133+
}
134+
135+
isUserConfirmedRescan.value = false
127136
isAnalyzing.value = true
128137
showCleaningComposable.value = true
129138
viewModelScope.launch {
130139
fileScanner.startScanning()
131140
withContext(Dispatchers.Main) {
132141
scannedFiles.value = fileScanner.getFilteredFiles()
133-
isAnalyzing.value =false
142+
isAnalyzing.value = false
143+
hasScanned.value = true
134144
}
135145
}
136146
}
137147

148+
fun rescan(activity: Activity) {
149+
showRescanDialog.value = false
150+
scannedFiles.value = emptyList()
151+
analyze(activity)
152+
}
153+
138154
/**
139155
* Initiates the cleaning process if the required permissions are granted.
140156
*

0 commit comments

Comments
 (0)