Skip to content

Commit

Permalink
refactor: never fill the width of the candidate item view
Browse files Browse the repository at this point in the history
This will make the blank area too large when compact candidate view just has a few of candidates

refactor: rename the text view in the candidate item view
  • Loading branch information
WhiredPlanck committed Sep 5, 2024
1 parent b0eea1d commit 904e715
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 text =
private val label =
textView {
textSize = theme.generalStyle.candidateTextSize.toFloat()
typeface = FontManager.getTypeface("candidate_font")
Expand All @@ -44,7 +44,7 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
maybeCandidateTextColor?.let { setTextColor(it) }
}

private val comment =
private val altLabel =
textView {
textSize = theme.generalStyle.commentTextSize.toFloat()
typeface = FontManager.getTypeface("comment_font")
Expand All @@ -59,20 +59,20 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
background = ColorManager.getColor("hilited_candidate_back_color")?.let { pressHighlightDrawable(it) }
if (theme.generalStyle.commentOnTop) {
add(
comment,
altLabel,
lParams(wrapContent, wrapContent) {
topOfParent()
centerHorizontally()
above(text)
above(label)

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

Expand All @@ -81,20 +81,20 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
)
} else {
add(
text,
label,
lParams(wrapContent, wrapContent) {
startOfParent()
centerVertically()
before(comment)
before(altLabel)

horizontalChainStyle = ConstraintLayout.LayoutParams.CHAIN_PACKED
horizontalBias = 0.5f
},
)
add(
comment,
altLabel,
lParams(wrapContent, wrapContent) {
after(text)
after(label)
centerVertically()
endOfParent()

Expand All @@ -105,11 +105,11 @@ class CandidateItemUi(override val ctx: Context, theme: Theme) : Ui {
}

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

fun setComment(str: String) {
comment.run {
altLabel.run {
if (str.isNotEmpty()) {
text = str
if (visibility == View.GONE) visibility = View.VISIBLE
Expand All @@ -121,11 +121,11 @@ 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) }
maybeHighlightedCandidateTextColor?.let { label.setTextColor(it) }
maybeHighlightedCommentTextColor?.let { altLabel.setTextColor(it) }
} else {
maybeCandidateTextColor?.let { text.setTextColor(it) }
maybeCommentTextColor?.let { comment.setTextColor(it) }
maybeCandidateTextColor?.let { label.setTextColor(it) }
maybeCommentTextColor?.let { altLabel.setTextColor(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ open class CompactCandidateViewAdapter(val theme: Theme) : BaseQuickAdapter<Cand
holder.idx = before + position // unused
holder.ui.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
minWidth = 0
flexGrow = 1f
flexGrow = 0f
}
}
}

0 comments on commit 904e715

Please sign in to comment.