mirror of
https://github.com/fcitx5-android/fcitx5-android.git
synced 2026-08-02 04:44:35 +08:00
Always re-bind CandidateViewHolder in PagingCandidateViewAdapter
the adapter would skip onBindViewHolder when diffCallback determines areItemsTheSame but we should always update the candidate idx
This commit is contained in:
parent
1d13d2e992
commit
35229d1258
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* SPDX-FileCopyrightText: Copyright 2024 Fcitx5 for Android Contributors
|
||||
* SPDX-FileCopyrightText: Copyright 2024-2026 Fcitx5 for Android Contributors
|
||||
*/
|
||||
|
||||
package org.fcitx.fcitx5.android.input.candidates
|
||||
@ -17,13 +17,13 @@ class CandidateViewHolder(val ui: CandidateItemUi) : RecyclerView.ViewHolder(ui.
|
||||
|
||||
fun update(newIndex: Int, newCandidate: CandidateWord) {
|
||||
idx = newIndex
|
||||
candidate = newCandidate
|
||||
ui.updateCandidate(newCandidate)
|
||||
if (candidate != newCandidate) {
|
||||
candidate = newCandidate
|
||||
ui.updateCandidate(newCandidate)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
idx = -1
|
||||
candidate = CandidateWord.Empty
|
||||
ui.updateCandidate(CandidateWord.Empty)
|
||||
update(-1, CandidateWord.Empty)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
|
||||
* SPDX-FileCopyrightText: Copyright 2021-2026 Fcitx5 for Android Contributors
|
||||
*/
|
||||
|
||||
package org.fcitx.fcitx5.android.input.candidates.expanded
|
||||
@ -17,14 +17,13 @@ open class PagingCandidateViewAdapter(val theme: Theme) :
|
||||
PagingDataAdapter<CandidateWord, CandidateViewHolder>(diffCallback) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Always re-bind all [CandidateViewHolder]s every time to make sure `idx` is up-to-date.
|
||||
* [CandidateViewHolder.update] would skip unnecessary UI updates.
|
||||
*/
|
||||
private val diffCallback = object : DiffUtil.ItemCallback<CandidateWord>() {
|
||||
override fun areItemsTheSame(oldItem: CandidateWord, newItem: CandidateWord): Boolean {
|
||||
return oldItem.text == newItem.text && oldItem.comment == newItem.comment
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: CandidateWord, newItem: CandidateWord): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
override fun areItemsTheSame(oldItem: CandidateWord, newItem: CandidateWord) = false
|
||||
override fun areContentsTheSame(oldItem: CandidateWord, newItem: CandidateWord) = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user