Skip to content

Commit 098a031

Browse files
committed
Tweak CandidatesView pagination layout
1 parent 8ed5609 commit 098a031

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/src/main/java/org/fcitx/fcitx5/android/input/candidates/floating/PagedCandidatesUi.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package org.fcitx.fcitx5.android.input.candidates.floating
88
import android.annotation.SuppressLint
99
import android.content.Context
1010
import android.view.ViewGroup
11+
import androidx.core.view.updateLayoutParams
1112
import androidx.recyclerview.widget.RecyclerView
1213
import com.google.android.flexbox.AlignItems
1314
import com.google.android.flexbox.FlexDirection
@@ -16,14 +17,15 @@ import com.google.android.flexbox.FlexboxLayoutManager
1617
import org.fcitx.fcitx5.android.core.FcitxEvent
1718
import org.fcitx.fcitx5.android.core.FcitxEvent.PagedCandidateEvent.LayoutHint
1819
import org.fcitx.fcitx5.android.data.theme.Theme
19-
import splitties.dimensions.dp
2020
import splitties.views.dsl.core.Ui
2121
import splitties.views.dsl.recyclerview.recyclerView
2222

2323
class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
2424

2525
private var data = FcitxEvent.PagedCandidateEvent.Data.Empty
2626

27+
private var isVertical = false
28+
2729
sealed class UiHolder(open val ui: Ui) : RecyclerView.ViewHolder(ui.root) {
2830
class Candidate(override val ui: LabeledCandidateItemUi) : UiHolder(ui)
2931
class Pagination(override val ui: PaginationUi) : UiHolder(ui)
@@ -42,8 +44,6 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
4244
val wrap = ViewGroup.LayoutParams.WRAP_CONTENT
4345
ui.root.layoutParams = FlexboxLayoutManager.LayoutParams(wrap, wrap).apply {
4446
flexGrow = 1f
45-
alignSelf = AlignItems.STRETCH
46-
minHeight = ctx.dp(20)
4747
}
4848
}
4949
}
@@ -57,6 +57,9 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
5757
}
5858
is UiHolder.Pagination -> {
5959
holder.ui.update(data)
60+
holder.ui.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
61+
alignSelf = if (isVertical) AlignItems.STRETCH else AlignItems.CENTER
62+
}
6063
}
6164
}
6265
}
@@ -78,10 +81,9 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
7881
orientation: FloatingCandidatesOrientation
7982
) {
8083
this.data = data
81-
val isVertical = when (orientation) {
84+
this.isVertical = when (orientation) {
8285
FloatingCandidatesOrientation.Automatic -> data.layoutHint == LayoutHint.Vertical
83-
FloatingCandidatesOrientation.Horizontal -> false
84-
FloatingCandidatesOrientation.Vertical -> true
86+
else -> orientation == FloatingCandidatesOrientation.Vertical
8587
}
8688
candidatesLayoutManager.apply {
8789
if (isVertical) {

app/src/main/java/org/fcitx/fcitx5/android/input/candidates/floating/PaginationUi.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import splitties.views.dsl.constraintlayout.centerVertically
2020
import splitties.views.dsl.constraintlayout.constraintLayout
2121
import splitties.views.dsl.constraintlayout.endOfParent
2222
import splitties.views.dsl.constraintlayout.lParams
23-
import splitties.views.dsl.constraintlayout.matchConstraints
2423
import splitties.views.dsl.core.Ui
2524
import splitties.views.dsl.core.add
2625
import splitties.views.dsl.core.imageView
@@ -40,11 +39,13 @@ class PaginationUi(override val ctx: Context, val theme: Theme) : Ui {
4039
private val disabledAlpha = styledFloat(android.R.attr.disabledAlpha)
4140

4241
override val root = constraintLayout {
43-
add(nextIcon, lParams(dp(10), matchConstraints) {
42+
val w = dp(10)
43+
val h = dp(20)
44+
add(nextIcon, lParams(w, h) {
4445
centerVertically()
4546
endOfParent()
4647
})
47-
add(prevIcon, lParams(dp(10), matchConstraints) {
48+
add(prevIcon, lParams(w, h) {
4849
centerVertically()
4950
before(nextIcon)
5051
})

0 commit comments

Comments
 (0)