From 5ec79f776b562ac85ee3673eea501914c46cadf2 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Thu, 5 Sep 2024 13:30:39 +0800 Subject: [PATCH] refactor: make the candidate text always in center while ... ... the comment show in the rest top space. --- .../trime/ime/candidates/CandidateItemUi.kt | 35 +++---------------- .../adapter/CompactCandidateViewAdapter.kt | 4 +-- .../adapter/PagingCandidateViewAdapter.kt | 4 +-- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ime/candidates/CandidateItemUi.kt b/app/src/main/java/com/osfans/trime/ime/candidates/CandidateItemUi.kt index 4845454362..3fb632e5de 100644 --- a/app/src/main/java/com/osfans/trime/ime/candidates/CandidateItemUi.kt +++ b/app/src/main/java/com/osfans/trime/ime/candidates/CandidateItemUi.kt @@ -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 @@ -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") @@ -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 = @@ -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 { @@ -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) } diff --git a/app/src/main/java/com/osfans/trime/ime/candidates/adapter/CompactCandidateViewAdapter.kt b/app/src/main/java/com/osfans/trime/ime/candidates/adapter/CompactCandidateViewAdapter.kt index e959956a79..34ec112383 100644 --- a/app/src/main/java/com/osfans/trime/ime/candidates/adapter/CompactCandidateViewAdapter.kt +++ b/app/src/main/java/com/osfans/trime/ime/candidates/adapter/CompactCandidateViewAdapter.kt @@ -71,8 +71,8 @@ open class CompactCandidateViewAdapter(val theme: Theme) : BaseQuickAdapter