make sure we dont select unselectable items at recyclerviews, like section titles

This commit is contained in:
tibbi 2018-06-22 12:24:13 +02:00
parent 1c0b3d416f
commit ec10a6b7c8
3 changed files with 13 additions and 3 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '4.2.9'
propVersionName = '4.2.10'
kotlin_version = '1.2.50'
support_libs = '27.1.1'
}

View file

@ -51,6 +51,8 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis
override fun getSelectableItemCount() = fileDirItems.size
override fun getIsItemSelectable(position: Int) = false
override fun onViewRecycled(holder: MyRecyclerViewAdapter.ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) {

View file

@ -49,9 +49,15 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
abstract fun getSelectableItemCount(): Int
abstract fun getIsItemSelectable(position: Int): Boolean
protected fun isOneItemSelected() = selectedPositions.size == 1
protected fun toggleItemSelection(select: Boolean, pos: Int) {
if (select && !getIsItemSelectable(pos)) {
return
}
if (select) {
if (viewHolders[pos] != null) {
prepareItemSelection(viewHolders[pos])
@ -85,8 +91,10 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
protected fun selectAll() {
val cnt = itemCount - positionOffset
for (i in 0 until cnt) {
selectedPositions.add(i)
notifyItemChanged(i + positionOffset)
if (getIsItemSelectable(i)) {
selectedPositions.add(i)
notifyItemChanged(i + positionOffset)
}
}
updateTitle(cnt)
lastLongPressedItem = -1