@@ -23,6 +23,9 @@ import splitties.views.dsl.recyclerview.recyclerView
23
23
class PagedCandidatesUi (
24
24
override val ctx : Context ,
25
25
val theme : Theme ,
26
+ private val onCandidateClick : (Int ) -> Unit ,
27
+ private val onPrevPage : () -> Unit ,
28
+ private val onNextPage : () -> Unit ,
26
29
) : Ui {
27
30
private var menu = RimeProto .Context .Menu ()
28
31
@@ -40,19 +43,7 @@ class PagedCandidatesUi(
40
43
) : UiHolder(ui)
41
44
}
42
45
43
- enum class ClickType {
44
- CANDIDATE ,
45
- PREV_PAGE ,
46
- NEXT_PAGE ,
47
- }
48
-
49
- private var clickListener: ((type: ClickType , position: Int ) -> Unit )? = null
50
-
51
- fun setOnClickListener (listener : (type: ClickType , position: Int ) -> Unit ) {
52
- clickListener = listener
53
- }
54
-
55
- val candidatesAdapter =
46
+ private val candidatesAdapter =
56
47
object : BaseQuickAdapter <RimeProto .Candidate , UiHolder >() {
57
48
override fun getItemCount (items : List <RimeProto .Candidate >) =
58
49
items.size + (if (menu.pageNumber != 0 || ! menu.isLastPage) 1 else 0 )
@@ -89,7 +80,7 @@ class PagedCandidatesUi(
89
80
val candidate = item ? : return
90
81
holder.ui.update(candidate, position == menu.highlightedCandidateIndex)
91
82
holder.ui.root.setOnClickListener {
92
- clickListener? .invoke(ClickType . CANDIDATE , position)
83
+ onCandidateClick .invoke(position)
93
84
}
94
85
}
95
86
is UiHolder .Pagination -> {
@@ -99,10 +90,10 @@ class PagedCandidatesUi(
99
90
alignSelf = if (isHorizontal) AlignItems .CENTER else AlignItems .STRETCH
100
91
}
101
92
holder.ui.prevIcon.setOnClickListener {
102
- clickListener? .invoke(ClickType . PREV_PAGE , menu.pageNumber )
93
+ onPrevPage .invoke()
103
94
}
104
95
holder.ui.nextIcon.setOnClickListener {
105
- clickListener? .invoke(ClickType . NEXT_PAGE , menu.pageNumber )
96
+ onNextPage .invoke()
106
97
}
107
98
}
108
99
}
0 commit comments