Skip to content

Commit df07189

Browse files
committed
refactor: simplify event transition of UnrollButtonStateMachine
1 parent 9ee65a3 commit df07189

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

app/src/main/java/com/osfans/trime/ime/bar/InputBarDelegate.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,10 @@ class InputBarDelegate : InputBroadcastReceiver {
174174
val unrollButtonStateMachine =
175175
UnrollButtonStateMachine.new {
176176
when (it) {
177-
UnrollButtonStateMachine.State.AboutToAttachWindow -> {
178-
setUnrollButtonToDetach()
179-
setUnrollButtonEnabled(true)
180-
windowManager.attachWindow(FlexboxUnrolledCandidateWindow())
181-
}
182177
UnrollButtonStateMachine.State.ClickToAttachWindow -> {
183178
setUnrollButtonToAttach()
184179
setUnrollButtonEnabled(true)
180+
setUnrollWindowToAttach()
185181
}
186182
UnrollButtonStateMachine.State.ClickToDetachWindow -> {
187183
setUnrollButtonToDetach()
@@ -211,6 +207,14 @@ class InputBarDelegate : InputBroadcastReceiver {
211207
candidateUi.unrollButton.visibility = if (enabled) View.VISIBLE else View.INVISIBLE
212208
}
213209

210+
private fun setUnrollWindowToAttach() {
211+
unrollButtonStateMachine.getBooleanState(
212+
UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesHighlighted,
213+
)?.let {
214+
windowManager.attachWindow(FlexboxUnrolledCandidateWindow())
215+
}
216+
}
217+
214218
override fun onCandidateListUpdate(data: RimeMessage.CandidateListMessage.Data) {
215219
barStateMachine.push(
216220
QuickBarStateMachine.TransitionEvent.CandidatesUpdated,

app/src/main/java/com/osfans/trime/ime/bar/UnrollButtonStateMachine.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// SPDX-FileCopyrightText: 2015 - 2024 Rime community
2-
//
3-
// SPDX-License-Identifier: GPL-3.0-or-later
1+
/*
2+
* SPDX-FileCopyrightText: 2015 - 2026 Rime community
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
45

56
package com.osfans.trime.ime.bar
67

78
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesEmpty
89
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesHighlighted
9-
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.AboutToAttachWindow
1010
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.ClickToAttachWindow
1111
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.ClickToDetachWindow
1212
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.Hidden
@@ -16,7 +16,6 @@ import com.osfans.trime.util.TransitionBuildBlock
1616

1717
object UnrollButtonStateMachine {
1818
enum class State {
19-
AboutToAttachWindow,
2019
ClickToAttachWindow,
2120
ClickToDetachWindow,
2221
Hidden,
@@ -33,11 +32,10 @@ object UnrollButtonStateMachine {
3332
UnrolledCandidatesUpdated({
3433
from(Hidden) transitTo ClickToAttachWindow on (UnrolledCandidatesEmpty to false)
3534
from(ClickToAttachWindow) transitTo Hidden on (UnrolledCandidatesEmpty to true)
36-
from(ClickToAttachWindow) transitTo AboutToAttachWindow on (UnrolledCandidatesHighlighted to true)
35+
from(ClickToAttachWindow) transitTo ClickToDetachWindow on (UnrolledCandidatesHighlighted to true)
3736
}),
3837
UnrolledCandidatesAttached({
3938
from(ClickToAttachWindow) transitTo ClickToDetachWindow
40-
from(AboutToAttachWindow) transitTo ClickToDetachWindow
4139
}),
4240
UnrolledCandidatesDetached({
4341
from(ClickToDetachWindow) transitTo Hidden on (UnrolledCandidatesEmpty to true)

0 commit comments

Comments
 (0)