#1112 - Mark conversations read/unread

This commit is contained in:
Moez Bhatti
2018-06-12 13:42:23 -04:00
parent c41d40cbd6
commit 5ede84acf5
15 changed files with 175 additions and 23 deletions
@@ -441,7 +441,7 @@ class ComposeViewModel @Inject constructor(
.mapNotNull { conversation -> conversation.takeIf { it.isValid }?.id }
.debounce(200, TimeUnit.MILLISECONDS)
.autoDisposable(view.scope())
.subscribe { threadId -> markRead.execute(threadId) }
.subscribe { threadId -> markRead.execute(listOf(threadId)) }
// Open the attachment options
view.attachIntent
@@ -169,6 +169,12 @@ class MainActivity : QkThemedActivity(), MainView {
return
}
val markRead = when (state.page) {
is Inbox -> state.page.markRead
is Archived -> state.page.markRead
else -> true
}
val selectedConversations = when (state.page) {
is Inbox -> state.page.selected
is Archived -> state.page.selected
@@ -178,6 +184,8 @@ class MainActivity : QkThemedActivity(), MainView {
toolbarSearch.setVisible(state.page is Inbox && state.page.selected == 0 || state.page is Searching)
toolbarTitle.setVisible(toolbarSearch.visibility != View.VISIBLE)
toolbar.menu.findItem(R.id.read)?.isVisible = markRead && selectedConversations != 0
toolbar.menu.findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
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
@@ -38,6 +38,7 @@ sealed class MainPage
data class Inbox(
val showClearButton: Boolean = false,
val markRead: Boolean = false,
val data: RealmResults<Conversation>? = null,
val selected: Int = 0,
val showArchivedSnackbar: Boolean = false) : MainPage()
@@ -49,6 +50,7 @@ data class Searching(
data class Archived(
val showClearButton: Boolean = false,
val markRead: Boolean = false,
val data: RealmResults<Conversation>? = null,
val selected: Int = 0) : MainPage()
@@ -27,7 +27,9 @@ import interactor.DeleteConversations
import interactor.MarkAllSeen
import interactor.MarkArchived
import interactor.MarkBlocked
import interactor.MarkRead
import interactor.MarkUnarchived
import interactor.MarkUnread
import interactor.MigratePreferences
import interactor.SyncMessages
import io.reactivex.Observable
@@ -50,6 +52,8 @@ class MainViewModel @Inject constructor(
private val messageRepo: MessageRepository,
private val markAllSeen: MarkAllSeen,
private val deleteConversations: DeleteConversations,
private val markRead: MarkRead,
private val markUnread: MarkUnread,
private val markArchived: MarkArchived,
private val markUnarchived: MarkUnarchived,
private val markBlocked: MarkBlocked,
@@ -195,6 +199,16 @@ class MainViewModel @Inject constructor(
view.optionsItemIntent
.withLatestFrom(view.conversationsSelectedIntent, { itemId, conversations ->
when (itemId) {
R.id.read -> {
markRead.execute(conversations)
view.clearSelection()
}
R.id.unread -> {
markUnread.execute(conversations)
view.clearSelection()
}
R.id.archive -> {
markArchived.execute(conversations)
view.clearSelection()
@@ -228,16 +242,20 @@ class MainViewModel @Inject constructor(
.subscribe { ratingManager.dismiss() }
view.conversationsSelectedIntent
.map { selection -> selection.size }
.withLatestFrom(state, { selected, state ->
.withLatestFrom(state, { selection, state ->
val read = selection
.mapNotNull(messageRepo::getConversation)
.sumBy { if (it.read) -1 else 1 } >= 0
val selected = selection.size
when (state.page) {
is Inbox -> {
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
newState { copy(page = page) }
val page = state.page.copy(markRead = read, selected = selected, showClearButton = selected > 0)
newState { copy(page = page.copy(markRead = read, selected = selected, showClearButton = selected > 0)) }
}
is Archived -> {
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
val page = state.page.copy(markRead = read, selected = selected, showClearButton = selected > 0)
newState { copy(page = page) }
}
}
@@ -113,7 +113,7 @@ class QkReplyViewModel @Inject constructor(
.map { conversation -> conversation.id }
.autoDisposable(view.scope())
.subscribe { threadId ->
markRead.execute(threadId) { newState { copy(hasError = true) } }
markRead.execute(listOf(threadId)) { newState { copy(hasError = true) } }
}
// Call
@@ -216,7 +216,7 @@ class QkReplyViewModel @Inject constructor(
threadId
})
.doOnNext { threadId ->
markRead.execute(threadId) {
markRead.execute(listOf(threadId)) {
newState { copy(hasError = true) }
}
}