From ecd99a08fdc737b2d697b6ca18164b7dabab6352 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 4 Oct 2021 20:10:47 +0200 Subject: [PATCH] Prevent crash --- .../recyclerview/selection/GestureRouter.java | 23 ++++++++++++- patches/SelectionTracker.patch | 32 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java b/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java index 3c25415326..edd308ada3 100644 --- a/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java +++ b/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java @@ -94,7 +94,28 @@ final class GestureRouter @Override public void onLongPress(@NonNull MotionEvent e) { - mDelegates.get(e).onLongPress(e); + try { + mDelegates.get(e).onLongPress(e); + } catch (Throwable ex) { + eu.faircode.email.Log.w(ex); + /* + java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling eu.faircode.email.FixedRecyclerView{239c688b VFED.... ........ 0,0-800,1162 #7f0a04da app:id/rvMessage}, adapter:eu.faircode.email.AdapterMessage@209415c5, layout:eu.faircode.email.FragmentMessages$7@190d7b1a, context:eu.faircode.email.ActivityView@3e8522fb + at androidx.recyclerview.widget.RecyclerView.assertNotInLayoutOrScroll(SourceFile:3) + at androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeChanged(SourceFile:1) + at androidx.recyclerview.widget.RecyclerView$AdapterDataObservable.notifyItemRangeChanged(SourceFile:3) + at androidx.recyclerview.widget.RecyclerView$Adapter.notifyItemChanged(SourceFile:2) + at androidx.recyclerview.selection.EventBridge$TrackerToAdapterBridge.onItemStateChanged(SourceFile:3) + at androidx.recyclerview.selection.DefaultSelectionTracker.notifyItemStateChanged(SourceFile:3) + at androidx.recyclerview.selection.DefaultSelectionTracker.select(SourceFile:8) + at androidx.recyclerview.selection.MotionInputHandler.selectItem(SourceFile:4) + at androidx.recyclerview.selection.TouchInputHandler.onLongPress(SourceFile:10) + at androidx.recyclerview.selection.GestureRouter.onLongPress(SourceFile:1) + at android.view.GestureDetector.dispatchLongPress(GestureDetector.java:700) + at android.view.GestureDetector.access$200(GestureDetector.java:40) + at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:273) + at android.os.Handler.dispatchMessage(Handler.java:102) + */ + } } @Override diff --git a/patches/SelectionTracker.patch b/patches/SelectionTracker.patch index 9fdbb5b11c..f6c05a4c80 100644 --- a/patches/SelectionTracker.patch +++ b/patches/SelectionTracker.patch @@ -83,3 +83,35 @@ } } }, +--- a/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java ++++ b/app/src/main/java/androidx/recyclerview/selection/GestureRouter.java +@@ -94,7 +94,28 @@ final class GestureRouter + + @Override + public void onLongPress(@NonNull MotionEvent e) { +- mDelegates.get(e).onLongPress(e); ++ try { ++ mDelegates.get(e).onLongPress(e); ++ } catch (Throwable ex) { ++ eu.faircode.email.Log.w(ex); ++ /* ++ java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling eu.faircode.email.FixedRecyclerView{239c688b VFED.... ........ 0,0-800,1162 #7f0a04da app:id/rvMessage}, adapter:eu.faircode.email.AdapterMessage@209415c5, layout:eu.faircode.email.FragmentMessages$7@190d7b1a, context:eu.faircode.email.ActivityView@3e8522fb ++ at androidx.recyclerview.widget.RecyclerView.assertNotInLayoutOrScroll(SourceFile:3) ++ at androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeChanged(SourceFile:1) ++ at androidx.recyclerview.widget.RecyclerView$AdapterDataObservable.notifyItemRangeChanged(SourceFile:3) ++ at androidx.recyclerview.widget.RecyclerView$Adapter.notifyItemChanged(SourceFile:2) ++ at androidx.recyclerview.selection.EventBridge$TrackerToAdapterBridge.onItemStateChanged(SourceFile:3) ++ at androidx.recyclerview.selection.DefaultSelectionTracker.notifyItemStateChanged(SourceFile:3) ++ at androidx.recyclerview.selection.DefaultSelectionTracker.select(SourceFile:8) ++ at androidx.recyclerview.selection.MotionInputHandler.selectItem(SourceFile:4) ++ at androidx.recyclerview.selection.TouchInputHandler.onLongPress(SourceFile:10) ++ at androidx.recyclerview.selection.GestureRouter.onLongPress(SourceFile:1) ++ at android.view.GestureDetector.dispatchLongPress(GestureDetector.java:700) ++ at android.view.GestureDetector.access$200(GestureDetector.java:40) ++ at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:273) ++ at android.os.Handler.dispatchMessage(Handler.java:102) ++ */ ++ } + } + + @Override