Skip to content

Commit 276181e

Browse files
committed
feat: Add Cat Editor seed input
ref: #545 Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent 3166e8a commit 276181e

File tree

13 files changed

+1395
-64
lines changed

13 files changed

+1395
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.5.0
44

5+
- Add Cat Editor seed input [#545](https://github.com/hushenghao/AndroidEasterEggs/issues/545)
56
- Add Bengali translation, Thanks for [@ChildishRifty7](https://github.com/childishrifty7) 's contribution
67
- Fix Cat Editor draw problem on Android N [#37138664](https://issuetracker.google.com/issues/37138664)
78
- Fix Cat Editor color hvs palette maxWidth [#522](https://github.com/hushenghao/AndroidEasterEggs/issues/522)

CHANGELOG_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.5.0
44

5+
- 新增 Cat Editor 种子输入 [#545](https://github.com/hushenghao/AndroidEasterEggs/issues/545)
56
- 新增孟加拉语翻译,感谢 [@ChildishRifty7](https://github.com/childishrifty7) 的贡献
67
- 修复 Cat Editor 在 Android N 的绘制问题 [#37138664](https://issuetracker.google.com/issues/37138664)
78
- 修复 Cat Editor hvs颜色选择器最大宽度 [#522](https://github.com/hushenghao/AndroidEasterEggs/issues/522)

app/src/main/java/com/dede/android_eggs/ui/composes/BuildTypeBubble.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.dede.android_eggs.ui.composes
33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.layout.Box
55
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.foundation.shape.CircleShape
67
import androidx.compose.foundation.shape.CornerSize
7-
import androidx.compose.foundation.shape.RoundedCornerShape
88
import androidx.compose.material3.Text
99
import androidx.compose.runtime.Composable
1010
import androidx.compose.ui.Modifier
@@ -37,8 +37,7 @@ fun BuildTypeBubble() {
3737
modifier = Modifier
3838
.background(
3939
Color.Red,
40-
RoundedCornerShape(50)
41-
.copy(bottomStart = CornerSize(0))
40+
CircleShape.copy(bottomStart = CornerSize(0))
4241
)
4342
.padding(horizontal = 4.dp, vertical = 1.dp),
4443
color = Color.White,

app/src/main/java/com/dede/android_eggs/views/main/compose/BottomSearchBar.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
1414
import androidx.compose.foundation.layout.imePadding
1515
import androidx.compose.foundation.layout.navigationBarsPadding
1616
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.shape.CircleShape
1718
import androidx.compose.foundation.shape.RoundedCornerShape
1819
import androidx.compose.foundation.text.KeyboardOptions
1920
import androidx.compose.material.icons.Icons
@@ -208,7 +209,7 @@ private fun BottomSearchBarView(
208209
keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Search
209210
),
210211
singleLine = true,
211-
shape = RoundedCornerShape(50),
212+
shape = CircleShape,
212213
colors = TextFieldDefaults.colors(
213214
focusedIndicatorColor = Color.Transparent,
214215
disabledIndicatorColor = Color.Transparent,

core/resources/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@
5555
<string name="action_goto_settings">Go to Settings</string>
5656

5757
<string name="cat_editor">Cat Editor</string>
58+
<string name="cat_editor_input_seed">Input Cat Seed</string>
5859
</resources>

fastlane/metadata/android/en-US/changelogs/60.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Add Cat Editor seed input #545
12
- Add Bengali translation, Thanks for @ChildishRifty7 's contribution
23
- Fix Cat Editor draw problem on Android N #37138664
34
- Fix Cat Editor color hvs palette maxWidth #522

fastlane/metadata/android/zh-CN/changelogs/60.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- 新增 Cat Editor 种子输入 #545
12
- 新增孟加拉语翻译,感谢 @ChildishRifty7 的贡献
23
- 修复 Cat Editor 在 Android N 的绘制问题 #37138664
34
- 修复 Cat Editor hvs颜色选择器最大宽度 #522

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import androidx.compose.ui.graphics.Color
1616
import androidx.compose.ui.graphics.toArgb
1717

1818

19-
internal class CatEditorControllerImpl(private val speed: Long) : CatEditorController {
19+
internal class CatEditorControllerImpl(private val seed: Long) : CatEditorController {
2020

2121
internal object SaverImpl : Saver<CatEditorControllerImpl, Bundle> {
22-
private const val KEY_SPEED = "speed"
22+
private const val KEY_SEED = "seed"
2323
private const val KEY_COLORS = "colors"
2424
private const val KEY_SCALE = "scale"
2525
private const val KEY_OFFSET_X = "offset_x"
@@ -30,7 +30,7 @@ internal class CatEditorControllerImpl(private val speed: Long) : CatEditorContr
3030
private const val KEY_GRID_VISIBLE = "grid_visible"
3131

3232
override fun restore(value: Bundle): CatEditorControllerImpl {
33-
val speed = value.getLong(KEY_SPEED)
33+
val seed = value.getLong(KEY_SEED)
3434
val colors = value.getIntArray(KEY_COLORS)
3535
val offsetX = value.getFloat(KEY_OFFSET_X)
3636
val offsetY = value.getFloat(KEY_OFFSET_Y)
@@ -40,7 +40,7 @@ internal class CatEditorControllerImpl(private val speed: Long) : CatEditorContr
4040
val gesturesEnabled = value.getBoolean(KEY_GESTURES_ENABLED)
4141
val gridVisible = value.getBoolean(KEY_GRID_VISIBLE)
4242

43-
val impl = CatEditorControllerImpl(speed).apply {
43+
val impl = CatEditorControllerImpl(seed).apply {
4444
if (colors != null) {
4545
updateColors(colors.map(::Color))
4646
}
@@ -56,7 +56,7 @@ internal class CatEditorControllerImpl(private val speed: Long) : CatEditorContr
5656

5757
override fun SaverScope.save(value: CatEditorControllerImpl): Bundle {
5858
return Bundle().apply {
59-
putLong(KEY_SPEED, value.speed)
59+
putLong(KEY_SEED, value.seed)
6060
putIntArray(KEY_COLORS, value.colorStateList.map(Color::toArgb).toIntArray())
6161
putFloat(KEY_OFFSET_X, value.offsetState.value.x)
6262
putFloat(KEY_OFFSET_Y, value.offsetState.value.y)
@@ -81,7 +81,7 @@ internal class CatEditorControllerImpl(private val speed: Long) : CatEditorContr
8181

8282
private val gesturesEnabledState = mutableStateOf(true)
8383

84-
private val colorStateList = mutableStateListOf(*CatPartColors.colors(speed))
84+
private val colorStateList = mutableStateListOf(*CatPartColors.colors(seed))
8585

8686
override var defaultGraphicsLayerScale: Float = 1f
8787
set(value) {
@@ -139,8 +139,8 @@ internal interface CatEditorController {
139139

140140
fun updateColors(colors: List<Color>)
141141

142-
fun updateColors(speed: Long) {
143-
updateColors(CatPartColors.colors(speed).toList())
142+
fun updateColors(seed: Long) {
143+
updateColors(CatPartColors.colors(seed).toList())
144144
}
145145

146146
fun setSelectedPartColor(color: Color)
@@ -152,8 +152,8 @@ internal interface CatEditorController {
152152
}
153153

154154
@Composable
155-
internal fun rememberCatEditorController(speed: Long = System.currentTimeMillis()): CatEditorController {
155+
internal fun rememberCatEditorController(seed: Long = Utilities.randomSeed()): CatEditorController {
156156
return rememberSaveable(saver = CatEditorControllerImpl.SaverImpl) {
157-
CatEditorControllerImpl(speed)
157+
CatEditorControllerImpl(seed)
158158
}
159159
}

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

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
5151

5252
private const val TAG = "CatEditorRecords"
5353

54-
fun speed(speed: Long): Record {
55-
return SpeedRecord(speed)
54+
fun seed(seed: Long): Record {
55+
return SeedRecord(seed)
5656
}
5757

58-
fun colors(colors: List<Color>, speed: Long): Record {
59-
return ColorsRecord(ArrayList(colors), speed)
58+
fun colors(colors: List<Color>, seed: Long): Record {
59+
return ColorsRecord(ArrayList(colors), seed)
6060
}
6161

6262
@Composable
@@ -73,19 +73,19 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
7373
fun restoreRecord(
7474
record: Record?,
7575
controller: CatEditorController,
76-
speedState: MutableLongState
76+
seedState: MutableLongState
7777
) {
78-
record?.restore(controller, speedState)
78+
record?.restore(controller, seedState)
7979
}
8080
}
8181

82-
internal abstract class Record(val speed: Long) : Parcelable {
83-
abstract fun restore(controller: CatEditorController, speedState: MutableLongState)
82+
internal abstract class Record(val seed: Long) : Parcelable {
83+
abstract fun restore(controller: CatEditorController, seedState: MutableLongState)
8484
}
8585

86-
private class ColorsRecord(private val colors: List<Color>, speed: Long) : Record(speed) {
87-
override fun restore(controller: CatEditorController, speedState: MutableLongState) {
88-
speedState.longValue = speed
86+
private class ColorsRecord(private val colors: List<Color>, seed: Long) : Record(seed) {
87+
override fun restore(controller: CatEditorController, seedState: MutableLongState) {
88+
seedState.longValue = seed
8989
controller.updateColors(colors)
9090
}
9191

@@ -95,7 +95,7 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
9595
separator = ",",
9696
postfix = "]"
9797
) { Utilities.getHexColor(it, true) }
98-
return "ColorRecord(colors=$colorsStr, speed=$speed)"
98+
return "ColorRecord(colors=$colorsStr, seed=$seed)"
9999
}
100100

101101
override fun describeContents(): Int {
@@ -104,15 +104,15 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
104104

105105
override fun writeToParcel(dest: Parcel, flags: Int) {
106106
dest.writeIntArray(colors.map(Color::toArgb).toIntArray())
107-
dest.writeLong(speed)
107+
dest.writeLong(seed)
108108
}
109109

110110
companion object CREATOR : Parcelable.Creator<ColorsRecord> {
111111
override fun createFromParcel(parcel: Parcel): ColorsRecord {
112112
val colors = IntArray(CatPartColors.COLOR_SIZE)
113113
parcel.readIntArray(colors)
114-
val speed = parcel.readLong()
115-
return ColorsRecord(colors.map(::Color).toList(), speed)
114+
val seed = parcel.readLong()
115+
return ColorsRecord(colors.map(::Color).toList(), seed)
116116
}
117117

118118
override fun newArray(size: Int): Array<ColorsRecord?> {
@@ -121,31 +121,31 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
121121
}
122122
}
123123

124-
private open class SpeedRecord(speed: Long) : Record(speed) {
125-
override fun restore(controller: CatEditorController, speedState: MutableLongState) {
126-
speedState.longValue = speed
127-
controller.updateColors(speed)
124+
private open class SeedRecord(seed: Long) : Record(seed) {
125+
override fun restore(controller: CatEditorController, seedState: MutableLongState) {
126+
seedState.longValue = seed
127+
controller.updateColors(seed)
128128
}
129129

130130
override fun toString(): String {
131-
return "SpeedRecord(speed=$speed)"
131+
return "SeedRecord(seed=$seed)"
132132
}
133133

134134
override fun describeContents(): Int {
135135
return 0
136136
}
137137

138138
override fun writeToParcel(dest: Parcel, flags: Int) {
139-
dest.writeLong(speed)
139+
dest.writeLong(seed)
140140
}
141141

142-
companion object CREATOR : Parcelable.Creator<SpeedRecord> {
143-
override fun createFromParcel(parcel: Parcel): SpeedRecord {
144-
val speed = parcel.readLong()
145-
return SpeedRecord(speed)
142+
companion object CREATOR : Parcelable.Creator<SeedRecord> {
143+
override fun createFromParcel(parcel: Parcel): SeedRecord {
144+
val seed = parcel.readLong()
145+
return SeedRecord(seed)
146146
}
147147

148-
override fun newArray(size: Int): Array<SpeedRecord?> {
148+
override fun newArray(size: Int): Array<SeedRecord?> {
149149
return arrayOfNulls(size)
150150
}
151151
}
@@ -172,11 +172,15 @@ internal class CatEditorRecords(private val maxSize: Int, recordIndex: Int = 0)
172172
}
173173

174174
fun goBack(): Record? {
175-
return getRecord(--recordIndex)
175+
return getRecord(--recordIndex).apply {
176+
Log.i(TAG, "goBack, index: $recordIndex, count: $recordCount")
177+
}
176178
}
177179

178180
fun goNext(): Record? {
179-
return getRecord(++recordIndex)
181+
return getRecord(++recordIndex).apply {
182+
Log.i(TAG, "goNext, index: $recordIndex, count: $recordCount")
183+
}
180184
}
181185

182186
fun addRecord(record: Record) {

0 commit comments

Comments
 (0)