make sure unselecting items work on all android versions

This commit is contained in:
tibbi 2016-11-17 10:45:52 +01:00
parent 258c49eeb8
commit cc7c6a1e24
2 changed files with 12 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.adapters package com.simplemobiletools.gallery.adapters
import android.os.Build
import android.support.v7.view.ActionMode import android.support.v7.view.ActionMode
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.view.* import android.view.*
@ -24,6 +25,13 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
companion object { companion object {
var actMode: ActionMode? = null var actMode: ActionMode? = null
fun toggleItemSelection(itemView: View, select: Boolean) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
itemView.dir_frame.isSelected = select
else
itemView.dir_thumbnail.isSelected = select
}
} }
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
@ -51,7 +59,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
override fun onDestroyActionMode(actionMode: ActionMode?) { override fun onDestroyActionMode(actionMode: ActionMode?) {
super.onDestroyActionMode(actionMode) super.onDestroyActionMode(actionMode)
views.forEach { it.dir_thumbnail.isSelected = false } views.forEach { toggleItemSelection(it, false) }
} }
} }
@ -87,7 +95,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
activity.startSupportActionMode(multiSelectorCallback) activity.startSupportActionMode(multiSelectorCallback)
multiSelector.setSelected(this, true) multiSelector.setSelected(this, true)
actMode?.title = multiSelector.selectedPositions.size.toString() actMode?.title = multiSelector.selectedPositions.size.toString()
itemView.dir_thumbnail.isSelected = true toggleItemSelection(itemView, true)
} }
true true
} }
@ -98,7 +106,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
if (multiSelector.isSelectable) { if (multiSelector.isSelectable) {
val isSelected = multiSelector.selectedPositions.contains(layoutPosition) val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
multiSelector.setSelected(this, !isSelected) multiSelector.setSelected(this, !isSelected)
itemView.dir_thumbnail.isSelected = !isSelected toggleItemSelection(itemView, !isSelected)
val selectedCnt = multiSelector.selectedPositions.size val selectedCnt = multiSelector.selectedPositions.size
if (selectedCnt == 0) { if (selectedCnt == 0) {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.gallery.views.MyImageView <com.simplemobiletools.gallery.views.MyImageView
android:id="@+id/dir_thumbnail"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dir_thumbnail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:foreground="@drawable/selector"/> android:foreground="@drawable/selector"/>