@@ -10,19 +10,15 @@ import androidx.compose.animation.fadeOut
10
10
import androidx.compose.animation.slideInVertically
11
11
import androidx.compose.animation.slideOutVertically
12
12
import androidx.compose.foundation.background
13
- import androidx.compose.foundation.focusable
14
13
import androidx.compose.foundation.layout.Box
15
14
import androidx.compose.foundation.layout.Column
16
15
import androidx.compose.foundation.layout.Spacer
17
16
import androidx.compose.foundation.layout.fillMaxSize
18
17
import androidx.compose.foundation.layout.padding
19
18
import androidx.compose.foundation.shape.CircleShape
20
- import androidx.compose.foundation.text.KeyboardActions
21
- import androidx.compose.foundation.text.KeyboardOptions
22
19
import androidx.compose.material.icons.Icons
23
20
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
24
21
import androidx.compose.material.icons.automirrored.rounded.ArrowForward
25
- import androidx.compose.material.icons.rounded.Clear
26
22
import androidx.compose.material.icons.rounded.ContentCopy
27
23
import androidx.compose.material.icons.rounded.Edit
28
24
import androidx.compose.material.icons.rounded.GridOff
@@ -31,7 +27,6 @@ import androidx.compose.material.icons.rounded.MoreVert
31
27
import androidx.compose.material.icons.rounded.Palette
32
28
import androidx.compose.material.icons.rounded.Refresh
33
29
import androidx.compose.material.icons.rounded.Save
34
- import androidx.compose.material3.AlertDialog
35
30
import androidx.compose.material3.BottomAppBar
36
31
import androidx.compose.material3.CenterAlignedTopAppBar
37
32
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -41,8 +36,6 @@ import androidx.compose.material3.MaterialTheme
41
36
import androidx.compose.material3.MaterialTheme.colorScheme
42
37
import androidx.compose.material3.Scaffold
43
38
import androidx.compose.material3.Text
44
- import androidx.compose.material3.TextButton
45
- import androidx.compose.material3.TextField
46
39
import androidx.compose.material3.surfaceColorAtElevation
47
40
import androidx.compose.runtime.Composable
48
41
import androidx.compose.runtime.LaunchedEffect
@@ -60,24 +53,18 @@ import androidx.compose.ui.graphics.asAndroidBitmap
60
53
import androidx.compose.ui.platform.LocalContext
61
54
import androidx.compose.ui.res.stringResource
62
55
import androidx.compose.ui.text.font.FontWeight
63
- import androidx.compose.ui.text.input.ImeAction
64
- import androidx.compose.ui.text.input.KeyboardCapitalization
65
- import androidx.compose.ui.text.input.KeyboardType
66
- import androidx.compose.ui.text.intl.LocaleList
67
56
import androidx.compose.ui.text.style.TextOverflow
68
57
import androidx.compose.ui.unit.dp
69
58
import com.dede.android_eggs.cat_editor.CaptureControllerDelegate.Companion.rememberCaptureControllerDelegate
70
59
import com.dede.android_eggs.cat_editor.CatEditorRecords.Companion.rememberCatEditorRecords
71
60
import com.dede.android_eggs.navigation.EasterEggsDestination
72
61
import com.dede.android_eggs.navigation.LocalNavController
73
- import com.dede.android_eggs.ui.composes.icons.rounded.Cat
74
62
import com.dede.basic.copy
75
63
import com.dede.basic.toast
76
64
import com.dede.basic.utils.ShareCatUtils
77
65
import com.google.accompanist.permissions.ExperimentalPermissionsApi
78
66
import kotlinx.coroutines.launch
79
67
import androidx.appcompat.R as AppCompatR
80
- import com.dede.android_eggs.resources.R as StringR
81
68
82
69
object CatEditorScreen : EasterEggsDestination {
83
70
override val route: String = " cat_editor"
@@ -109,8 +96,6 @@ fun CatEditorScreen() {
109
96
}
110
97
111
98
var moreOptionsVisible by remember { mutableStateOf(false ) }
112
- var inputSeedDialog by remember { mutableStateOf(false ) }
113
- var inputSeedText by remember { mutableStateOf(" " ) }
114
99
115
100
Scaffold (
116
101
topBar = {
@@ -290,82 +275,17 @@ fun CatEditorScreen() {
290
275
}
291
276
)
292
277
278
+ val inputSeedDialogState = remember { mutableStateOf(false ) }
279
+
293
280
fun updateCatSeed (seed : Long ) {
294
281
catSeed = seed
295
282
catEditorController.updateColors(catSeed)
296
283
catEditorRecords.addRecord(CatEditorRecords .seed(catSeed))
297
284
}
298
285
299
- if (inputSeedDialog) {
300
-
301
- fun onInputDone () {
302
- if (inputSeedText.isBlank()) {
303
- return
304
- }
305
- val seed = Utilities .string2Seed(inputSeedText)
306
- updateCatSeed(seed)
307
- }
308
-
309
- AlertDialog (
310
- onDismissRequest = {
311
- inputSeedDialog = false
312
- },
313
- title = {
314
- Text (text = stringResource(StringR .string.cat_editor))
315
- },
316
- text = {
317
- TextField (
318
- modifier = Modifier .focusable(true ),
319
- value = inputSeedText,
320
- onValueChange = { inputSeedText = it },
321
- placeholder = {
322
- Text (text = " XXX" )
323
- },
324
- leadingIcon = {
325
- Icon (imageVector = Icons .Rounded .Cat , contentDescription = null )
326
- },
327
- trailingIcon = {
328
- IconButton (onClick = {
329
- inputSeedText = " "
330
- }) {
331
- Icon (
332
- imageVector = Icons .Rounded .Clear ,
333
- contentDescription = null
334
- )
335
- }
336
- },
337
- label = { Text (text = stringResource(StringR .string.cat_editor_input_seed)) },
338
- keyboardOptions = KeyboardOptions (
339
- autoCorrectEnabled = false ,
340
- keyboardType = KeyboardType .Text ,
341
- imeAction = ImeAction .Done ,
342
- showKeyboardOnFocus = true ,
343
- hintLocales = LocaleList (" en" ),
344
- capitalization = KeyboardCapitalization .None ,
345
- ),
346
- keyboardActions = KeyboardActions {
347
- onInputDone()
348
- inputSeedDialog = false
349
- }
350
- )
351
- },
352
- dismissButton = {
353
- TextButton (onClick = {
354
- inputSeedDialog = false
355
- }) {
356
- Text (text = stringResource(android.R .string.cancel))
357
- }
358
- },
359
- confirmButton = {
360
- TextButton (onClick = {
361
- onInputDone()
362
- inputSeedDialog = false
363
- }) {
364
- Text (text = stringResource(android.R .string.ok))
365
- }
366
- },
367
- )
368
- }
286
+ CatSeedInputDialog (inputSeedDialogState, onConfirm = { seed ->
287
+ updateCatSeed(seed)
288
+ })
369
289
370
290
AnimatedVisibility (
371
291
visible = moreOptionsVisible,
@@ -391,7 +311,7 @@ fun CatEditorScreen() {
391
311
}
392
312
393
313
IconButton (onClick = {
394
- inputSeedDialog = true
314
+ inputSeedDialogState.value = true
395
315
}) {
396
316
Icon (imageVector = Icons .Rounded .Edit , contentDescription = null )
397
317
}
0 commit comments