@@ -10,19 +10,15 @@ import androidx.compose.animation.fadeOut
1010import androidx.compose.animation.slideInVertically
1111import androidx.compose.animation.slideOutVertically
1212import androidx.compose.foundation.background
13- import androidx.compose.foundation.focusable
1413import androidx.compose.foundation.layout.Box
1514import androidx.compose.foundation.layout.Column
1615import androidx.compose.foundation.layout.Spacer
1716import androidx.compose.foundation.layout.fillMaxSize
1817import androidx.compose.foundation.layout.padding
1918import androidx.compose.foundation.shape.CircleShape
20- import androidx.compose.foundation.text.KeyboardActions
21- import androidx.compose.foundation.text.KeyboardOptions
2219import androidx.compose.material.icons.Icons
2320import androidx.compose.material.icons.automirrored.rounded.ArrowBack
2421import androidx.compose.material.icons.automirrored.rounded.ArrowForward
25- import androidx.compose.material.icons.rounded.Clear
2622import androidx.compose.material.icons.rounded.ContentCopy
2723import androidx.compose.material.icons.rounded.Edit
2824import androidx.compose.material.icons.rounded.GridOff
@@ -31,7 +27,6 @@ import androidx.compose.material.icons.rounded.MoreVert
3127import androidx.compose.material.icons.rounded.Palette
3228import androidx.compose.material.icons.rounded.Refresh
3329import androidx.compose.material.icons.rounded.Save
34- import androidx.compose.material3.AlertDialog
3530import androidx.compose.material3.BottomAppBar
3631import androidx.compose.material3.CenterAlignedTopAppBar
3732import androidx.compose.material3.ExperimentalMaterial3Api
@@ -41,8 +36,6 @@ import androidx.compose.material3.MaterialTheme
4136import androidx.compose.material3.MaterialTheme.colorScheme
4237import androidx.compose.material3.Scaffold
4338import androidx.compose.material3.Text
44- import androidx.compose.material3.TextButton
45- import androidx.compose.material3.TextField
4639import androidx.compose.material3.surfaceColorAtElevation
4740import androidx.compose.runtime.Composable
4841import androidx.compose.runtime.LaunchedEffect
@@ -60,24 +53,18 @@ import androidx.compose.ui.graphics.asAndroidBitmap
6053import androidx.compose.ui.platform.LocalContext
6154import androidx.compose.ui.res.stringResource
6255import 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
6756import androidx.compose.ui.text.style.TextOverflow
6857import androidx.compose.ui.unit.dp
6958import com.dede.android_eggs.cat_editor.CaptureControllerDelegate.Companion.rememberCaptureControllerDelegate
7059import com.dede.android_eggs.cat_editor.CatEditorRecords.Companion.rememberCatEditorRecords
7160import com.dede.android_eggs.navigation.EasterEggsDestination
7261import com.dede.android_eggs.navigation.LocalNavController
73- import com.dede.android_eggs.ui.composes.icons.rounded.Cat
7462import com.dede.basic.copy
7563import com.dede.basic.toast
7664import com.dede.basic.utils.ShareCatUtils
7765import com.google.accompanist.permissions.ExperimentalPermissionsApi
7866import kotlinx.coroutines.launch
7967import androidx.appcompat.R as AppCompatR
80- import com.dede.android_eggs.resources.R as StringR
8168
8269object CatEditorScreen : EasterEggsDestination {
8370 override val route: String = " cat_editor"
@@ -109,8 +96,6 @@ fun CatEditorScreen() {
10996 }
11097
11198 var moreOptionsVisible by remember { mutableStateOf(false ) }
112- var inputSeedDialog by remember { mutableStateOf(false ) }
113- var inputSeedText by remember { mutableStateOf(" " ) }
11499
115100 Scaffold (
116101 topBar = {
@@ -290,82 +275,17 @@ fun CatEditorScreen() {
290275 }
291276 )
292277
278+ val inputSeedDialogState = remember { mutableStateOf(false ) }
279+
293280 fun updateCatSeed (seed : Long ) {
294281 catSeed = seed
295282 catEditorController.updateColors(catSeed)
296283 catEditorRecords.addRecord(CatEditorRecords .seed(catSeed))
297284 }
298285
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+ })
369289
370290 AnimatedVisibility (
371291 visible = moreOptionsVisible,
@@ -391,7 +311,7 @@ fun CatEditorScreen() {
391311 }
392312
393313 IconButton (onClick = {
394- inputSeedDialog = true
314+ inputSeedDialogState.value = true
395315 }) {
396316 Icon (imageVector = Icons .Rounded .Edit , contentDescription = null )
397317 }
0 commit comments