Skip to content

Commit

Permalink
Merge pull request #13359 from woocommerce/issue/13358-handle-no-posi…
Browse files Browse the repository at this point in the history
…tion

Handle crash in Bulk Order Update when item position is -1
  • Loading branch information
hichamboushaba authored Jan 21, 2025
2 parents 438ecaf + 2d4a970 commit cf90e04
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.woocommerce.android.ui.orders

import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.selection.ItemDetailsLookup
import androidx.recyclerview.widget.RecyclerView
import com.woocommerce.android.ui.orders.list.OrderListAdapter
Expand All @@ -10,17 +11,24 @@ class DefaultOrderListItemLookup(private val recyclerView: RecyclerView) : ItemD
override fun getItemDetails(event: MotionEvent): ItemDetails<Long>? =
recyclerView
.findChildViewUnder(event.x, event.y)
?.let { view ->
recyclerView.getChildViewHolder(view)?.let { viewHolder ->
val position = viewHolder.bindingAdapterPosition
val item = (recyclerView.adapter as? OrderListAdapter)?.currentList?.get(position)
if (item is OrderListItemUI) {
DefaultOrderItemDetailsLookup(position, item.orderId)
} else {
null
}
?.let { view -> getDetailsFromView(view) }

private fun getDetailsFromView(view: View): ItemDetails<Long>? {
val viewHolder = recyclerView.getChildViewHolder(view) ?: return null
val position = viewHolder.bindingAdapterPosition

return when {
position == RecyclerView.NO_POSITION -> null
else -> {
val item = (recyclerView.adapter as? OrderListAdapter)?.currentList?.get(position)
if (item is OrderListItemUI) {
DefaultOrderItemDetailsLookup(position, item.orderId)
} else {
null
}
}
}
}
}

class DefaultOrderItemDetailsLookup(
Expand Down

0 comments on commit cf90e04

Please sign in to comment.