allow selecting multiple items by long pressing the first and last selection item
This commit is contained in:
parent
d2f81c3ffc
commit
0e8d61b33e
2 changed files with 11 additions and 1 deletions
|
@ -7,7 +7,7 @@ buildscript {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '4.1.11'
|
||||
propVersionName = '4.1.14'
|
||||
kotlin_version = '1.2.50'
|
||||
support_libs = '27.1.1'
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
|
|||
private val multiSelector = MultiSelector()
|
||||
private var actMode: ActionMode? = null
|
||||
private var actBarTextView: TextView? = null
|
||||
private var lastLongPressedItem = -1
|
||||
|
||||
abstract fun getActionMenuId(): Int
|
||||
|
||||
|
@ -88,6 +89,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
|
|||
notifyItemChanged(i + positionOffset)
|
||||
}
|
||||
updateTitle(cnt)
|
||||
lastLongPressedItem = -1
|
||||
}
|
||||
|
||||
protected fun setupDragListener(enable: Boolean) {
|
||||
|
@ -184,12 +186,19 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
|
|||
private val adapterListener = object : MyAdapterListener {
|
||||
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
||||
toggleItemSelection(select, position)
|
||||
lastLongPressedItem = -1
|
||||
}
|
||||
|
||||
override fun getSelectedPositions() = selectedPositions
|
||||
|
||||
override fun itemLongClicked(position: Int) {
|
||||
recyclerView.setDragSelectActive(position)
|
||||
lastLongPressedItem = if (lastLongPressedItem == -1) {
|
||||
position
|
||||
} else {
|
||||
selectItemRange(lastLongPressedItem, position, Math.min(lastLongPressedItem, position), Math.max(lastLongPressedItem, position))
|
||||
-1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,6 +237,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
|
|||
selectedPositions.clear()
|
||||
actBarTextView?.text = ""
|
||||
actMode = null
|
||||
lastLongPressedItem = -1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue