Simplify intent for drawer item clicks

This commit is contained in:
Moez Bhatti
2017-12-15 18:30:38 -05:00
parent 1773f7ed35
commit 949a59d9d4
4 changed files with 33 additions and 38 deletions
@@ -45,11 +45,14 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
override val composeIntent by lazy { compose.clicks() }
override val drawerOpenIntent by lazy { drawerLayout.drawerOpen(Gravity.START) }
override val inboxIntent by lazy { inbox.clicks() }
override val archivedIntent by lazy { archived.clicks() }
override val scheduledIntent by lazy { scheduled.clicks() }
override val blockedIntent by lazy { blocked.clicks() }
override val settingsIntent by lazy { settings.clicks() }
override val drawerItemIntent: Observable<DrawerItem> by lazy {
Observable.merge(listOf(
inbox.clicks().map { DrawerItem.INBOX },
archived.clicks().map { DrawerItem.ARCHIVED },
scheduled.clicks().map { DrawerItem.SCHEDULED },
blocked.clicks().map { DrawerItem.BLOCKED },
settings.clicks().map { DrawerItem.SETTINGS }))
}
override val deleteConversationIntent: Subject<Long> = PublishSubject.create()
override val archiveConversationIntent: Observable<Long> by lazy {
itemTouchCallback.swipes
@@ -9,12 +9,10 @@ interface MainView : QkView<MainState> {
val queryChangedIntent: Observable<CharSequence>
val composeIntent: Observable<Unit>
val drawerOpenIntent: Observable<Boolean>
val inboxIntent: Observable<Unit>
val archivedIntent: Observable<Unit>
val scheduledIntent: Observable<Unit>
val blockedIntent: Observable<Unit>
val settingsIntent: Observable<Unit>
val drawerItemIntent: Observable<DrawerItem>
val deleteConversationIntent: Subject<Long>
val archiveConversationIntent: Observable<Long>
}
}
enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS }
@@ -63,35 +63,26 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
newState { it.copy(page = Inbox(filteredConversations)) }
}
intents += view.composeIntent.subscribe {
navigator.showCompose()
newState { it.copy(drawerOpen = false) }
}
intents += view.composeIntent
.subscribe { navigator.showCompose() }
intents += view.drawerOpenIntent.filter { it }.subscribe {
newState { it.copy(drawerOpen = true) }
}
intents += view.drawerOpenIntent
.filter { it }
.subscribe { newState { it.copy(drawerOpen = true) } }
intents += view.inboxIntent.subscribe {
newState { it.copy(page = Inbox(conversations), drawerOpen = false) }
}
intents += view.archivedIntent.subscribe {
newState { it.copy(page = Archived(messageRepo.getConversations(true)), drawerOpen = false) }
}
intents += view.scheduledIntent.subscribe {
newState { it.copy(page = Scheduled(), drawerOpen = false) }
}
intents += view.blockedIntent.subscribe {
newState { it.copy(page = Blocked(), drawerOpen = false) }
}
intents += view.settingsIntent.subscribe {
navigator.showSettings()
newState { it.copy(drawerOpen = false) }
}
intents += view.drawerItemIntent
.doOnNext { newState { it.copy(drawerOpen = false) } }
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
.distinctUntilChanged()
.doOnNext {
when (it) {
DrawerItem.INBOX -> newState { it.copy(page = Inbox(conversations)) }
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked()) }
}
}
.subscribe()
intents += view.deleteConversationIntent
.subscribe { threadId -> deleteConversation.execute(threadId) }