Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ class QuickBar(
val unrollButtonStateMachine =
UnrollButtonStateMachine.new {
when (it) {
UnrollButtonStateMachine.State.AboutToAttachWindow -> {
setUnrollButtonToDetach()
setUnrollButtonEnabled(true)
windowManager.attachWindow(
FlexboxUnrolledCandidateWindow(context, service, rime, theme, this, windowManager, candidate),
)
}
UnrollButtonStateMachine.State.ClickToAttachWindow -> {
setUnrollButtonToAttach()
setUnrollButtonEnabled(true)
Expand All @@ -193,7 +200,7 @@ class QuickBar(
}

private fun setUnrollButtonToAttach() {
candidateUi.unrollButton.setOnClickListener { view ->
candidateUi.unrollButton.setOnClickListener {
windowManager.attachWindow(
FlexboxUnrolledCandidateWindow(context, service, rime, theme, this, windowManager, candidate),
)
Expand All @@ -202,7 +209,7 @@ class QuickBar(
}

private fun setUnrollButtonToDetach() {
candidateUi.unrollButton.setOnClickListener { view ->
candidateUi.unrollButton.setOnClickListener {
windowManager.attachWindow(KeyboardWindow)
}
candidateUi.unrollButton.setIcon(R.drawable.ic_baseline_expand_less_24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package com.osfans.trime.ime.bar

import com.osfans.trime.ime.bar.UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesEmpty
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesHighlighted
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.AboutToAttachWindow
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.ClickToAttachWindow
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.ClickToDetachWindow
import com.osfans.trime.ime.bar.UnrollButtonStateMachine.State.Hidden
Expand All @@ -14,13 +16,15 @@ import com.osfans.trime.util.TransitionBuildBlock

object UnrollButtonStateMachine {
enum class State {
AboutToAttachWindow,
ClickToAttachWindow,
ClickToDetachWindow,
Hidden,
}

enum class BooleanKey : EventStateMachine.BooleanStateKey {
UnrolledCandidatesEmpty,
UnrolledCandidatesHighlighted,
}

enum class TransitionEvent(
Expand All @@ -29,9 +33,11 @@ object UnrollButtonStateMachine {
UnrolledCandidatesUpdated({
from(Hidden) transitTo ClickToAttachWindow on (UnrolledCandidatesEmpty to false)
from(ClickToAttachWindow) transitTo Hidden on (UnrolledCandidatesEmpty to true)
from(ClickToAttachWindow) transitTo AboutToAttachWindow on (UnrolledCandidatesHighlighted to true)
}),
UnrolledCandidatesAttached({
from(ClickToAttachWindow) transitTo ClickToDetachWindow
from(AboutToAttachWindow) transitTo ClickToDetachWindow
}),
UnrolledCandidatesDetached({
from(ClickToDetachWindow) transitTo Hidden on (UnrolledCandidatesEmpty to true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.osfans.trime.ime.candidates

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.View
Expand Down Expand Up @@ -122,19 +123,20 @@ class CandidateItemUi(
)
}

@SuppressLint("UseKtx")
fun update(
item: CandidateItem,
isHighlighted: Boolean,
highlighted: Boolean,
) {
val tColor = if (isHighlighted) hlTextColor else textColor
val cColor = if (isHighlighted) hlCommentColor else commentColor
val tColor = if (highlighted) hlTextColor else textColor
val cColor = if (highlighted) hlCommentColor else commentColor
text.text = item.text
text.setTextColor(tColor)
comment.text = if (theme.generalStyle.commentOnTop) item.comment else " ${item.comment}"
comment.setTextColor(cColor)
comment.isGone = item.comment.isEmpty()
root.background =
if (isHighlighted) {
if (highlighted) {
ColorDrawable(hlBackColor)
} else {
pressHighlightDrawable(hlBackColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ class CompactCandidateModule(
UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesEmpty to
(adapter.total == childCount),
)
bar.unrollButtonStateMachine.push(
UnrollButtonStateMachine.TransitionEvent.UnrolledCandidatesUpdated,
UnrollButtonStateMachine.BooleanKey.UnrolledCandidatesHighlighted to
(adapter.highlightedIdx >= childCount),
)
}

val adapter by lazy {
CompactCandidateViewAdapter(theme).apply {
setOnItemClickListener { _, view, position ->
setOnItemClickListener { _, _, position ->
rime.launchOnReady { it.selectCandidate(position, global = true) }
}
setOnItemLongClickListener { _, view, position ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ open class PagingCandidateViewAdapter(
var offset: Int = 0
private set

fun refreshWithOffset(offset: Int) {
var highlightedIndex: Int = -1
private set

fun refreshWith(offset: Int, highlightedIndex: Int) {
this.offset = offset
this.highlightedIndex = highlightedIndex
refresh()
}

Expand All @@ -49,9 +53,11 @@ open class PagingCandidateViewAdapter(
position: Int,
) {
val item = getItem(position) ?: return
holder.ui.update(item, false)
val idx = position + offset
val highlighted = idx == highlightedIndex
holder.ui.update(item, highlighted)
holder.text = item.text
holder.comment = item.comment
holder.idx = position + offset
holder.idx = idx
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ abstract class BaseUnrolledCandidateWindow(
windowManager.attachWindow(KeyboardWindow)
} else {
candidateLayout.resetPosition()
adapter.refreshWithOffset(it)
adapter.refreshWith(
offset = it,
highlightedIndex = compactCandidate.adapter.highlightedIdx,
)
}
}
}
Expand All @@ -120,7 +123,7 @@ abstract class BaseUnrolledCandidateWindow(

fun bindCandidateUiViewHolder(holder: CandidateViewHolder) {
holder.itemView.run {
setOnClickListener { view ->
setOnClickListener { _ ->
rime.launchOnReady { it.selectCandidate(holder.idx, global = true) }
}
setOnLongClickListener { view ->
Expand Down
Loading