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

Handle crash in Bulk Order Update when item position is -1 #13359

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
@@ -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
Loading