#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
@@ -61,6 +61,10 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
title = title // The title may have been set before layout inflation
}
override fun setTitle(titleId: Int) {
title = getString(titleId)
}
override fun setTitle(title: CharSequence?) {
super.setTitle(title)
toolbarTitle?.text = title
@@ -74,7 +78,7 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
return result
}
protected fun showBackButton(show: Boolean) {
protected open fun showBackButton(show: Boolean) {
supportActionBar?.setDisplayHomeAsUpEnabled(show)
}
@@ -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]
}
@@ -159,6 +159,15 @@ class Colors @Inject constructor(private val context: Context, private val prefs
.map { res -> getColor(res) }
.distinctUntilChanged()
val ripple: Observable<Int> = prefs.night.asObservable()
.map { night ->
when (night) {
true -> R.drawable.ripple_dark
false -> R.drawable.ripple
}
}
.distinctUntilChanged()
val field: Observable<Int> = prefs.night.asObservable()
.map { night -> if (night) R.color.fieldDark else R.color.fieldLight }
.map { res -> getColor(res) }