public static int safeGetLayoutPosition(@Nullable RecyclerView.ViewHolder holder) { return (holder != null) ? holder.getLayoutPosition() : RecyclerView.NO_POSITION; }
private void updateSwapTargetTranslation(RecyclerView.ViewHolder draggingItem, RecyclerView.ViewHolder swapTargetItem, float translationPhase) { final View swapItemView = swapTargetItem.itemView; final int pos1 = draggingItem.getLayoutPosition(); final int pos2 = swapTargetItem.getLayoutPosition();
@Override public boolean animateChange( RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { if (oldHolder == newHolder) { // NOTE: This condition can be occurred since v23.1.0. // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. return mMoveAnimationsManager.addPendingAnimation(oldHolder, fromX, fromY, toX, toY); } if (mDebug) { final String oldId = (oldHolder != null) ? Long.toString(oldHolder.getItemId()) : "-"; final String oldPosition = (oldHolder != null) ? Long.toString(oldHolder.getLayoutPosition()) : "-"; final String newId = (newHolder != null) ? Long.toString(newHolder.getItemId()) : "-"; final String newPosition = (newHolder != null) ? Long.toString(newHolder.getLayoutPosition()) : "-"; Log.d(TAG, "animateChange(old.id = " + oldId + ", old.position = " + oldPosition + ", new.id = " + newId + ", new.position = " + newPosition + ", fromX = " + fromX + ", fromY = " + fromY + ", toX = " + toX + ", toY = " + toY + ")"); } return mChangeAnimationsManager.addPendingAnimation(oldHolder, newHolder, fromX, fromY, toX, toY); }
private float calculateTranslationPhase(RecyclerView.ViewHolder draggingItem, RecyclerView.ViewHolder swapTargetItem) { final View swapItemView = swapTargetItem.itemView; final int pos1 = draggingItem.getLayoutPosition(); final int pos2 = swapTargetItem.getLayoutPosition();
final View toView = swapTargetHolder.itemView; final View firstView = CustomRecyclerViewUtils.findViewByPosition(layoutManager, firstVisible); final int rootFromPosition = (draggingItemHolder != null) ? draggingItemHolder.getLayoutPosition() : RecyclerView.NO_POSITION; final int rootToPosition = swapTargetHolder.getLayoutPosition(); final Integer fromOrigin = getItemViewOrigin(fromView, isVertical); final Integer toOrigin = getItemViewOrigin(toView, isVertical);
private static View findRangeLastItem(RecyclerView rv, ItemDraggableRange range, int firstVisiblePosition, int lastVisiblePosition) { if (firstVisiblePosition == RecyclerView.NO_POSITION || lastVisiblePosition == RecyclerView.NO_POSITION) { return null; } View v = null; final int childCount = rv.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { final View v2 = rv.getChildAt(i); final RecyclerView.ViewHolder vh = rv.getChildViewHolder(v2); if (vh != null) { final int position = vh.getLayoutPosition(); if ((position >= firstVisiblePosition) && (position <= lastVisiblePosition) && range.checkInRange(position)) { v = v2; break; } } } return v; }
private static View findRangeFirstItem(RecyclerView rv, ItemDraggableRange range, int firstVisiblePosition, int lastVisiblePosition) { if (firstVisiblePosition == RecyclerView.NO_POSITION || lastVisiblePosition == RecyclerView.NO_POSITION) { return null; } View v = null; final int childCount = rv.getChildCount(); for (int i = 0; i < childCount; i++) { final View v2 = rv.getChildAt(i); final RecyclerView.ViewHolder vh = rv.getChildViewHolder(v2); if (vh != null) { final int position = vh.getLayoutPosition(); if ((position >= firstVisiblePosition) && (position <= lastVisiblePosition) && range.checkInRange(position)) { v = v2; break; } } } return v; }
@Override public boolean animateAdd(final RecyclerView.ViewHolder holder) { if (mDebug) { Log.d(TAG, "animateAdd(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ")"); } return mAddAnimationsManager.addPendingAnimation(holder); }
@Override public void onAnimationUpdate(View view) { float translation = mHorizontal ? view.getTranslationX() : view.getTranslationY(); float amount = translation * mInvSize; mAdapter.onUpdateSlideAmount(mViewHolder, mViewHolder.getLayoutPosition(), amount, true, mHorizontal, false); }
@Override public boolean animateRemove(final RecyclerView.ViewHolder holder) { if (mDebug) { Log.d(TAG, "animateRemove(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ")"); } return mRemoveAnimationManager.addPendingAnimation(holder); }
@Override public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) { if (mDebug) { Log.d(TAG, "animateMove(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ", fromX = " + fromX + ", fromY = " + fromY + ", toX = " + toX + ", toY = " + toY + ")"); } return mMoveAnimationsManager.addPendingAnimation(holder, fromX, fromY, toX, toY); }
public static int getSynchronizedPosition(@NonNull RecyclerView.ViewHolder holder) { int pos1 = holder.getLayoutPosition(); int pos2 = holder.getAdapterPosition(); if (pos1 == pos2) { return pos1; } else { return RecyclerView.NO_POSITION; } }