diff --git a/app/build.gradle b/app/build.gradle index cc0fb5aaff..4345ddf1d9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -113,7 +113,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) def appcompat_version = "1.0.2" - def recyclerview_version = "1.0.0" + def recyclerview_version = "1.1.0-alpha06" def coordinatorlayout_version = "1.0.0" def constraintlayout_version = "1.1.3" def material_version = "1.1.0-alpha07" @@ -122,7 +122,7 @@ dependencies { def room_version = "2.1.0-rc01" def paging_version = "2.1.0" def preference_version = "1.0.0" - def work_version = "2.1.0-alpha02" + def work_version = "2.1.0-alpha03" def exif_version = "1.0.0" def billingclient_version = "2.0.0" def javamail_version = "1.6.3" @@ -143,7 +143,7 @@ dependencies { // https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview // https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview-selection implementation "androidx.recyclerview:recyclerview:$recyclerview_version" - //implementation "androidx.recyclerview:recyclerview-selection:1.1.0-alpha05" + //implementation "androidx.recyclerview:recyclerview-selection:1.1.0-alpha06" // https://mvnrepository.com/artifact/androidx.coordinatorlayout/coordinatorlayout implementation "androidx.coordinatorlayout:coordinatorlayout:$coordinatorlayout_version" diff --git a/app/src/main/java/androidx/recyclerview/selection/AutoScroller.java b/app/src/main/java/androidx/recyclerview/selection/AutoScroller.java index c3112c44b6..bd365759e7 100644 --- a/app/src/main/java/androidx/recyclerview/selection/AutoScroller.java +++ b/app/src/main/java/androidx/recyclerview/selection/AutoScroller.java @@ -16,19 +16,22 @@ package androidx.recyclerview.selection; -import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; +import static androidx.annotation.VisibleForTesting.PACKAGE_PRIVATE; import android.graphics.Point; import androidx.annotation.NonNull; import androidx.annotation.RestrictTo; +import androidx.annotation.VisibleForTesting; /** * Provides support for auto-scrolling a view. * * @hide */ -@RestrictTo(LIBRARY_GROUP) +@RestrictTo(LIBRARY) +@VisibleForTesting(otherwise = PACKAGE_PRIVATE) public abstract class AutoScroller { /** diff --git a/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java b/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java index 0635f91ad8..a513f5725a 100644 --- a/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java +++ b/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java @@ -16,7 +16,7 @@ package androidx.recyclerview.selection; -import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; import static androidx.core.util.Preconditions.checkArgument; import static androidx.core.util.Preconditions.checkState; import static androidx.recyclerview.selection.Shared.DEBUG; @@ -49,7 +49,7 @@ import java.util.Set; * * @hide */ -@RestrictTo(LIBRARY_GROUP) +@RestrictTo(LIBRARY) public class DefaultSelectionTracker extends SelectionTracker { private static final String TAG = "DefaultSelectionTracker"; @@ -296,6 +296,11 @@ public class DefaultSelectionTracker extends SelectionTracker { private void extendRange(int position, @RangeType int type) { checkState(isRangeActive(), "Range start point not set."); + if (position == RecyclerView.NO_POSITION) { + Log.w(TAG, "Invalid position: Cannot extend selection to: " + position); + return; + } + mRange.extendRange(position, type); // We're being lazy here notifying even when something might not have changed. diff --git a/app/src/main/java/androidx/recyclerview/selection/EventBridge.java b/app/src/main/java/androidx/recyclerview/selection/EventBridge.java index 6c43f7e09a..c2731063d0 100644 --- a/app/src/main/java/androidx/recyclerview/selection/EventBridge.java +++ b/app/src/main/java/androidx/recyclerview/selection/EventBridge.java @@ -16,7 +16,7 @@ package androidx.recyclerview.selection; -import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; import static androidx.annotation.VisibleForTesting.PACKAGE_PRIVATE; import static androidx.core.util.Preconditions.checkArgument; import static androidx.recyclerview.selection.Shared.VERBOSE; @@ -38,7 +38,7 @@ import androidx.recyclerview.widget.RecyclerView; * * @hide */ -@RestrictTo(LIBRARY_GROUP) +@RestrictTo(LIBRARY) @VisibleForTesting(otherwise = PACKAGE_PRIVATE) public class EventBridge { diff --git a/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java b/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java index 3736ada49c..8caf86d239 100644 --- a/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java +++ b/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java @@ -94,11 +94,17 @@ final class GestureSelectionHelper implements OnItemTouchListener { @Override /** @hide */ public boolean onInterceptTouchEvent(@NonNull RecyclerView unused, @NonNull MotionEvent e) { + // TODO(b/132447183): For some reason we're not receiving an ACTION_UP + // event after a > long-press NOT followed by a ACTION_MOVE < event. + if (mStarted) { + handleTouch(e); + } + switch (e.getActionMasked()) { case MotionEvent.ACTION_MOVE: - case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - return mStarted && mSelectionMgr.isRangeActive(); + case MotionEvent.ACTION_UP: + return mStarted; default: return false; } @@ -127,32 +133,25 @@ final class GestureSelectionHelper implements OnItemTouchListener { * so this methods return value is irrelevant to it. * */ - private boolean handleTouch(MotionEvent e) { - if (!mStarted) { - return false; - } - + private void handleTouch(MotionEvent e) { if (!mSelectionMgr.isRangeActive()) { Log.e(TAG, "Internal state of GestureSelectionHelper out of sync w/ SelectionTracker " + "(isRangeActive is false). Ignoring event and resetting state."); endSelection(); - return false; } switch (e.getActionMasked()) { case MotionEvent.ACTION_MOVE: handleMoveEvent(e); - return true; + break; case MotionEvent.ACTION_UP: handleUpEvent(); - return true; + break; case MotionEvent.ACTION_CANCEL: handleCancelEvent(); - return true; + break; } - - return false; } @Override diff --git a/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java b/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java index d032e2b2a9..002849c7ce 100644 --- a/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java +++ b/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java @@ -16,7 +16,7 @@ package androidx.recyclerview.selection; -import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; import android.view.MotionEvent; @@ -72,7 +72,7 @@ public abstract class ItemDetailsLookup { * @return true if there is an item w/ a stable ID at the event coordinates. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected boolean overItemWithSelectionKey(@NonNull MotionEvent e) { return overItem(e) && hasSelectionKey(getItemDetails(e)); } diff --git a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java index 1591ff4bf9..032fa35316 100644 --- a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java +++ b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java @@ -16,7 +16,7 @@ package androidx.recyclerview.selection; -import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; import static androidx.core.util.Preconditions.checkArgument; import android.content.Context; @@ -180,7 +180,7 @@ public abstract class SelectionTracker { public abstract boolean deselect(@NonNull K key); /** @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected abstract AdapterDataObserver getAdapterDataObserver(); /** @@ -192,7 +192,7 @@ public abstract class SelectionTracker { * work with the established anchor point to define selection ranges. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) public abstract void startRange(int position); /** @@ -208,7 +208,7 @@ public abstract class SelectionTracker { * must have been started by a call to {@link #startRange(int)}. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) public abstract void extendRange(int position); /** @@ -217,14 +217,14 @@ public abstract class SelectionTracker { * {@link #mergeProvisionalSelection()} is called first.) * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) public abstract void endRange(); /** * @return Whether or not there is a current range selection active. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) public abstract boolean isRangeActive(); /** @@ -237,7 +237,7 @@ public abstract class SelectionTracker { * @param position the anchor position. Must already be selected. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) public abstract void anchorRange(int position); /** @@ -246,7 +246,7 @@ public abstract class SelectionTracker { * @param position the end point. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected abstract void extendProvisionalRange(int position); /** @@ -254,14 +254,14 @@ public abstract class SelectionTracker { * @param newSelection * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected abstract void setProvisionalSelection(@NonNull Set newSelection); /** * Clears any existing provisional selection * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected abstract void clearProvisionalSelection(); /** @@ -269,7 +269,7 @@ public abstract class SelectionTracker { * provisional selection. * @hide */ - @RestrictTo(LIBRARY_GROUP) + @RestrictTo(LIBRARY) protected abstract void mergeProvisionalSelection(); /** @@ -769,7 +769,7 @@ public abstract class SelectionTracker { try { gestureHelper.start(); } catch (IllegalStateException ex) { - ex.printStackTrace(); + eu.faircode.email.Log.w(ex); } } } diff --git a/recyclerview-selection.patch b/recyclerview-selection.patch index 331075f7bf..3afe27c217 100644 --- a/recyclerview-selection.patch +++ b/recyclerview-selection.patch @@ -1,35 +1,29 @@ -diff --git a/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java b/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java -index 7f2a5bb2..3736ada4 100644 ---- a/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java -+++ b/app/src/main/java/androidx/recyclerview/selection/GestureSelectionHelper.java -@@ -98,7 +98,7 @@ final class GestureSelectionHelper implements OnItemTouchListener { - case MotionEvent.ACTION_MOVE: - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: -- return mStarted; -+ return mStarted && mSelectionMgr.isRangeActive(); - default: - return false; - } diff --git a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java -index ae3785df..1591ff4b 100644 +index 76087ea4..121fbd14 100644 --- a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java +++ b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java -@@ -765,7 +765,13 @@ public abstract class SelectionTracker { - new Runnable() { +@@ -488,7 +488,7 @@ public abstract class SelectionTracker { + private OnContextClickListener mOnContextClickListener; + + private BandPredicate mBandPredicate; +- private int mBandOverlayId = R.drawable.selection_band_overlay; ++ private int mBandOverlayId = eu.faircode.email.R.drawable.selection_band_overlay; + + private int[] mGestureToolTypes = new int[] { + MotionEvent.TOOL_TYPE_FINGER, +@@ -766,7 +766,11 @@ public abstract class SelectionTracker { @Override public void run() { -- gestureHelper.start(); -+ if (mSelectionPredicate.canSelectMultiple()) { + if (mSelectionPredicate.canSelectMultiple()) { +- gestureHelper.start(); + try { + gestureHelper.start(); + } catch (IllegalStateException ex) { + ex.printStackTrace(); + } -+ } + } } }, - mOnDragInitiatedListener, diff --git a/app/src/main/java/androidx/recyclerview/selection/TouchInputHandler.java b/app/src/main/java/androidx/recyclerview/selection/TouchInputHandler.java index d82812cc..48db78ec 100644 --- a/app/src/main/java/androidx/recyclerview/selection/TouchInputHandler.java