forked from upstream-mirrors/quik
#874 - Multi selection for conversations
This commit is contained in:
@@ -48,6 +48,7 @@ import model.Message
|
||||
import model.MmsPart
|
||||
import util.MessageUtils
|
||||
import util.Preferences
|
||||
import util.extensions.anyOf
|
||||
import util.extensions.asMaybe
|
||||
import util.extensions.insertOrUpdate
|
||||
import util.extensions.map
|
||||
@@ -236,71 +237,82 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.findAll()
|
||||
}
|
||||
|
||||
override fun updateConversation(threadId: Long) {
|
||||
override fun updateConversations(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
realm.refresh()
|
||||
|
||||
val conversation = realm
|
||||
.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst() ?: return
|
||||
threadIds.forEach { threadId ->
|
||||
val conversation = realm
|
||||
.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst() ?: return
|
||||
|
||||
val messages = realm
|
||||
.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.findAll()
|
||||
val messages = realm
|
||||
.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.findAll()
|
||||
|
||||
val message = messages.firstOrNull()
|
||||
val message = messages.firstOrNull()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversation.count = messages.size
|
||||
conversation.date = message?.date ?: 0
|
||||
conversation.snippet = message?.getSummary() ?: ""
|
||||
conversation.read = message?.read ?: true
|
||||
conversation.me = message?.isMe() ?: false
|
||||
realm.executeTransaction {
|
||||
conversation.count = messages.size
|
||||
conversation.date = message?.date ?: 0
|
||||
conversation.snippet = message?.getSummary() ?: ""
|
||||
conversation.read = message?.read ?: true
|
||||
conversation.me = message?.isMe() ?: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markArchived(threadId: Long) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val conversation = realm.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst()
|
||||
override fun markArchived(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction { conversation?.archived = true }
|
||||
realm.close()
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.archived = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markUnarchived(threadId: Long) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val conversation = realm.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst()
|
||||
override fun markUnarchived(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction { conversation?.archived = false }
|
||||
realm.close()
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.archived = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markBlocked(threadId: Long) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val conversation = realm.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst()
|
||||
override fun markBlocked(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction { conversation?.blocked = true }
|
||||
realm.close()
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.blocked = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markUnblocked(threadId: Long) {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val conversation = realm.where(Conversation::class.java)
|
||||
.equalTo("id", threadId)
|
||||
.findFirst()
|
||||
override fun markUnblocked(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.equalTo("archived", false)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction { conversation?.blocked = false }
|
||||
realm.close()
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.blocked = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markAllSeen() {
|
||||
@@ -611,10 +623,10 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteConversation(threadId: Long) {
|
||||
override fun deleteConversations(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversation = realm.where(Conversation::class.java).equalTo("id", threadId).findAll()
|
||||
val messages = realm.where(Message::class.java).equalTo("threadId", threadId).findAll()
|
||||
val conversation = realm.where(Conversation::class.java).anyOf("id", threadIds).findAll()
|
||||
val messages = realm.where(Message::class.java).anyOf("threadId", threadIds).findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversation.deleteAllFromRealm()
|
||||
@@ -622,8 +634,10 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val uri = ContentUris.withAppendedId(Telephony.Threads.CONTENT_URI, threadId)
|
||||
context.contentResolver.delete(uri, null, null)
|
||||
threadIds.forEach { threadId ->
|
||||
val uri = ContentUris.withAppendedId(Telephony.Threads.CONTENT_URI, threadId)
|
||||
context.contentResolver.delete(uri, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConversationFromCp(threadId: Long): Conversation? {
|
||||
|
||||
@@ -22,7 +22,9 @@ import io.reactivex.Observable
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmModel
|
||||
import io.realm.RealmObject
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.RealmResults
|
||||
import timber.log.Timber
|
||||
|
||||
fun RealmModel.insertOrUpdate() {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
@@ -42,4 +44,13 @@ fun <T : RealmObject> RealmObject.asObservable(): Observable<T> {
|
||||
|
||||
fun <T : RealmObject> RealmResults<T>.asObservable(): Observable<RealmResults<T>> {
|
||||
return asFlowable().toObservable()
|
||||
}
|
||||
|
||||
fun <T : RealmObject> RealmQuery<T>.anyOf(fieldName: String, values: LongArray): RealmQuery<T> {
|
||||
values.forEach { Timber.v("vararg: $it") }
|
||||
|
||||
return when (values.isEmpty()) {
|
||||
true -> equalTo(fieldName, -1L)
|
||||
false -> `in`(fieldName, values.toTypedArray())
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -22,14 +22,14 @@ import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteConversation @Inject constructor(
|
||||
class DeleteConversations @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val updateBadge: UpdateBadge
|
||||
): Interactor<Long>() {
|
||||
) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.deleteConversation(params) }
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.deleteConversations(*threadIds) }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ class DeleteMessage @Inject constructor(
|
||||
.doOnNext { messageId ->
|
||||
val threadId = messageRepo.getMessage(messageId)?.threadId
|
||||
messageRepo.deleteMessage(messageId)
|
||||
threadId?.let { messageRepo.updateConversation(it) }
|
||||
threadId?.let { messageRepo.updateConversations(it) }
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversation(params) } // Update the conversation
|
||||
.doOnNext { messageRepo.updateConversations(params) } // Update the conversation
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
|
||||
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markArchived(params) }
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markArchived(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,11 +22,11 @@ import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
|
||||
class MarkBlocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markBlocked(params) }
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markBlocked(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class MarkRead @Inject constructor(
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markRead(params) }
|
||||
.doOnNext { messageRepo.updateConversation(params) } // Update the conversation
|
||||
.doOnNext { messageRepo.updateConversations(params) } // Update the conversation
|
||||
.doOnNext { notificationManager.update(params) }
|
||||
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
|
||||
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markUnarchived(params) }
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markUnarchived(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,11 +22,11 @@ import io.reactivex.Flowable
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long>() {
|
||||
class MarkUnblocked @Inject constructor(private val messageRepo: MessageRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||
return Flowable.just(Unit)
|
||||
.doOnNext { messageRepo.markUnblocked(params) }
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> messageRepo.markUnblocked(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class ReceiveMms @Inject constructor(
|
||||
if (blocked) messageRepo.deleteMessage(message.id)
|
||||
}
|
||||
}
|
||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
|
||||
@@ -50,7 +50,7 @@ class ReceiveSms @Inject constructor(
|
||||
|
||||
messageRepo.insertReceivedSms(address, body, time) // Add the message to the db
|
||||
}
|
||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) } // Update the conversation
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) } // Update the conversation
|
||||
.mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation
|
||||
.filter { conversation -> !conversation.blocked } // Don't notify for blocked conversations
|
||||
.doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary
|
||||
|
||||
@@ -34,7 +34,7 @@ class SyncMessage @Inject constructor(
|
||||
override fun buildObservable(params: Uri): Flowable<Message> {
|
||||
return Flowable.just(params)
|
||||
.mapNotNull { uri -> syncManager.syncMessage(uri) }
|
||||
.doOnNext { message -> messageRepo.updateConversation(message.threadId) }
|
||||
.doOnNext { message -> messageRepo.updateConversations(message.threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,15 +72,15 @@ interface MessageRepository {
|
||||
/**
|
||||
* Updates message-related fields in the conversation, like the date and snippet
|
||||
*/
|
||||
fun updateConversation(threadId: Long)
|
||||
fun updateConversations(vararg threadIds: Long)
|
||||
|
||||
fun markArchived(threadId: Long)
|
||||
fun markArchived(vararg threadIds: Long)
|
||||
|
||||
fun markUnarchived(threadId: Long)
|
||||
fun markUnarchived(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(threadId: Long)
|
||||
fun markBlocked(vararg threadIds: Long)
|
||||
|
||||
fun markUnblocked(threadId: Long)
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
fun markAllSeen()
|
||||
|
||||
@@ -122,6 +122,6 @@ interface MessageRepository {
|
||||
|
||||
fun deleteMessage(messageId: Long)
|
||||
|
||||
fun deleteConversation(threadId: Long)
|
||||
fun deleteConversations(vararg threadIds: Long)
|
||||
|
||||
}
|
||||
@@ -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) }
|
||||
|
||||
@@ -72,7 +72,7 @@ class BlockedViewModel : QkViewModel<BlockedView, BlockedState>(BlockedState())
|
||||
view.confirmUnblockIntent
|
||||
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnblocked.execute(threadId) }
|
||||
.subscribe { threadId -> markUnblocked.execute(listOf(threadId)) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import injection.appComponent
|
||||
import interactor.DeleteConversation
|
||||
import interactor.DeleteConversations
|
||||
import interactor.MarkArchived
|
||||
import interactor.MarkBlocked
|
||||
import interactor.MarkUnarchived
|
||||
@@ -48,7 +48,7 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
@Inject lateinit var markBlocked: MarkBlocked
|
||||
@Inject lateinit var markUnblocked: MarkUnblocked
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var deleteConversation: DeleteConversation
|
||||
@Inject lateinit var deleteConversations: DeleteConversations
|
||||
|
||||
private val conversation: Observable<Conversation>
|
||||
|
||||
@@ -76,7 +76,7 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
disposables += markUnarchived
|
||||
disposables += markBlocked
|
||||
disposables += markUnblocked
|
||||
disposables += deleteConversation
|
||||
disposables += deleteConversations
|
||||
|
||||
// Update the recipients whenever they change
|
||||
disposables += conversation
|
||||
@@ -118,8 +118,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation ->
|
||||
when (conversation.archived) {
|
||||
true -> markUnarchived.execute(conversation.id)
|
||||
false -> markArchived.execute(conversation.id)
|
||||
true -> markUnarchived.execute(listOf(conversation.id))
|
||||
false -> markArchived.execute(listOf(conversation.id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,8 +129,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation ->
|
||||
when (conversation.blocked) {
|
||||
true -> markUnblocked.execute(conversation.id)
|
||||
false -> markBlocked.execute(conversation.id)
|
||||
true -> markUnblocked.execute(listOf(conversation.id))
|
||||
false -> markBlocked.execute(listOf(conversation.id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
view.confirmDeleteIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> deleteConversation.execute(conversation.id) }
|
||||
.subscribe { conversation -> deleteConversations.execute(listOf(conversation.id)) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,29 +20,31 @@ package feature.conversations
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.view.longClicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.Navigator
|
||||
import common.base.FlowableAdapter
|
||||
import common.base.QkViewHolder
|
||||
import common.util.Colors
|
||||
import common.util.DateFormatter
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
||||
import model.Conversation
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationsAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val colors: Colors
|
||||
private val navigator: Navigator
|
||||
) : FlowableAdapter<Conversation>() {
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
val longClicks: Subject<Long> = PublishSubject.create()
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
@@ -52,6 +54,9 @@ class ConversationsAdapter @Inject constructor(
|
||||
val layoutInflater = LayoutInflater.from(context)
|
||||
val view = layoutInflater.inflate(R.layout.conversation_list_item, parent, false)
|
||||
|
||||
disposables += colors.ripple
|
||||
.subscribe { res -> view.setBackgroundResource(res) }
|
||||
|
||||
if (viewType == 1) {
|
||||
view.title.setTypeface(view.title.typeface, Typeface.BOLD)
|
||||
|
||||
@@ -70,18 +75,33 @@ class ConversationsAdapter @Inject constructor(
|
||||
val conversation = getItem(position)
|
||||
val view = viewHolder.itemView
|
||||
|
||||
view.clicks().subscribe { clicks.onNext(conversation.id) }
|
||||
view.longClicks().subscribe { longClicks.onNext(conversation.id) }
|
||||
view.clicks().subscribe {
|
||||
when (toggleSelection(conversation.id, false)) {
|
||||
true -> view.isSelected = isSelected(conversation.id)
|
||||
false -> navigator.showConversation(conversation.id)
|
||||
}
|
||||
}
|
||||
view.longClicks().subscribe {
|
||||
toggleSelection(conversation.id)
|
||||
view.isSelected = isSelected(conversation.id)
|
||||
}
|
||||
|
||||
view.isSelected = isSelected(conversation.id)
|
||||
|
||||
view.avatars.contacts = conversation.recipients
|
||||
view.title.text = conversation.getTitle()
|
||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||
view.snippet.text = when(conversation.me) {
|
||||
view.snippet.text = when (conversation.me) {
|
||||
true -> context.getString(R.string.main_sender_you, conversation.snippet)
|
||||
false -> conversation.snippet
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
override fun getItemId(index: Int): Long {
|
||||
return getItem(index).id
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.support.v7.widget.helper.ItemTouchHelper
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import com.jakewharton.rxbinding2.support.v4.widget.drawerOpen
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
@@ -37,14 +38,12 @@ import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.QkDialog
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.autoScrollToStart
|
||||
import common.util.extensions.dismissKeyboard
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.QkEditText
|
||||
import feature.conversations.ConversationItemTouchCallback
|
||||
import feature.conversations.ConversationsAdapter
|
||||
import injection.appComponent
|
||||
@@ -60,18 +59,17 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var conversationsAdapter: ConversationsAdapter
|
||||
@Inject lateinit var dialog: QkDialog
|
||||
@Inject lateinit var itemTouchCallback: ConversationItemTouchCallback
|
||||
|
||||
override val viewModelClass = MainViewModel::class
|
||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||
override val queryCancelledIntent: PublishSubject<Unit> = PublishSubject.create()
|
||||
override val composeIntent by lazy { compose.clicks() }
|
||||
override val drawerOpenIntent: Observable<Boolean> by lazy {
|
||||
drawerLayout
|
||||
.drawerOpen(Gravity.START)
|
||||
.doOnNext { dismissKeyboard() }
|
||||
}
|
||||
override val homeIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val drawerItemIntent: Observable<DrawerItem> by lazy {
|
||||
Observable.merge(listOf(
|
||||
inbox.clicks().map { DrawerItem.INBOX },
|
||||
@@ -81,15 +79,16 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
plus.clicks().map { DrawerItem.PLUS },
|
||||
help.clicks().map { DrawerItem.HELP }))
|
||||
}
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val dismissRatingIntent by lazy { rateDismiss.clicks() }
|
||||
override val rateIntent by lazy { rateOkay.clicks() }
|
||||
override val conversationClickIntent by lazy { conversationsAdapter.clicks }
|
||||
override val conversationLongClickIntent by lazy { conversationsAdapter.longClicks }
|
||||
override val conversationMenuItemIntent by lazy { dialog.adapter.menuItemClicks }
|
||||
override val conversationsSelectedIntent by lazy { conversationsAdapter.selectionChanges }
|
||||
override val confirmDeleteIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
|
||||
override val undoSwipeConversationIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val toggle by lazy { ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0) }
|
||||
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
|
||||
private val archiveSnackbar by lazy {
|
||||
Snackbar.make(drawerLayout, R.string.toast_archived, Snackbar.LENGTH_INDEFINITE).apply {
|
||||
@@ -105,9 +104,12 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.main_activity)
|
||||
viewModel.bindView(this)
|
||||
toolbarSearch.setHint(R.string.title_conversations)
|
||||
|
||||
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0).apply { syncState() }
|
||||
toggle.syncState()
|
||||
toolbar.setNavigationOnClickListener {
|
||||
dismissKeyboard()
|
||||
homeIntent.onNext(Unit)
|
||||
}
|
||||
|
||||
recyclerView.setHasFixedSize(true)
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
@@ -184,20 +186,35 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
}
|
||||
|
||||
override fun render(state: MainState) {
|
||||
toolbarSearch.isEnabled = state.page is Inbox
|
||||
toolbarSearch.setTextSize(if (state.page is Inbox) QkEditText.SIZE_PRIMARY else QkEditText.SIZE_TOOLBAR)
|
||||
|
||||
toolbar.menu.findItem(R.id.clear)?.run {
|
||||
isVisible = state.page is Inbox && state.page.showClearButton
|
||||
if (state.hasError) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
val selectedConversations = when (state.page) {
|
||||
is Inbox -> state.page.selected
|
||||
is Archived -> state.page.selected
|
||||
else -> 0
|
||||
}
|
||||
|
||||
toolbarSearch.setVisible(state.page is Inbox && state.page.selected == 0)
|
||||
toolbarTitle.setVisible(toolbarSearch.visibility != View.VISIBLE)
|
||||
|
||||
toolbar.menu.findItem(R.id.archive)?.isVisible = state.page is Inbox && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.unarchive)?.isVisible = state.page is Archived && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = selectedConversations != 0
|
||||
|
||||
syncing.setVisible(state.syncing)
|
||||
synced.setVisible(!state.syncing)
|
||||
rateLayout.setVisible(state.showRating)
|
||||
|
||||
compose.setVisible(state.page is Inbox || state.page is Archived)
|
||||
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
if (!inbox.isSelected) toolbarSearch.text = null
|
||||
showBackButton(state.page.showClearButton)
|
||||
title = getString(R.string.main_title_selected, state.page.selected)
|
||||
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
||||
conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView)
|
||||
@@ -205,24 +222,25 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
true -> R.string.inbox_search_empty_text
|
||||
false -> R.string.inbox_empty_text
|
||||
})
|
||||
compose.setVisible(true)
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
if (!archived.isSelected) toolbarSearch.setText(R.string.title_archived)
|
||||
showBackButton(state.page.showClearButton)
|
||||
title = when (state.page.selected != 0) {
|
||||
true -> getString(R.string.main_title_selected, state.page.selected)
|
||||
false -> getString(R.string.title_archived)
|
||||
}
|
||||
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
||||
conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
empty.setText(R.string.archived_empty_text)
|
||||
compose.setVisible(true)
|
||||
}
|
||||
|
||||
is Scheduled -> {
|
||||
if (!scheduled.isSelected) toolbarSearch.setText(R.string.title_scheduled)
|
||||
setTitle(R.string.title_scheduled)
|
||||
recyclerView.adapter = null
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
empty.setText(R.string.scheduled_empty_text)
|
||||
compose.setVisible(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,24 +250,24 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
}
|
||||
|
||||
inbox.isSelected = state.page is Inbox
|
||||
inboxIcon.isSelected = state.page is Inbox
|
||||
archived.isSelected = state.page is Archived
|
||||
archivedIcon.isSelected = state.page is Archived
|
||||
scheduled.isSelected = state.page is Scheduled
|
||||
scheduledIcon.isSelected = state.page is Scheduled
|
||||
|
||||
if (drawerLayout.isDrawerOpen(Gravity.START) && !state.drawerOpen) drawerLayout.closeDrawer(Gravity.START)
|
||||
else if (!drawerLayout.isDrawerVisible(Gravity.START) && state.drawerOpen) drawerLayout.openDrawer(Gravity.START)
|
||||
}
|
||||
|
||||
override fun showBackButton(show: Boolean) {
|
||||
toggle.onDrawerSlide(drawer, if (show) 1f else 0f)
|
||||
}
|
||||
|
||||
override fun clearSearch() {
|
||||
dismissKeyboard()
|
||||
toolbarSearch.text = null
|
||||
}
|
||||
|
||||
override fun showDialog(menuItems: List<common.MenuItem>) {
|
||||
dialog.adapter.data = menuItems
|
||||
dialog.show(this)
|
||||
override fun clearSelection() {
|
||||
conversationsAdapter.clearSelection()
|
||||
}
|
||||
|
||||
override fun showDeleteDialog() {
|
||||
@@ -267,12 +285,12 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.clear -> queryCancelledIntent.onNext(Unit)
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
optionsItemIntent.onNext(item.itemId)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
backPressedIntent.onNext(Unit)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.reactivex.Flowable
|
||||
import model.Conversation
|
||||
|
||||
data class MainState(
|
||||
val hasError: Boolean = false,
|
||||
val page: MainPage = Inbox(),
|
||||
val drawerOpen: Boolean = false,
|
||||
val syncing: Boolean = false,
|
||||
@@ -33,10 +34,13 @@ sealed class MainPage
|
||||
data class Inbox(
|
||||
val showClearButton: Boolean = false,
|
||||
val data: Flowable<List<Conversation>>? = null,
|
||||
val selected: Int = 0,
|
||||
val showArchivedSnackbar: Boolean = false) : MainPage()
|
||||
|
||||
data class Archived(
|
||||
val data: Flowable<List<Conversation>>? = null) : MainPage()
|
||||
val showClearButton: Boolean = false,
|
||||
val data: Flowable<List<Conversation>>? = null,
|
||||
val selected: Int = 0) : MainPage()
|
||||
|
||||
data class Scheduled(
|
||||
val data: Any? = null) : MainPage()
|
||||
@@ -18,28 +18,27 @@
|
||||
*/
|
||||
package feature.main
|
||||
|
||||
import common.MenuItem
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface MainView : QkView<MainState> {
|
||||
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val queryCancelledIntent: Observable<*>
|
||||
val composeIntent: Observable<Unit>
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
val homeIntent: Observable<*>
|
||||
val drawerItemIntent: Observable<DrawerItem>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val dismissRatingIntent: Observable<*>
|
||||
val rateIntent: Observable<*>
|
||||
val conversationClickIntent: Observable<Long>
|
||||
val conversationLongClickIntent: Observable<Long>
|
||||
val conversationMenuItemIntent: Observable<Int>
|
||||
val conversationsSelectedIntent: Observable<List<Long>>
|
||||
val confirmDeleteIntent: Observable<Unit>
|
||||
val swipeConversationIntent: Observable<Long>
|
||||
val undoSwipeConversationIntent: Observable<Unit>
|
||||
val backPressedIntent: Observable<Unit>
|
||||
|
||||
fun clearSearch()
|
||||
fun showDialog(menuItems: List<MenuItem>)
|
||||
fun clearSelection()
|
||||
fun showDeleteDialog()
|
||||
|
||||
}
|
||||
|
||||
@@ -26,12 +26,11 @@ import android.support.v4.content.ContextCompat
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.MenuItem
|
||||
import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import common.util.filter.ConversationFilter
|
||||
import injection.appComponent
|
||||
import interactor.DeleteConversation
|
||||
import interactor.DeleteConversations
|
||||
import interactor.MarkAllSeen
|
||||
import interactor.MarkArchived
|
||||
import interactor.MarkBlocked
|
||||
@@ -56,7 +55,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var conversationFilter: ConversationFilter
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markAllSeen: MarkAllSeen
|
||||
@Inject lateinit var deleteConversation: DeleteConversation
|
||||
@Inject lateinit var deleteConversations: DeleteConversations
|
||||
@Inject lateinit var markArchived: MarkArchived
|
||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||
@Inject lateinit var markBlocked: MarkBlocked
|
||||
@@ -66,11 +65,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var prefs: Preferences
|
||||
@Inject lateinit var ratingManager: RatingManager
|
||||
|
||||
private val menuArchive by lazy { MenuItem(context.getString(R.string.inbox_menu_archive), 0) }
|
||||
private val menuUnarchive by lazy { MenuItem(context.getString(R.string.inbox_menu_unarchive), 1) }
|
||||
private val menuBlock by lazy { MenuItem(context.getString(R.string.inbox_menu_block), 2) }
|
||||
private val menuDelete by lazy { MenuItem(context.getString(R.string.inbox_menu_delete), 3) }
|
||||
|
||||
private val conversations by lazy { messageRepo.getConversations() }
|
||||
|
||||
init {
|
||||
@@ -79,7 +73,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
// Now the conversations can be loaded
|
||||
conversations
|
||||
|
||||
disposables += deleteConversation
|
||||
disposables += deleteConversations
|
||||
disposables += markAllSeen
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
@@ -138,14 +132,24 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.queryCancelledIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSearch() }
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose() }
|
||||
|
||||
view.homeIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.page is Inbox && state.page.selected > 0 -> view.clearSelection()
|
||||
state.page is Inbox && state.page.showClearButton -> view.clearSearch()
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
else -> newState { it.copy(drawerOpen = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.drawerOpenIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { open -> newState { it.copy(drawerOpen = open) } }
|
||||
@@ -158,8 +162,8 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox()) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = conversations)) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
else -> {
|
||||
} // Do nothing
|
||||
@@ -168,6 +172,30 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.optionsItemIntent
|
||||
.withLatestFrom(view.conversationsSelectedIntent, { itemId, conversations ->
|
||||
when (itemId) {
|
||||
R.id.archive -> {
|
||||
markArchived.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.unarchive -> {
|
||||
markUnarchived.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.block -> {
|
||||
markBlocked.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.delete -> view.showDeleteDialog()
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.rateIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
@@ -179,29 +207,19 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { ratingManager.dismiss() }
|
||||
|
||||
view.conversationClickIntent
|
||||
.doOnNext { view.clearSearch() }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
view.conversationsSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
.withLatestFrom(state, { selected, state ->
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
}
|
||||
|
||||
view.conversationLongClickIntent
|
||||
.withLatestFrom(state, { _, mainState ->
|
||||
when (mainState.page) {
|
||||
is Inbox -> view.showDialog(listOf(menuArchive, menuBlock, menuDelete))
|
||||
is Archived -> view.showDialog(listOf(menuUnarchive, menuBlock, menuDelete))
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.conversationMenuItemIntent
|
||||
.withLatestFrom(view.conversationLongClickIntent, { actionId, threadId ->
|
||||
when (actionId) {
|
||||
menuArchive.actionId -> markArchived.execute(threadId)
|
||||
menuUnarchive.actionId -> markUnarchived.execute(threadId)
|
||||
menuBlock.actionId -> markBlocked.execute(threadId)
|
||||
menuDelete.actionId -> view.showDeleteDialog()
|
||||
is Archived -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -209,13 +227,16 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
|
||||
// Delete the conversation
|
||||
view.confirmDeleteIntent
|
||||
.withLatestFrom(view.conversationLongClickIntent, { _, threadId -> threadId })
|
||||
.withLatestFrom(view.conversationsSelectedIntent, { _, conversations -> conversations })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> deleteConversation.execute(threadId) }
|
||||
.subscribe { conversations ->
|
||||
deleteConversations.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
view.swipeConversationIntent
|
||||
.withLatestFrom(state, { threadId, state ->
|
||||
markArchived.execute(threadId) {
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = true)
|
||||
newState { it.copy(page = page) }
|
||||
@@ -224,7 +245,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
})
|
||||
.switchMap { Observable.timer(2750, TimeUnit.MILLISECONDS) }
|
||||
.withLatestFrom(state, { threadId, state ->
|
||||
markArchived.execute(threadId) {
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = false)
|
||||
newState { it.copy(page = page) }
|
||||
@@ -237,7 +258,25 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
view.undoSwipeConversationIntent
|
||||
.withLatestFrom(view.swipeConversationIntent, { _, threadId -> threadId })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnarchived.execute(threadId) }
|
||||
.subscribe { threadId -> markUnarchived.execute(listOf(threadId)) }
|
||||
|
||||
view.backPressedIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.drawerOpen -> newState { it.copy(drawerOpen = false) }
|
||||
|
||||
state.page is Inbox && state.page.selected > 0 -> view.clearSelection()
|
||||
state.page is Inbox && state.page.showClearButton -> view.clearSearch()
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
state.page !is Inbox -> newState { it.copy(page = Inbox(data = conversations)) }
|
||||
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class SendMessage @Inject constructor(
|
||||
sendMms(params.threadId, params.addresses, params.body, params.attachments)
|
||||
}
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversation(params.threadId) }
|
||||
.doOnNext { messageRepo.updateConversations(params.threadId) }
|
||||
.doOnNext { messageRepo.markUnarchived(params.threadId) }
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_material_light">
|
||||
android:color="@color/rippleLight">
|
||||
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
@@ -30,10 +30,7 @@
|
||||
<item>
|
||||
<selector>
|
||||
<item android:state_selected="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners android:radius="2dp" />
|
||||
</shape>
|
||||
<color android:color="@color/separatorLight" />
|
||||
</item>
|
||||
|
||||
<item>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
~
|
||||
~ This file is part of QKSMS.
|
||||
~
|
||||
~ QKSMS is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ QKSMS is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/rippleDark">
|
||||
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners android:radius="2dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<selector>
|
||||
<item android:state_selected="true">
|
||||
<color android:color="@color/separatorDark" />
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<color android:color="@android:color/transparent" />
|
||||
</item>
|
||||
</selector>
|
||||
</item>
|
||||
|
||||
</ripple>
|
||||
@@ -32,6 +32,7 @@
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/Toolbar"
|
||||
android:animateLayoutChanges="true"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
@@ -39,11 +40,16 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:background="@color/white">
|
||||
|
||||
<common.widget.QkTextView
|
||||
android:id="@+id/toolbarTitle"
|
||||
style="@style/ToolbarText" />
|
||||
|
||||
<common.widget.QkEditText
|
||||
android:id="@+id/toolbarSearch"
|
||||
style="@style/ToolbarText"
|
||||
android:hint="@string/title_conversations"
|
||||
app:textColorHint="tertiary"
|
||||
tools:hint="Search something"
|
||||
app:textSize="primary"
|
||||
tools:textSize="16sp" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
@@ -21,10 +21,31 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/clear"
|
||||
android:icon="@drawable/ic_cancel_black_24dp"
|
||||
android:title="@string/menu_clear"
|
||||
android:id="@+id/archive"
|
||||
android:icon="@drawable/ic_archive_black_24dp"
|
||||
android:title="@string/main_menu_archive"
|
||||
android:visible="false"
|
||||
app:showAsAction="always" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/unarchive"
|
||||
android:icon="@drawable/ic_archive_black_24dp"
|
||||
android:title="@string/main_menu_unarchive"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/block"
|
||||
android:icon="@drawable/ic_block_black_24dp"
|
||||
android:title="@string/main_menu_block"
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:icon="@drawable/ic_delete_black_24dp"
|
||||
android:title="@string/main_menu_delete"
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
@@ -21,6 +21,9 @@
|
||||
<color name="white">#FFFFFF</color>
|
||||
<color name="black">#000000</color>
|
||||
|
||||
<color name="rippleLight">#1f000000</color>
|
||||
<color name="rippleDark">#33ffffff</color>
|
||||
|
||||
<color name="statusBarLight">#F7F7F7</color>
|
||||
<color name="statusBarDark">#1a1e22</color>
|
||||
|
||||
|
||||
@@ -34,13 +34,22 @@
|
||||
<string name="setup_skip">Skip</string>
|
||||
<string name="setup_next">Continue</string>
|
||||
|
||||
<string name="menu_clear">Clear</string>
|
||||
<string name="menu_call">Call</string>
|
||||
<string name="menu_info">Details</string>
|
||||
<string name="menu_save">Save image</string>
|
||||
|
||||
<string name="main_title_selected">%d selected</string>
|
||||
<string name="main_menu_clear">Clear</string>
|
||||
<string name="main_menu_archive">Archive</string>
|
||||
<string name="main_menu_unarchive">Unarchive</string>
|
||||
<string name="main_menu_block">Block</string>
|
||||
<string name="main_menu_delete">Delete</string>
|
||||
<string name="main_syncing">Optimizing database, this might take a minute…</string>
|
||||
<string name="main_sender_you">You: %s</string>
|
||||
<string name="inbox_empty_text">Your conversations will appear here</string>
|
||||
<string name="inbox_search_empty_text">No results</string>
|
||||
<string name="archived_empty_text">Your archived conversations will appear here</string>
|
||||
<string name="scheduled_empty_text">Your scheduled messages will appear here</string>
|
||||
|
||||
<string name="drawer_inbox">Inbox</string>
|
||||
<string name="drawer_archived">Archived</string>
|
||||
@@ -55,15 +64,6 @@
|
||||
<string name="rate_okay">OKAY!</string>
|
||||
<string name="rate_dismiss">DISMISS</string>
|
||||
|
||||
<string name="inbox_empty_text">Your conversations will appear here</string>
|
||||
<string name="inbox_search_empty_text">No results</string>
|
||||
<string name="inbox_menu_archive">Archive</string>
|
||||
<string name="inbox_menu_unarchive">Unarchive</string>
|
||||
<string name="inbox_menu_block">Block</string>
|
||||
<string name="inbox_menu_delete">Delete</string>
|
||||
<string name="archived_empty_text">Your archived conversations will appear here</string>
|
||||
<string name="scheduled_empty_text">Your scheduled messages will appear here</string>
|
||||
|
||||
<string name="dialog_delete_title">Delete</string>
|
||||
<string name="dialog_delete_message">Are you sure you would like to delete this conversation?</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user