Skip to content

Commit ec332d5

Browse files
committed
fix: dispatch clipboard observer updates to the main thread to prevent CalledFromWrongThreadException
1 parent f2805c0 commit ec332d5

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,20 +579,26 @@ class ClipboardHistoryView @JvmOverloads constructor(
579579

580580

581581
override fun onClipInserted(position: Int) {
582-
clipboardAdapter.refresh()
583-
if (!clipboardAdapter.isFiltering) {
584-
clipboardRecyclerView.smoothScrollToPosition(0)
582+
confirmationHandler.post {
583+
clipboardAdapter.refresh()
584+
if (!clipboardAdapter.isFiltering) {
585+
clipboardRecyclerView.smoothScrollToPosition(0)
586+
}
587+
updateEmptyView(clipboardAdapter.isFiltering)
585588
}
586-
updateEmptyView(clipboardAdapter.isFiltering)
587589
}
588590

589591
override fun onClipsRemoved(position: Int, count: Int) {
590-
clipboardAdapter.refresh()
591-
updateEmptyView(clipboardAdapter.isFiltering)
592+
confirmationHandler.post {
593+
clipboardAdapter.refresh()
594+
updateEmptyView(clipboardAdapter.isFiltering)
595+
}
592596
}
593597

594598
override fun onClipMoved(oldPosition: Int, newPosition: Int) {
595-
clipboardAdapter.refresh()
599+
confirmationHandler.post {
600+
clipboardAdapter.refresh()
601+
}
596602
}
597603

598604
override fun onSharedPreferenceChanged(prefs: SharedPreferences?, key: String?) {
@@ -603,7 +609,9 @@ class ClipboardHistoryView @JvmOverloads constructor(
603609
// Ensure settings are reloaded first
604610
Settings.getInstance().onSharedPreferenceChanged(prefs, key)
605611
clipboardHistoryManager.sortHistoryEntries()
606-
clipboardAdapter.refresh()
612+
confirmationHandler.post {
613+
clipboardAdapter.refresh()
614+
}
607615
}
608616
}
609617
}

0 commit comments

Comments
 (0)