Skip to content

Commit

Permalink
refactor: make the candidate text always in center while ...
Browse files Browse the repository at this point in the history
... the comment show in the rest top space.
  • Loading branch information
WhiredPlanck committed Sep 5, 2024
1 parent 904e715 commit 5ec79f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
package com.osfans.trime.ime.candidates

import android.content.Context
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.FontManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.util.pressHighlightDrawable
import splitties.views.dsl.constraintlayout.above
import splitties.views.dsl.constraintlayout.after
import splitties.views.dsl.constraintlayout.before
import splitties.views.dsl.constraintlayout.below
import splitties.views.dsl.constraintlayout.bottomOfParent
import splitties.views.dsl.constraintlayout.centerHorizontally
import splitties.views.dsl.constraintlayout.centerInParent
import splitties.views.dsl.constraintlayout.centerVertically
import splitties.views.dsl.constraintlayout.constraintLayout
import splitties.views.dsl.constraintlayout.endOfParent
Expand All @@ -35,7 +32,7 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
private val maybeHighlightedCandidateTextColor = ColorManager.getColor("hilited_candidate_text_color")
private val maybeHighlightedCommentTextColor = ColorManager.getColor("hilited_comment_text_color")

private val label =
val label =
textView {
textSize = theme.generalStyle.candidateTextSize.toFloat()
typeface = FontManager.getTypeface("candidate_font")
Expand All @@ -44,14 +41,13 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
maybeCandidateTextColor?.let { setTextColor(it) }
}

private val altLabel =
val altLabel =
textView {
textSize = theme.generalStyle.commentTextSize.toFloat()
typeface = FontManager.getTypeface("comment_font")
isSingleLine = true
gravity = gravityCenter
maybeCommentTextColor?.let { setTextColor(it) }
visibility = View.GONE
}

override val root =
Expand All @@ -63,20 +59,12 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
lParams(wrapContent, wrapContent) {
topOfParent()
centerHorizontally()
above(label)

verticalChainStyle = ConstraintLayout.LayoutParams.CHAIN_PACKED
verticalBias = 0.5f
},
)
add(
label,
lParams(wrapContent, wrapContent) {
below(altLabel)
centerHorizontally()
bottomOfParent()

verticalBias = 0.5f
centerInParent()
},
)
} else {
Expand Down Expand Up @@ -104,21 +92,6 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
}
}

fun setText(str: String) {
label.text = str
}

fun setComment(str: String) {
altLabel.run {
if (str.isNotEmpty()) {
text = str
if (visibility == View.GONE) visibility = View.VISIBLE
} else if (visibility != View.GONE) {
visibility = View.GONE
}
}
}

fun highlight(yes: Boolean) {
if (yes) {
maybeHighlightedCandidateTextColor?.let { label.setTextColor(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ open class CompactCandidateViewAdapter(val theme: Theme) : BaseQuickAdapter<Cand
val (comment, text) = item!!
val idx = sticky + position
holder.ui.run {
setText(text)
setComment(comment)
label.text = text
altLabel.text = comment
highlight(theme.generalStyle.candidateUseCursor && idx == highlightedIdx)
}
holder.text = text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ open class PagingCandidateViewAdapter(val theme: Theme) : PagingDataAdapter<Cand
position: Int,
) {
val (comment, text) = getItem(position)!!
holder.ui.setText(text)
holder.ui.setComment(comment)
holder.ui.label.text = text
holder.ui.altLabel.text = comment
holder.text = text
holder.comment = comment
holder.idx = position + offset
Expand Down

0 comments on commit 5ec79f7

Please sign in to comment.