From b5522cc15d4f5bd6704f486ddc38d81d80d89bfa Mon Sep 17 00:00:00 2001 From: yangjiakang Date: Thu, 25 May 2023 17:27:22 +0800 Subject: [PATCH] Replace uses of deprecated adapterPosition with bindingAdapterPosition --- .../airbnb/epoxy/EpoxyModelTouchCallback.java | 12 ++++++------ .../java/com/airbnb/epoxy/EpoxyVisibilityItem.kt | 6 +++--- .../com/airbnb/epoxy/EpoxyVisibilityTracker.kt | 16 ++++++++-------- .../WrappedEpoxyModelCheckedChangeListener.java | 2 +- .../epoxy/WrappedEpoxyModelClickListener.kt | 2 +- .../epoxy/preload/PreloadableViewDataProvider.kt | 2 +- .../com/airbnb/epoxy/ModelClickListenerTest.java | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyModelTouchCallback.java b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyModelTouchCallback.java index d33128ac26..a3c6a878db 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyModelTouchCallback.java +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyModelTouchCallback.java @@ -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; } @@ -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(); @@ -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( @@ -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 diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityItem.kt b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityItem.kt index ed093acfda..36063afb8e 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityItem.kt +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityItem.kt @@ -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 @@ -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 @@ -198,6 +198,6 @@ class EpoxyVisibilityItem(adapterPosition: Int? = null) { } fun shiftBy(offsetPosition: Int) { - adapterPosition += offsetPosition + bindingAdapterPosition += offsetPosition } } diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityTracker.kt b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityTracker.kt index b1c4973211..2638cc77b1 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityTracker.kt +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyVisibilityTracker.kt @@ -309,7 +309,7 @@ open class EpoxyVisibilityTracker { TAG, "$eventOriginForDebug.processVisibilityEvents " + "${System.identityHashCode(epoxyHolder)}, " + - "$detachEvent, ${epoxyHolder.adapterPosition}" + "$detachEvent, ${epoxyHolder.bindingAdapterPosition}" ) } val itemView = epoxyHolder.itemView @@ -317,14 +317,14 @@ open class EpoxyVisibilityTracker { 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)) { @@ -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) } @@ -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) } @@ -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) diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelCheckedChangeListener.java b/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelCheckedChangeListener.java index 6a55fc9dc7..3b3db8e290 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelCheckedChangeListener.java +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelCheckedChangeListener.java @@ -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, diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelClickListener.kt b/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelClickListener.kt index 68a06d6c8c..758ed3a8b5 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelClickListener.kt +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/WrappedEpoxyModelClickListener.kt @@ -62,7 +62,7 @@ class WrappedEpoxyModelClickListener, 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() diff --git a/epoxy-adapter/src/main/java/com/airbnb/epoxy/preload/PreloadableViewDataProvider.kt b/epoxy-adapter/src/main/java/com/airbnb/epoxy/preload/PreloadableViewDataProvider.kt index c9afa5a070..9cf48b9799 100644 --- a/epoxy-adapter/src/main/java/com/airbnb/epoxy/preload/PreloadableViewDataProvider.kt +++ b/epoxy-adapter/src/main/java/com/airbnb/epoxy/preload/PreloadableViewDataProvider.kt @@ -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 } diff --git a/epoxy-integrationtest/src/test/java/com/airbnb/epoxy/ModelClickListenerTest.java b/epoxy-integrationtest/src/test/java/com/airbnb/epoxy/ModelClickListenerTest.java index e63450ecd0..90b387e2a2 100644 --- a/epoxy-integrationtest/src/test/java/com/airbnb/epoxy/ModelClickListenerTest.java +++ b/epoxy-integrationtest/src/test/java/com/airbnb/epoxy/ModelClickListenerTest.java @@ -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); @@ -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);