From 56241436787d6930fda9cd27a12424cd46303f1b Mon Sep 17 00:00:00 2001 From: DaniilBorovskiy1809 <> Date: Sat, 5 Dec 2026 20:45:45 +0300 Subject: [PATCH] Fix a crash when a profile drag ends during layout ItemTouchHelper can call clearView() from RecyclerView.dispatchLayout() when the dragged row is detached. endDrag() then finishes the selection started by the long press and notifies the rows, which RecyclerView forbids while it is laying out. Post endDrag() so the selection finishes after the layout. --- .../nekohasekai/sagernet/ui/profiles/ProfileListFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/profiles/ProfileListFragment.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/profiles/ProfileListFragment.kt index 1a234e243..ff14dfc7f 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/profiles/ProfileListFragment.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/profiles/ProfileListFragment.kt @@ -324,7 +324,9 @@ class ProfileListFragment : Fragment(R.layout.layout_profile_list) { override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { super.clearView(recyclerView, viewHolder) - adapter.endDrag() + // ItemTouchHelper may call this while the list is laying out the detached row. Finishing the + // drag's selection notifies the rows, which RecyclerView only allows after the layout. + recyclerView.post { adapter.endDrag() } } }).also { it.attachToRecyclerView(list) } }