Skip to content

Commit 1aea201

Browse files
committed
refactor: restore the style for SwitchesUi
feat: always apply `candidate_view_height` plus `comment_height` as bar view height
1 parent 9e38094 commit 1aea201

File tree

5 files changed

+88
-12
lines changed

5 files changed

+88
-12
lines changed

app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class QuickBar(context: Context, service: TrimeInputMethodService, rime: RimeSes
3838

3939
private val showSwitchers get() = prefs.keyboard.switchesEnabled
4040

41+
val themedHeight =
42+
theme.generalStyle.candidateViewHeight + theme.generalStyle.commentHeight
43+
4144
private fun evalAlwaysUiState() {
4245
val newState =
4346
when {

app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchUi.kt

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55
package com.osfans.trime.ime.bar.ui.always.switches
66

77
import android.content.Context
8+
import android.view.View
89
import com.osfans.trime.data.theme.ColorManager
910
import com.osfans.trime.data.theme.FontManager
1011
import com.osfans.trime.data.theme.Theme
12+
import splitties.dimensions.dp
13+
import splitties.views.dsl.constraintlayout.above
14+
import splitties.views.dsl.constraintlayout.after
15+
import splitties.views.dsl.constraintlayout.before
16+
import splitties.views.dsl.constraintlayout.below
17+
import splitties.views.dsl.constraintlayout.bottomOfParent
18+
import splitties.views.dsl.constraintlayout.centerHorizontally
19+
import splitties.views.dsl.constraintlayout.centerVertically
20+
import splitties.views.dsl.constraintlayout.constraintLayout
21+
import splitties.views.dsl.constraintlayout.endOfParent
22+
import splitties.views.dsl.constraintlayout.lParams
23+
import splitties.views.dsl.constraintlayout.startOfParent
24+
import splitties.views.dsl.constraintlayout.topOfParent
1125
import splitties.views.dsl.core.Ui
1226
import splitties.views.dsl.core.add
13-
import splitties.views.dsl.core.frameLayout
14-
import splitties.views.dsl.core.lParams
1527
import splitties.views.dsl.core.textView
16-
import splitties.views.gravityCenter
28+
import splitties.views.dsl.core.wrapContent
1729

1830
class SwitchUi(override val ctx: Context, private val theme: Theme) : Ui {
1931
var enabled: Int = -1
@@ -25,12 +37,64 @@ class SwitchUi(override val ctx: Context, private val theme: Theme) : Ui {
2537
ColorManager.getColor("candidate_text_color")?.let { setTextColor(it) }
2638
}
2739

40+
private val altLabel =
41+
textView {
42+
textSize = theme.generalStyle.commentTextSize.toFloat()
43+
typeface = FontManager.getTypeface("comment_font")
44+
ColorManager.getColor("comment_text_color")?.let { setTextColor(it) }
45+
visibility = View.GONE
46+
}
47+
2848
override val root =
29-
frameLayout {
30-
add(label, lParams { gravity = gravityCenter })
49+
constraintLayout {
50+
layoutParams = lParams(wrapContent, wrapContent)
51+
if (theme.generalStyle.commentOnTop) {
52+
add(
53+
altLabel,
54+
lParams(wrapContent, wrapContent) {
55+
bottomMargin = dp(-3)
56+
topOfParent()
57+
above(label)
58+
centerHorizontally()
59+
},
60+
)
61+
add(
62+
label,
63+
lParams(wrapContent, wrapContent) {
64+
topMargin = dp(-3)
65+
below(altLabel)
66+
centerHorizontally()
67+
bottomOfParent()
68+
},
69+
)
70+
} else {
71+
add(
72+
label,
73+
lParams(wrapContent, wrapContent) {
74+
startOfParent()
75+
before(altLabel)
76+
centerVertically()
77+
},
78+
)
79+
add(
80+
altLabel,
81+
lParams(wrapContent, wrapContent) {
82+
after(label)
83+
centerVertically()
84+
endOfParent()
85+
},
86+
)
87+
}
3188
}
3289

3390
fun setLabel(str: String) {
3491
label.text = str
3592
}
93+
94+
fun setAltLabel(str: String) {
95+
altLabel.text = str
96+
if (altLabel.visibility == View.GONE) {
97+
altLabel.visibility = View.VISIBLE
98+
}
99+
}
36100
}

app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchesAdapter.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import android.content.Context
88
import android.view.ViewGroup
99
import androidx.recyclerview.widget.RecyclerView
1010
import com.chad.library.adapter4.BaseQuickAdapter
11+
import com.osfans.trime.data.prefs.AppPrefs
1112
import com.osfans.trime.data.schema.Schema
1213
import com.osfans.trime.data.theme.Theme
1314

1415
class SwitchesAdapter(private val theme: Theme) :
1516
BaseQuickAdapter<Schema.Switch, SwitchesAdapter.Holder>() {
17+
private val showArrow = AppPrefs.defaultInstance().keyboard.switchArrowEnabled
18+
1619
inner class Holder(val ui: SwitchUi) : RecyclerView.ViewHolder(ui.root)
1720

1821
override fun onCreateViewHolder(
@@ -31,6 +34,17 @@ class SwitchesAdapter(private val theme: Theme) :
3134
holder.ui.apply {
3235
val enabled = item!!.enabled
3336
setLabel(item.states!![enabled])
37+
if (item.options.isNullOrEmpty()) {
38+
val text =
39+
item.states[1 - enabled].let {
40+
if (showArrow) {
41+
"$it"
42+
} else {
43+
it
44+
}
45+
}
46+
setAltLabel(text)
47+
}
3448
}
3549
}
3650
}

app/src/main/java/com/osfans/trime/ime/core/InputView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class InputView(
197197
)
198198
add(
199199
quickBar.view,
200-
lParams(matchParent, wrapContent) {
200+
lParams(matchParent, dp(quickBar.themedHeight)) {
201201
topOfParent()
202202
centerHorizontally()
203203
},

app/src/main/java/com/osfans/trime/ime/text/Candidate.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,7 @@ class Candidate(
112112
widthMeasureSpec: Int,
113113
heightMeasureSpec: Int,
114114
) {
115-
val h =
116-
if (shouldShowComment && isCommentOnTop) {
117-
candidateViewHeight + commentHeight
118-
} else {
119-
candidateViewHeight
120-
}
115+
val h = candidateViewHeight + commentHeight
121116
setMeasuredDimension(
122117
MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpec.UNSPECIFIED),
123118
MeasureSpec.makeMeasureSpec(h, MeasureSpec.AT_MOST),

0 commit comments

Comments
 (0)