forked from upstream-mirrors/quik
added select all actionbar item on main (inc archived) and compose activities. item becomes available when first item selected. menu item toggles select all/select none.
added indefinite timeout to archive snackbar on conversations activity when >= 10 conversations are archived at once. in case of accidental mass archive gives user more time to undo. added 'show status' menu item on compose activity that does the same as short touching on an item (exapnds it to show time, etc) but cn be applied to multiple selected items at once.
This commit is contained in:
@@ -73,6 +73,7 @@ import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.compose_activity.*
|
||||
import kotlinx.android.synthetic.main.main_activity.toolbar
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -256,6 +257,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
// Don't set the adapters unless needed
|
||||
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
||||
|
||||
toolbar.menu.findItem(R.id.select_all)?.isVisible = !state.editingMode && (messageAdapter.itemCount > 1) && state.selectedMessages != 0
|
||||
toolbar.menu.findItem(R.id.add)?.isVisible = state.editingMode
|
||||
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
&& state.query.isEmpty()
|
||||
@@ -265,6 +267,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.show_status)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
toolbar.menu.findItem(R.id.next)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
toolbar.menu.findItem(R.id.clear)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
@@ -322,6 +325,14 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
override fun clearSelection() = messageAdapter.clearSelection()
|
||||
|
||||
override fun toggleSelectAll() {
|
||||
messageAdapter.toggleSelectAll()
|
||||
}
|
||||
|
||||
override fun expandMessages(messageIds: List<Long>, expand: Boolean) {
|
||||
messageAdapter.expandMessages(messageIds, expand)
|
||||
}
|
||||
|
||||
override fun showDetails(details: String) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.compose_details_title)
|
||||
|
||||
@@ -58,6 +58,8 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val confirmDeleteIntent: Observable<List<Long>>
|
||||
|
||||
fun clearSelection()
|
||||
fun toggleSelectAll()
|
||||
fun expandMessages(messageIds: List<Long>, expand: Boolean)
|
||||
fun showDetails(details: String)
|
||||
fun requestDefaultSms()
|
||||
fun requestStoragePermission()
|
||||
|
||||
@@ -310,6 +310,12 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy() } }
|
||||
|
||||
// toggle select all / select none
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.select_all }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.toggleSelectAll() }
|
||||
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.call }
|
||||
@@ -369,15 +375,25 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
// Forward the message
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.forward }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages ->
|
||||
messages?.firstOrNull()?.let { messageRepo.getMessage(it) }?.let { message ->
|
||||
val images = message.parts.filter { it.isImage() }.mapNotNull { it.getUri() }
|
||||
navigator.showCompose(message.getText(), images)
|
||||
}
|
||||
.filter { it == R.id.forward }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages ->
|
||||
messages?.firstOrNull()?.let { messageRepo.getMessage(it) }?.let { message ->
|
||||
val images = message.parts.filter { it.isImage() }.mapNotNull { it.getUri() }
|
||||
navigator.showCompose(message.getText(), images)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
// expand message to show additional info
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.show_status }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages -> messages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { messageIds ->
|
||||
view.expandMessages(messageIds, true)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
// Show the previous search result
|
||||
view.optionsItemIntent
|
||||
|
||||
@@ -21,7 +21,6 @@ package dev.octoshrimpy.quik.feature.compose
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
@@ -315,6 +314,10 @@ class MessagesAdapter @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return getItem(position)?.id ?: -1
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val message = getItem(position) ?: return -1
|
||||
return when (message.isMe()) {
|
||||
@@ -323,6 +326,35 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleSelectAll() {
|
||||
var needToSelectAll = false
|
||||
|
||||
// if a non-selected item is found, then we need to select all, otherwise deselect all
|
||||
for (position in 0 until itemCount)
|
||||
if (!isSelected(getItemId(position))) {
|
||||
needToSelectAll = true
|
||||
break
|
||||
}
|
||||
|
||||
// select or deselect item based on if toggling all selected of deselected
|
||||
for (position in 0 until itemCount) {
|
||||
val messageId = getItemId(position)
|
||||
// if deselecting all then toggle selection (we know all items are selected)
|
||||
if (!needToSelectAll)
|
||||
toggleSelection(messageId)
|
||||
// else, selecting all, toggle if not already selected
|
||||
else if (!isSelected(messageId))
|
||||
toggleSelection(messageId)
|
||||
}
|
||||
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun expandMessages(messageIds: List<Long>, expand: Boolean) {
|
||||
messageIds.forEach { messageId -> expanded[messageId] = expand }
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the contacts in a map by the address, because the messages we're binding don't have
|
||||
* a reference to the contact.
|
||||
|
||||
Reference in New Issue
Block a user