#874 - Multi selection for conversations

This commit is contained in:
Moez Bhatti
2018-05-02 16:16:40 -04:00
parent f005be1e0b
commit e4bd882f35
30 changed files with 423 additions and 202 deletions
@@ -20,6 +20,8 @@ package common.base
import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
/**
* Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
@@ -37,6 +39,38 @@ abstract class QkAdapter<T> : RecyclerView.Adapter<QkViewHolder>() {
onDatasetChanged()
}
val selectionChanges: Subject<List<Long>> = BehaviorSubject.create()
private val selection = mutableListOf<Long>()
/**
* Toggles the selected state for a particular view
*
* If we are currently in selection mode (we have an active selection), then the state will
* toggle. If we are not in selection mode, then we will only toggle if [force]
*/
protected fun toggleSelection(id: Long, force: Boolean = true): Boolean {
if (!force && selection.isEmpty()) return false
when (selection.contains(id)) {
true -> selection.remove(id)
false -> selection.add(id)
}
selectionChanges.onNext(selection)
return true
}
protected fun isSelected(id: Long): Boolean {
return selection.contains(id)
}
fun clearSelection() {
selection.clear()
selectionChanges.onNext(selection)
notifyDataSetChanged()
}
fun getItem(position: Int): T {
return data[position]
}