@@ -61,6 +61,7 @@ import androidx.compose.runtime.collectAsState
61
61
import androidx.compose.runtime.getValue
62
62
import androidx.compose.runtime.mutableStateOf
63
63
import androidx.compose.runtime.remember
64
+ import androidx.compose.runtime.rememberCoroutineScope
64
65
import androidx.compose.runtime.setValue
65
66
import androidx.compose.ui.Alignment
66
67
import androidx.compose.ui.Modifier
@@ -85,8 +86,12 @@ import dev.zwander.installwithoptions.util.ElevatedPermissionHandler
85
86
import dev.zwander.installwithoptions.util.handleIncomingUris
86
87
import dev.zwander.installwithoptions.util.plus
87
88
import dev.zwander.installwithoptions.util.rememberPackageInstaller
89
+ import kotlinx.coroutines.CoroutineScope
90
+ import kotlinx.coroutines.Dispatchers
91
+ import kotlinx.coroutines.MainScope
92
+ import kotlinx.coroutines.launch
88
93
89
- class MainActivity : AppCompatActivity () {
94
+ class MainActivity : AppCompatActivity (), CoroutineScope by MainScope() {
90
95
private val permissionHandler by lazy {
91
96
ElevatedPermissionHandler (
92
97
context = this ,
@@ -132,24 +137,31 @@ class MainActivity : AppCompatActivity() {
132
137
133
138
private fun checkIntentForPackage (intent : Intent ) {
134
139
intent.data?.let {
135
- handleIncomingUris(listOf (it))
140
+ launch(Dispatchers .IO ) {
141
+ handleIncomingUris(listOf (it))
142
+ }
136
143
}
137
144
}
138
145
}
139
146
140
147
@OptIn(ExperimentalFoundationApi ::class )
141
148
@Composable
142
149
fun MainContent (modifier : Modifier = Modifier ) {
150
+ val scope = rememberCoroutineScope()
151
+
143
152
var selectedFiles by DataModel .selectedFiles.collectAsMutableState()
144
153
var showingSelectedFiles by remember {
145
154
mutableStateOf(false )
146
155
}
147
156
var selectedOptions by DataModel .selectedOptions.collectAsMutableState()
157
+ val isImporting by DataModel .isImporting.collectAsState()
148
158
149
159
val context = LocalContext .current
150
160
val fileSelector =
151
161
rememberLauncherForActivityResult(contract = ActivityResultContracts .OpenMultipleDocuments ()) { uris ->
152
- context.handleIncomingUris(uris)
162
+ scope.launch(Dispatchers .IO ) {
163
+ context.handleIncomingUris(uris)
164
+ }
153
165
}
154
166
val options = (rememberInstallOptions() + rememberMutableOptions()).sortedBy {
155
167
context.resources.getString(it.labelResource)
@@ -324,6 +336,32 @@ fun MainContent(modifier: Modifier = Modifier) {
324
336
}
325
337
}
326
338
}
339
+
340
+ AnimatedVisibility (
341
+ visible = isImporting,
342
+ modifier = Modifier .fillMaxSize(),
343
+ enter = fadeIn(),
344
+ exit = fadeOut(),
345
+ ) {
346
+ Box (
347
+ modifier = Modifier
348
+ .fillMaxSize()
349
+ .background(Color .Black .copy(alpha = 0.5f ))
350
+ .clickable(
351
+ interactionSource = remember {
352
+ MutableInteractionSource ()
353
+ },
354
+ indication = null ,
355
+ enabled = true ,
356
+ onClick = {},
357
+ ),
358
+ contentAlignment = Alignment .Center ,
359
+ ) {
360
+ CircularProgressIndicator (
361
+ color = Color .White ,
362
+ )
363
+ }
364
+ }
327
365
}
328
366
329
367
if (showingSelectedFiles) {
@@ -344,7 +382,8 @@ fun MainContent(modifier: Modifier = Modifier) {
344
382
selectedFiles.forEach { (pkg, files) ->
345
383
stickyHeader {
346
384
Row (
347
- modifier = Modifier .fillMaxWidth()
385
+ modifier = Modifier
386
+ .fillMaxWidth()
348
387
.background(color = MaterialTheme .colorScheme.surfaceContainerHigh),
349
388
horizontalArrangement = Arrangement .SpaceBetween ,
350
389
verticalAlignment = Alignment .CenterVertically ,
@@ -370,7 +409,8 @@ fun MainContent(modifier: Modifier = Modifier) {
370
409
371
410
items(items = files) {
372
411
Row (
373
- modifier = Modifier .fillMaxWidth()
412
+ modifier = Modifier
413
+ .fillMaxWidth()
374
414
.background(color = MaterialTheme .colorScheme.surfaceContainerHigh),
375
415
horizontalArrangement = Arrangement .SpaceBetween ,
376
416
verticalAlignment = Alignment .CenterVertically ,
0 commit comments