From b8276e5233e7e23fe69d4f01d32ce61bb9361ee4 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Mon, 20 Dec 2021 18:38:51 +0100 Subject: [PATCH] Fix long click on chatty connections The RecyclerView animator cancels the touch events whenever a view is updated, which is a problem when trying to long click an active connection to show its contextual menu. --- .../remote_capture/views/EmptyRecyclerView.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/emanuelef/remote_capture/views/EmptyRecyclerView.java b/app/src/main/java/com/emanuelef/remote_capture/views/EmptyRecyclerView.java index 8ddc0a96..2d79074c 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/views/EmptyRecyclerView.java +++ b/app/src/main/java/com/emanuelef/remote_capture/views/EmptyRecyclerView.java @@ -25,6 +25,7 @@ import android.view.View; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.SimpleItemAnimator; // Adapter from https://gist.github.com/AlexZhukovich/537eaa1e3c82ef9f5d5cd22efdc80c54#file-emptyrecyclerview-java public class EmptyRecyclerView extends RecyclerView { @@ -32,14 +33,26 @@ public class EmptyRecyclerView extends RecyclerView { public EmptyRecyclerView(Context context) { super(context); + init(); } public EmptyRecyclerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); + init(); } public EmptyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + init(); + } + + private void init() { + // Disable the item change animation since it cancels the touch event, making it impossible + // to long click a continuously refreshed item. + // https://stackoverflow.com/questions/58628885/handle-touch-events-for-recyclerview-with-frequently-changing-data + ItemAnimator animator = getItemAnimator(); + if(animator instanceof SimpleItemAnimator) + ((SimpleItemAnimator)animator).setSupportsChangeAnimations(false); } private void initEmptyView() {