Skip to content

Commit

Permalink
feat: restore the highlight of the candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Sep 1, 2024
1 parent 2f5b3ce commit a462c00
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ import splitties.views.dsl.core.wrapContent
import splitties.views.gravityCenter

class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
private val maybeCandidateTextColor = ColorManager.getColor("candidate_text_color")
private val maybeCommentTextColor = ColorManager.getColor("comment_text_color")
private val maybeHighlightedCandidateTextColor = ColorManager.getColor("hilited_candidate_text_color")
private val maybeHighlightedCommentTextColor = ColorManager.getColor("hilited_comment_text_color")

private val text =
textView {
textSize = theme.generalStyle.candidateTextSize.toFloat()
typeface = FontManager.getTypeface("candidate_font")
isSingleLine = true
gravity = gravityCenter
ColorManager.getColor("candidate_text_color")?.let { setTextColor(it) }
maybeCandidateTextColor?.let { setTextColor(it) }
}

private val comment =
Expand All @@ -37,7 +42,7 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
typeface = FontManager.getTypeface("comment_font")
isSingleLine = true
gravity = gravityCenter
ColorManager.getColor("comment_text_color")?.let { setTextColor(it) }
maybeCommentTextColor?.let { setTextColor(it) }
visibility = View.GONE
}

Expand Down Expand Up @@ -92,4 +97,14 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
}
}
}

fun highlight(yes: Boolean) {
if (yes) {
maybeHighlightedCandidateTextColor?.let { text.setTextColor(it) }
maybeHighlightedCommentTextColor?.let { comment.setTextColor(it) }
} else {
maybeCandidateTextColor?.let { text.setTextColor(it) }
maybeCommentTextColor?.let { comment.setTextColor(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ open class CompactCandidateViewAdapter(val theme: Theme) : BaseQuickAdapter<Cand
var previous: Int = 0
private set

var highlightedIdx: Int = -1
private set

fun updateCandidates(
list: List<CandidateItem>,
isLastPage: Boolean,
previous: Int,
highlightedIdx: Int,
sticky: Int = 0,
) {
this.isLastPage = isLastPage
this.previous = previous
this.sticky = sticky
this.highlightedIdx = highlightedIdx
super.submitList(list.drop(sticky))
}

Expand All @@ -57,11 +62,15 @@ open class CompactCandidateViewAdapter(val theme: Theme) : BaseQuickAdapter<Cand
item: CandidateItem?,
) {
val (comment, text) = item!!
holder.ui.setText(text)
holder.ui.setComment(comment)
val idx = sticky + position
holder.ui.run {
setText(text)
setComment(comment)
highlight(theme.generalStyle.candidateUseCursor && idx == highlightedIdx)
}
holder.text = text
holder.comment = comment
holder.idx = sticky + position
holder.idx = idx
holder.ui.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
minWidth = 0
flexGrow = 1f
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,12 @@ class InputView(
val candidates = ctx.menu.candidates.map { CandidateItem(it.comment ?: "", it.text) }
val isLastPage = ctx.menu.isLastPage
val previous = ctx.menu.run { pageSize * pageNumber }
val highlightedIdx = ctx.menu.highlightedCandidateIndex
if (composition.isPopupWindowEnabled) {
val sticky = composition.binding.composition.update(ctx)
compactCandidate.adapter.updateCandidates(candidates, isLastPage, previous, sticky)
compactCandidate.adapter.updateCandidates(candidates, isLastPage, previous, highlightedIdx, sticky)
} else {
compactCandidate.adapter.updateCandidates(candidates, isLastPage, previous)
compactCandidate.adapter.updateCandidates(candidates, isLastPage, previous, highlightedIdx)
}
if (candidates.isEmpty()) {
compactCandidate.refreshUnrolled()
Expand Down

0 comments on commit a462c00

Please sign in to comment.