Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace uses of deprecated adapterPosition with bindingAdapterPosition #1354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected int getMovementFlags(RecyclerView recyclerView, EpoxyViewHolder viewHo

if (!isOtherCallbackActive && isTouchableModel(model)) {
//noinspection unchecked
return getMovementFlagsForModel((T) model, viewHolder.getAdapterPosition());
return getMovementFlagsForModel((T) model, viewHolder.getBindingAdapterPosition());
} else {
return 0;
}
Expand All @@ -72,8 +72,8 @@ protected boolean onMove(RecyclerView recyclerView, EpoxyViewHolder viewHolder,
"A controller must be provided in the constructor if dragging is enabled");
}

int fromPosition = viewHolder.getAdapterPosition();
int toPosition = target.getAdapterPosition();
int fromPosition = viewHolder.getBindingAdapterPosition();
int toPosition = target.getBindingAdapterPosition();
controller.moveModel(fromPosition, toPosition);

EpoxyModel<?> model = viewHolder.getModel();
Expand All @@ -96,7 +96,7 @@ public void onModelMoved(int fromPosition, int toPosition, T modelBeingMoved, Vi
protected void onSwiped(EpoxyViewHolder viewHolder, int direction) {
EpoxyModel<?> model = viewHolder.getModel();
View view = viewHolder.itemView;
int position = viewHolder.getAdapterPosition();
int position = viewHolder.getBindingAdapterPosition();

if (!isTouchableModel(model)) {
throw new IllegalStateException(
Expand Down Expand Up @@ -128,11 +128,11 @@ protected void onSelectedChanged(@Nullable EpoxyViewHolder viewHolder, int actio
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
holderBeingSwiped = viewHolder;
//noinspection unchecked
onSwipeStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition());
onSwipeStarted((T) model, viewHolder.itemView, viewHolder.getBindingAdapterPosition());
} else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
holderBeingDragged = viewHolder;
//noinspection unchecked
onDragStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition());
onDragStarted((T) model, viewHolder.itemView, viewHolder.getBindingAdapterPosition());
}
} else if (holderBeingDragged != null) {
//noinspection unchecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EpoxyVisibilityItem(adapterPosition: Int? = null) {

private val localVisibleRect = Rect()

var adapterPosition = RecyclerView.NO_POSITION
var bindingAdapterPosition = RecyclerView.NO_POSITION
private set

@Px
Expand Down Expand Up @@ -86,7 +86,7 @@ class EpoxyVisibilityItem(adapterPosition: Int? = null) {
fullyVisible = false
visible = false
focusedVisible = false
adapterPosition = newAdapterPosition
bindingAdapterPosition = newAdapterPosition
lastVisibleHeightNotified = null
lastVisibleWidthNotified = null
lastVisibilityNotified = null
Expand Down Expand Up @@ -198,6 +198,6 @@ class EpoxyVisibilityItem(adapterPosition: Int? = null) {
}

fun shiftBy(offsetPosition: Int) {
adapterPosition += offsetPosition
bindingAdapterPosition += offsetPosition
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,22 @@ open class EpoxyVisibilityTracker {
TAG,
"$eventOriginForDebug.processVisibilityEvents " +
"${System.identityHashCode(epoxyHolder)}, " +
"$detachEvent, ${epoxyHolder.adapterPosition}"
"$detachEvent, ${epoxyHolder.bindingAdapterPosition}"
)
}
val itemView = epoxyHolder.itemView
val id = System.identityHashCode(itemView)
var vi = visibilityIdToItemMap[id]
if (vi == null) {
// New view discovered, assign an EpoxyVisibilityItem
vi = EpoxyVisibilityItem(epoxyHolder.adapterPosition)
vi = EpoxyVisibilityItem(epoxyHolder.bindingAdapterPosition)
visibilityIdToItemMap.put(id, vi)
visibilityIdToItems.add(vi)
} else if (epoxyHolder.adapterPosition != RecyclerView.NO_POSITION &&
vi.adapterPosition != epoxyHolder.adapterPosition
} else if (epoxyHolder.bindingAdapterPosition != RecyclerView.NO_POSITION &&
vi.bindingAdapterPosition != epoxyHolder.bindingAdapterPosition
) {
// EpoxyVisibilityItem being re-used for a different adapter position
vi.reset(epoxyHolder.adapterPosition)
vi.reset(epoxyHolder.bindingAdapterPosition)
}
var changed = false
if (vi.update(itemView, recyclerView, detachEvent)) {
Expand Down Expand Up @@ -438,7 +438,7 @@ open class EpoxyVisibilityTracker {
Log.d(TAG, "onItemRangeInserted($positionStart, $itemCount)")
}
for (item in visibilityIdToItems) {
if (item.adapterPosition >= positionStart) {
if (item.bindingAdapterPosition >= positionStart) {
visibleDataChanged = true
item.shiftBy(itemCount)
}
Expand All @@ -457,7 +457,7 @@ open class EpoxyVisibilityTracker {
Log.d(TAG, "onItemRangeRemoved($positionStart, $itemCount)")
}
for (item in visibilityIdToItems) {
if (item.adapterPosition >= positionStart) {
if (item.bindingAdapterPosition >= positionStart) {
visibleDataChanged = true
item.shiftBy(-itemCount)
}
Expand Down Expand Up @@ -488,7 +488,7 @@ open class EpoxyVisibilityTracker {
Log.d(TAG, "onItemRangeMoved($fromPosition, $fromPosition, 1)")
}
for (item in visibilityIdToItems) {
val position = item.adapterPosition
val position = item.bindingAdapterPosition
if (position == fromPosition) {
// We found the item to be moved, just swap the position.
item.shiftBy(toPosition - fromPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onCheckedChanged(CompoundButton button, boolean isChecked) {
return;
}

final int adapterPosition = epoxyHolder.getAdapterPosition();
final int adapterPosition = epoxyHolder.getBindingAdapterPosition();
if (adapterPosition != RecyclerView.NO_POSITION) {
originalCheckedChangeListener
.onChecked((T) epoxyHolder.getModel(), (V) epoxyHolder.objectToBind(), button,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WrappedEpoxyModelClickListener<T : EpoxyModel<*>, V> : OnClickListener, On
val epoxyHolder = ListenersUtils.getEpoxyHolderForChildView(view)
?: error("Could not find RecyclerView holder for clicked view")

val adapterPosition = epoxyHolder.adapterPosition
val adapterPosition = epoxyHolder.bindingAdapterPosition
if (adapterPosition == RecyclerView.NO_POSITION) return null

val boundObject = epoxyHolder.objectToBind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class PreloadableViewDataProvider(
// We need the view sizes, but viewholders can be bound without actually being laid out on screen yet
ViewCompat.isAttachedToWindow(it.itemView) &&
ViewCompat.isLaidOut(it.itemView) &&
cacheKey(preloader, boundModel as T, it.adapterPosition) == cacheKey
cacheKey(preloader, boundModel as T, it.bindingAdapterPosition) == cacheKey
} else {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ private View mockModelForClicking(EpoxyModel model) {
RecyclerView recyclerMock = mock(RecyclerView.class);
EpoxyViewHolder holderMock = mock(EpoxyViewHolder.class);

when(holderMock.getAdapterPosition()).thenReturn(1);
when(holderMock.getBindingAdapterPosition()).thenReturn(1);
doReturn(recyclerMock).when(mockedView).getParent();
doReturn(holderMock).when(recyclerMock).findContainingViewHolder(mockedView);
doReturn(model).when(holderMock).getModel();

when(mockedView.getParent()).thenReturn(recyclerMock);
when(recyclerMock.findContainingViewHolder(mockedView)).thenReturn(holderMock);
when(holderMock.getAdapterPosition()).thenReturn(1);
when(holderMock.getBindingAdapterPosition()).thenReturn(1);
when(holderMock.getModel()).thenReturn(model);

View parentView = mock(View.class);
Expand Down Expand Up @@ -175,14 +175,14 @@ private CompoundButton mockCompoundButtonForClicking(EpoxyModel model) {
RecyclerView recyclerMock = mock(RecyclerView.class);
EpoxyViewHolder holderMock = mock(EpoxyViewHolder.class);

when(holderMock.getAdapterPosition()).thenReturn(1);
when(holderMock.getBindingAdapterPosition()).thenReturn(1);
doReturn(recyclerMock).when(mockedView).getParent();
doReturn(holderMock).when(recyclerMock).findContainingViewHolder(mockedView);
doReturn(model).when(holderMock).getModel();

when(mockedView.getParent()).thenReturn(recyclerMock);
when(recyclerMock.findContainingViewHolder(mockedView)).thenReturn(holderMock);
when(holderMock.getAdapterPosition()).thenReturn(1);
when(holderMock.getBindingAdapterPosition()).thenReturn(1);
when(holderMock.getModel()).thenReturn(model);

View parentView = mock(View.class);
Expand Down