Updated recyclerview selection to versio 1.1.0-alpha02

pull/153/head
M66B 6 years ago
parent b87057cb21
commit dd9a9dbdb2

@ -348,7 +348,7 @@ public class DefaultSelectionTracker<K> extends SelectionTracker<K> {
} }
@Override @Override
protected AdapterDataObserver getAdapterDataObserver() { AdapterDataObserver getAdapterDataObserver() {
return mAdapterObserver; return mAdapterObserver;
} }

@ -259,7 +259,7 @@ final class GridModel<K> {
private void updateModel() { private void updateModel() {
RelativePoint old = mRelPointer; RelativePoint old = mRelPointer;
mRelPointer = createRelativePoint(mPointer); mRelPointer = createRelativePoint(mPointer);
if (mRelPointer.equals(old)) { if (old != null && mRelPointer.equals(old)) {
return; return;
} }

@ -16,13 +16,10 @@
package androidx.recyclerview.selection; package androidx.recyclerview.selection;
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import android.view.MotionEvent; import android.view.MotionEvent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
/** /**
@ -70,10 +67,8 @@ public abstract class ItemDetailsLookup<K> {
/** /**
* @return true if there is an item w/ a stable ID at the event coordinates. * @return true if there is an item w/ a stable ID at the event coordinates.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) final boolean overItemWithSelectionKey(@NonNull MotionEvent e) {
protected boolean overItemWithSelectionKey(@NonNull MotionEvent e) {
return overItem(e) && hasSelectionKey(getItemDetails(e)); return overItem(e) && hasSelectionKey(getItemDetails(e));
} }

@ -33,10 +33,18 @@ final class MotionEvents {
return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE; return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE;
} }
static boolean isTouchEvent(@NonNull MotionEvent e) {
return e.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER;
}
static boolean isActionMove(@NonNull MotionEvent e) { static boolean isActionMove(@NonNull MotionEvent e) {
return e.getActionMasked() == MotionEvent.ACTION_MOVE; return e.getActionMasked() == MotionEvent.ACTION_MOVE;
} }
static boolean isActionDown(@NonNull MotionEvent e) {
return e.getActionMasked() == MotionEvent.ACTION_DOWN;
}
static boolean isActionUp(@NonNull MotionEvent e) { static boolean isActionUp(@NonNull MotionEvent e) {
return e.getActionMasked() == MotionEvent.ACTION_UP; return e.getActionMasked() == MotionEvent.ACTION_UP;
} }

@ -16,7 +16,6 @@
package androidx.recyclerview.selection; package androidx.recyclerview.selection;
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import static androidx.core.util.Preconditions.checkArgument; import static androidx.core.util.Preconditions.checkArgument;
import android.content.Context; import android.content.Context;
@ -29,7 +28,6 @@ import android.view.MotionEvent;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver; import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener; import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
@ -179,9 +177,7 @@ public abstract class SelectionTracker<K> {
*/ */
public abstract boolean deselect(@NonNull K key); public abstract boolean deselect(@NonNull K key);
/** @hide */ abstract AdapterDataObserver getAdapterDataObserver();
@RestrictTo(LIBRARY_GROUP)
protected abstract AdapterDataObserver getAdapterDataObserver();
/** /**
* Attempts to establish a range selection at {@code position}, selecting the item * Attempts to establish a range selection at {@code position}, selecting the item
@ -190,10 +186,8 @@ public abstract class SelectionTracker<K> {
* @param position The "anchor" position for the range. Subsequent range operations * @param position The "anchor" position for the range. Subsequent range operations
* (primarily keyboard and mouse based operations like SHIFT + click) * (primarily keyboard and mouse based operations like SHIFT + click)
* work with the established anchor point to define selection ranges. * work with the established anchor point to define selection ranges.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void startRange(int position);
public abstract void startRange(int position);
/** /**
* Sets the end point for the active range selection. * Sets the end point for the active range selection.
@ -206,26 +200,20 @@ public abstract class SelectionTracker<K> {
* @param position The new end position for the selection range. * @param position The new end position for the selection range.
* @throws IllegalStateException if a range selection is not active. Range selection * @throws IllegalStateException if a range selection is not active. Range selection
* must have been started by a call to {@link #startRange(int)}. * must have been started by a call to {@link #startRange(int)}.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void extendRange(int position);
public abstract void extendRange(int position);
/** /**
* Clears an in-progress range selection. Provisional range selection established * Clears an in-progress range selection. Provisional range selection established
* using {@link #extendProvisionalRange(int)} will be cleared (unless * using {@link #extendProvisionalRange(int)} will be cleared (unless
* {@link #mergeProvisionalSelection()} is called first.) * {@link #mergeProvisionalSelection()} is called first.)
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void endRange();
public abstract void endRange();
/** /**
* @return Whether or not there is a current range selection active. * @return Whether or not there is a current range selection active.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract boolean isRangeActive();
public abstract boolean isRangeActive();
/** /**
* Establishes the "anchor" at which a selection range begins. This "anchor" is consulted * Establishes the "anchor" at which a selection range begins. This "anchor" is consulted
@ -235,42 +223,32 @@ public abstract class SelectionTracker<K> {
* TODO: Reconcile this with startRange. Maybe just docs need to be updated. * TODO: Reconcile this with startRange. Maybe just docs need to be updated.
* *
* @param position the anchor position. Must already be selected. * @param position the anchor position. Must already be selected.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void anchorRange(int position);
public abstract void anchorRange(int position);
/** /**
* Creates a provisional selection from anchor to {@code position}. * Creates a provisional selection from anchor to {@code position}.
* *
* @param position the end point. * @param position the end point.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void extendProvisionalRange(int position);
protected abstract void extendProvisionalRange(int position);
/** /**
* Sets the provisional selection, replacing any existing selection. * Sets the provisional selection, replacing any existing selection.
* @param newSelection * @param newSelection
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void setProvisionalSelection(@NonNull Set<K> newSelection);
protected abstract void setProvisionalSelection(@NonNull Set<K> newSelection);
/** /**
* Clears any existing provisional selection * Clears any existing provisional selection
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void clearProvisionalSelection();
protected abstract void clearProvisionalSelection();
/** /**
* Converts the provisional selection into primary selection, then clears * Converts the provisional selection into primary selection, then clears
* provisional selection. * provisional selection.
* @hide
*/ */
@RestrictTo(LIBRARY_GROUP) abstract void mergeProvisionalSelection();
protected abstract void mergeProvisionalSelection();
/** /**
* Preserves selection, if any. Call this method from Activity#onSaveInstanceState * Preserves selection, if any. Call this method from Activity#onSaveInstanceState

@ -21,10 +21,12 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.collection.LongSparseArray;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener; import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener;
import java.util.HashMap;
import java.util.Map;
/** /**
* An {@link ItemKeyProvider} that provides stable ids by way of cached * An {@link ItemKeyProvider} that provides stable ids by way of cached
* {@link RecyclerView.Adapter} stable ids. Items enter the cache as they are laid out by * {@link RecyclerView.Adapter} stable ids. Items enter the cache as they are laid out by
@ -38,7 +40,7 @@ import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListene
public final class StableIdKeyProvider extends ItemKeyProvider<Long> { public final class StableIdKeyProvider extends ItemKeyProvider<Long> {
private final SparseArray<Long> mPositionToKey = new SparseArray<>(); private final SparseArray<Long> mPositionToKey = new SparseArray<>();
private final LongSparseArray<Integer> mKeyToPosition = new LongSparseArray<>(); private final Map<Long, Integer> mKeyToPosition = new HashMap<Long, Integer>();
private final RecyclerView mRecyclerView; private final RecyclerView mRecyclerView;
/** /**
@ -100,6 +102,9 @@ public final class StableIdKeyProvider extends ItemKeyProvider<Long> {
@Override @Override
public int getPosition(@NonNull Long key) { public int getPosition(@NonNull Long key) {
return mKeyToPosition.get(key, RecyclerView.NO_POSITION); if (mKeyToPosition.containsKey(key)) {
return mKeyToPosition.get(key);
}
return RecyclerView.NO_POSITION;
} }
} }

@ -116,9 +116,9 @@
* <b>Include Selection in Activity lifecycle events</b> * <b>Include Selection in Activity lifecycle events</b>
* *
* <p> * <p>
* In order to preserve state, the author must include the selection library in the handling * In order to preserve state the author must the selection library in handling
* of Activity lifecycle events. See SelectionTracker#onSaveInstanceState and * of Activity lifecycle events. See SelectionTracker#onSaveInstanceState
* SelectionTracker#onRestoreInstanceState. * and SelectionTracker#onRestoreInstanceState.
* *
* <p>A unique selection id must be supplied to * <p>A unique selection id must be supplied to
* {@link androidx.recyclerview.selection.SelectionTracker.Builder SelectionTracker.Builder} * {@link androidx.recyclerview.selection.SelectionTracker.Builder SelectionTracker.Builder}

Loading…
Cancel
Save