forked from upstream-mirrors/quik
Undo archiving conversation
This commit is contained in:
@@ -55,15 +55,15 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
settings.clicks().map { DrawerItem.SETTINGS }))
|
||||
}
|
||||
override val deleteConversationIntent: Subject<Long> = PublishSubject.create()
|
||||
override val archiveConversationIntent: Observable<Long> by lazy {
|
||||
itemTouchCallback.swipes
|
||||
.map { position -> conversationsAdapter.getItem(position) }
|
||||
.map { pair -> pair.conversation }
|
||||
.map { conversation -> conversation.id }
|
||||
}
|
||||
override val archiveConversationIntent: Observable<Int> by lazy { itemTouchCallback.swipes }
|
||||
override val unarchiveConversationIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
|
||||
private val archiveSnackbar by lazy { Snackbar.make(drawerLayout, R.string.toast_archived, Snackbar.LENGTH_INDEFINITE) }
|
||||
private val archiveSnackbar by lazy {
|
||||
Snackbar.make(drawerLayout, R.string.toast_archived, Snackbar.LENGTH_INDEFINITE).apply {
|
||||
setAction(R.string.button_undo, { unarchiveConversationIntent.onNext(Unit) })
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
@@ -11,7 +11,8 @@ interface MainView : QkView<MainState> {
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
val drawerItemIntent: Observable<DrawerItem>
|
||||
val deleteConversationIntent: Subject<Long>
|
||||
val archiveConversationIntent: Observable<Long>
|
||||
val archiveConversationIntent: Observable<Int>
|
||||
val unarchiveConversationIntent: Subject<Unit>
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,7 @@ import android.provider.Telephony
|
||||
import com.moez.QKSMS.common.di.appComponent
|
||||
import com.moez.QKSMS.common.util.filter.ConversationFilter
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.domain.interactor.DeleteConversation
|
||||
import com.moez.QKSMS.domain.interactor.MarkAllSeen
|
||||
import com.moez.QKSMS.domain.interactor.MarkArchived
|
||||
import com.moez.QKSMS.domain.interactor.PartialSync
|
||||
import com.moez.QKSMS.domain.interactor.*
|
||||
import com.moez.QKSMS.presentation.Navigator
|
||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||
import io.reactivex.BackpressureStrategy
|
||||
@@ -28,6 +25,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var markAllSeen: MarkAllSeen
|
||||
@Inject lateinit var deleteConversation: DeleteConversation
|
||||
@Inject lateinit var markArchived: MarkArchived
|
||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
|
||||
private val conversations by lazy { messageRepo.getConversations() }
|
||||
@@ -88,7 +86,12 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
intents += view.deleteConversationIntent
|
||||
.subscribe { threadId -> deleteConversation.execute(threadId) }
|
||||
|
||||
intents += view.archiveConversationIntent
|
||||
val archivedConversation = view.archiveConversationIntent
|
||||
.withLatestFrom(conversations.toObservable(), { position, conversations -> conversations[position] })
|
||||
.map { pair -> pair.conversation }
|
||||
.map { conversation -> conversation.id }
|
||||
|
||||
intents += archivedConversation
|
||||
.withLatestFrom(state, { threadId, state ->
|
||||
markArchived.execute(threadId) {
|
||||
if (state.page is Inbox) {
|
||||
@@ -107,6 +110,10 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
}
|
||||
})
|
||||
.subscribe()
|
||||
|
||||
intents += view.unarchiveConversationIntent
|
||||
.withLatestFrom(archivedConversation, { _, threadId -> threadId })
|
||||
.subscribe { threadId -> markUnarchived.execute(threadId) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user