|
@@ -57,7 +57,10 @@ internal class MultiChoiceViewHolder(
|
|
|
titleView.isEnabled = value
|
|
|
}
|
|
|
|
|
|
- override fun onClick(view: View) = adapter.itemClicked(adapterPosition)
|
|
|
+ override fun onClick(view: View) {
|
|
|
+ if (adapterPosition < 0) return
|
|
|
+ adapter.itemClicked(adapterPosition)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -73,7 +76,8 @@ internal class MultiChoiceDialogAdapter(
|
|
|
private val waitForActionButton: Boolean,
|
|
|
private val allowEmptySelection: Boolean,
|
|
|
internal var selection: MultiChoiceListener
|
|
|
-) : RecyclerView.Adapter<MultiChoiceViewHolder>(), DialogAdapter<CharSequence, MultiChoiceListener> {
|
|
|
+) : RecyclerView.Adapter<MultiChoiceViewHolder>(),
|
|
|
+ DialogAdapter<CharSequence, MultiChoiceListener> {
|
|
|
|
|
|
private var currentSelection: IntArray = initialSelection
|
|
|
set(value) {
|
|
@@ -201,7 +205,12 @@ internal class MultiChoiceDialogAdapter(
|
|
|
|
|
|
override fun checkItems(indices: IntArray) {
|
|
|
val existingSelection = this.currentSelection
|
|
|
- val indicesToAdd = indices.filter { !existingSelection.contains(it) }
|
|
|
+ val indicesToAdd = indices.filter {
|
|
|
+ check(it >= 0 && it < items.size) {
|
|
|
+ "Index $it is out of range for this adapter of ${items.size} items."
|
|
|
+ }
|
|
|
+ !existingSelection.contains(it)
|
|
|
+ }
|
|
|
this.currentSelection = this.currentSelection.appendAll(indicesToAdd)
|
|
|
if (existingSelection.isEmpty()) {
|
|
|
dialog.setActionButtonEnabled(POSITIVE, true)
|
|
@@ -210,7 +219,12 @@ internal class MultiChoiceDialogAdapter(
|
|
|
|
|
|
override fun uncheckItems(indices: IntArray) {
|
|
|
val existingSelection = this.currentSelection
|
|
|
- val indicesToAdd = indices.filter { existingSelection.contains(it) }
|
|
|
+ val indicesToAdd = indices.filter {
|
|
|
+ check(it >= 0 && it < items.size) {
|
|
|
+ "Index $it is out of range for this adapter of ${items.size} items."
|
|
|
+ }
|
|
|
+ existingSelection.contains(it)
|
|
|
+ }
|
|
|
this.currentSelection = this.currentSelection.removeAll(indicesToAdd)
|
|
|
.also {
|
|
|
if (it.isEmpty()) {
|