Skip to content

Commit 8d4be50

Browse files
committed
feat: Cat Editor add seed display
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent 8a786f0 commit 8d4be50

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

feature/cat-editor/src/main/java/com/dede/android_eggs/cat_editor/CatEditorScreen.kt

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import androidx.compose.animation.fadeOut
1212
import androidx.compose.animation.slideInVertically
1313
import androidx.compose.animation.slideOutVertically
1414
import androidx.compose.foundation.layout.Box
15-
import androidx.compose.foundation.layout.BoxScope
15+
import androidx.compose.foundation.layout.Column
1616
import androidx.compose.foundation.layout.Row
1717
import androidx.compose.foundation.layout.RowScope
1818
import androidx.compose.foundation.layout.Spacer
@@ -39,6 +39,7 @@ import androidx.compose.material3.Icon
3939
import androidx.compose.material3.IconButton
4040
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
4141
import androidx.compose.material3.MaterialTheme.colorScheme
42+
import androidx.compose.material3.MaterialTheme.typography
4243
import androidx.compose.material3.Scaffold
4344
import androidx.compose.material3.Text
4445
import androidx.compose.material3.surfaceColorAtElevation
@@ -64,6 +65,7 @@ import androidx.compose.ui.res.stringResource
6465
import androidx.compose.ui.text.font.FontWeight
6566
import androidx.compose.ui.text.style.TextOverflow
6667
import androidx.compose.ui.unit.dp
68+
import androidx.compose.ui.unit.sp
6769
import com.dede.android_eggs.cat_editor.CaptureControllerDelegate.Companion.rememberCaptureControllerDelegate
6870
import com.dede.android_eggs.cat_editor.CatEditorRecords.Companion.rememberCatEditorRecords
6971
import com.dede.android_eggs.navigation.EasterEggsDestination
@@ -75,6 +77,7 @@ import com.dede.basic.utils.ShareCatUtils
7577
import com.google.accompanist.permissions.ExperimentalPermissionsApi
7678
import kotlinx.coroutines.launch
7779
import androidx.appcompat.R as AppCompatR
80+
import com.dede.android_eggs.resources.R as StringR
7881

7982
object CatEditorScreen : EasterEggsDestination {
8083
override val route: String = "cat_editor"
@@ -89,7 +92,7 @@ fun CatEditorScreen() {
8992

9093
val catSeedState = rememberSaveable { mutableLongStateOf(Utilities.randomSeed()) }
9194
var catSeed by catSeedState
92-
val catName = stringResource(R.string.default_cat_name, catSeed % 1000)
95+
val catName = stringResource(R.string.default_cat_name, catSeed)// full seed name
9396

9497
val colorPaletteState = remember { mutableStateOf(false) }
9598

@@ -188,10 +191,7 @@ fun CatEditorScreen() {
188191
}
189192
}
190193
val inputCatButton: @Composable () -> Unit = {
191-
IconButton(onClick = {
192-
moreOptionsPopVisible = false
193-
inputSeedDialogState.value = true
194-
}) {
194+
IconButton(onClick = { inputSeedDialogState.value = true }) {
195195
Icon(imageVector = Icons.Rounded.Cat, contentDescription = null)
196196
}
197197
}
@@ -231,12 +231,25 @@ fun CatEditorScreen() {
231231
}
232232
},
233233
title = {
234-
Text(
235-
text = catName,//"Cat Editor",
236-
maxLines = 1,
237-
overflow = TextOverflow.Ellipsis,
238-
fontWeight = FontWeight.Medium
239-
)
234+
Column(
235+
horizontalAlignment = Alignment.CenterHorizontally
236+
) {
237+
Text(
238+
text = stringResource(StringR.string.cat_editor),
239+
maxLines = 1,
240+
overflow = TextOverflow.Ellipsis,
241+
fontWeight = FontWeight.Medium
242+
)
243+
Text(
244+
text = stringResource(R.string.label_cat_seed, catSeed),
245+
maxLines = 1,
246+
overflow = TextOverflow.Ellipsis,
247+
style = typography.labelSmall.copy(
248+
fontSize = 9.sp,
249+
fontWeight = FontWeight.Normal
250+
),
251+
)
252+
}
240253
},
241254
)
242255
},
@@ -291,6 +304,7 @@ fun CatEditorScreen() {
291304

292305
if (bottomButtonCount < menuButtonList.size) {
293306
MoreOptionsPopup(
307+
modifier = Modifier.align(Alignment.BottomEnd),
294308
visible = moreOptionsPopVisible,
295309
) {
296310
for (i in bottomButtonCount..<menuButtonList.size) {
@@ -384,6 +398,10 @@ private fun BottomOptionsBar(
384398
// Add 'more options' button
385399
iconButtonCount = count - 1
386400
moreOptionsVisible = true
401+
} else {
402+
// Show all options
403+
iconButtonCount = totalOptionsCount
404+
moreOptionsVisible = false
387405
}
388406
}
389407
) {
@@ -406,14 +424,15 @@ private fun BottomOptionsBar(
406424
}
407425

408426
@Composable
409-
private fun BoxScope.MoreOptionsPopup(
427+
private fun MoreOptionsPopup(
428+
modifier: Modifier = Modifier,
410429
visible: Boolean,
411-
content: @Composable RowScope.() -> Unit
430+
content: @Composable() (RowScope.() -> Unit)
412431
) {
413432
AnimatedVisibility(
414433
visible = visible,
415434
modifier = Modifier
416-
.align(Alignment.BottomEnd)
435+
.then(modifier)
417436
.padding(vertical = 12.dp, horizontal = 14.dp),
418437
label = "More Options Visibility",
419438
enter = fadeIn(animationSpec = tween(220)) +

feature/cat-editor/src/main/java/com/dede/android_eggs/cat_editor/CatSeedInputDialog.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import androidx.compose.ui.text.input.ImeAction
3333
import androidx.compose.ui.text.input.KeyboardCapitalization
3434
import androidx.compose.ui.text.input.KeyboardType
3535
import androidx.compose.ui.text.intl.LocaleList
36-
import com.dede.android_eggs.resources.R
3736
import com.dede.android_eggs.ui.composes.icons.rounded.Cat
37+
import com.dede.android_eggs.resources.R as StringR
3838

3939
/**
4040
* A dialog for inputting a cat seed.
@@ -76,7 +76,7 @@ fun CatSeedInputDialog(
7676
dismiss()
7777
},
7878
title = {
79-
Text(text = stringResource(R.string.cat_editor))
79+
Text(text = stringResource(StringR.string.cat_editor))
8080
},
8181
text = {
8282
val focusRequester = remember { FocusRequester() }
@@ -120,11 +120,16 @@ fun CatSeedInputDialog(
120120
enter = fadeIn() + slideInVertically(),
121121
exit = fadeOut() + slideOutVertically(),
122122
) {
123-
Text(text = "# ${Utilities.string2Seed(inputSeedText)}")
123+
Text(
124+
text = stringResource(
125+
R.string.label_cat_seed,
126+
Utilities.string2Seed(inputSeedText)
127+
)
128+
)
124129
}
125130
},
126131
label = {
127-
Text(text = stringResource(R.string.cat_editor_input_seed))
132+
Text(text = stringResource(StringR.string.cat_editor_input_seed))
128133
},
129134
keyboardOptions = KeyboardOptions(
130135
autoCorrectEnabled = false,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="default_cat_name" translatable="false">Cat #%d</string>
4+
<string name="label_cat_seed" translatable="false">#%d</string>
45
</resources>

0 commit comments

Comments
 (0)