mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Simplify intent for drawer item clicks
This commit is contained in:
@@ -45,11 +45,14 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
|||||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||||
override val composeIntent by lazy { compose.clicks() }
|
override val composeIntent by lazy { compose.clicks() }
|
||||||
override val drawerOpenIntent by lazy { drawerLayout.drawerOpen(Gravity.START) }
|
override val drawerOpenIntent by lazy { drawerLayout.drawerOpen(Gravity.START) }
|
||||||
override val inboxIntent by lazy { inbox.clicks() }
|
override val drawerItemIntent: Observable<DrawerItem> by lazy {
|
||||||
override val archivedIntent by lazy { archived.clicks() }
|
Observable.merge(listOf(
|
||||||
override val scheduledIntent by lazy { scheduled.clicks() }
|
inbox.clicks().map { DrawerItem.INBOX },
|
||||||
override val blockedIntent by lazy { blocked.clicks() }
|
archived.clicks().map { DrawerItem.ARCHIVED },
|
||||||
override val settingsIntent by lazy { settings.clicks() }
|
scheduled.clicks().map { DrawerItem.SCHEDULED },
|
||||||
|
blocked.clicks().map { DrawerItem.BLOCKED },
|
||||||
|
settings.clicks().map { DrawerItem.SETTINGS }))
|
||||||
|
}
|
||||||
override val deleteConversationIntent: Subject<Long> = PublishSubject.create()
|
override val deleteConversationIntent: Subject<Long> = PublishSubject.create()
|
||||||
override val archiveConversationIntent: Observable<Long> by lazy {
|
override val archiveConversationIntent: Observable<Long> by lazy {
|
||||||
itemTouchCallback.swipes
|
itemTouchCallback.swipes
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ interface MainView : QkView<MainState> {
|
|||||||
val queryChangedIntent: Observable<CharSequence>
|
val queryChangedIntent: Observable<CharSequence>
|
||||||
val composeIntent: Observable<Unit>
|
val composeIntent: Observable<Unit>
|
||||||
val drawerOpenIntent: Observable<Boolean>
|
val drawerOpenIntent: Observable<Boolean>
|
||||||
val inboxIntent: Observable<Unit>
|
val drawerItemIntent: Observable<DrawerItem>
|
||||||
val archivedIntent: Observable<Unit>
|
|
||||||
val scheduledIntent: Observable<Unit>
|
|
||||||
val blockedIntent: Observable<Unit>
|
|
||||||
val settingsIntent: Observable<Unit>
|
|
||||||
val deleteConversationIntent: Subject<Long>
|
val deleteConversationIntent: Subject<Long>
|
||||||
val archiveConversationIntent: Observable<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)) }
|
newState { it.copy(page = Inbox(filteredConversations)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
intents += view.composeIntent.subscribe {
|
intents += view.composeIntent
|
||||||
navigator.showCompose()
|
.subscribe { navigator.showCompose() }
|
||||||
newState { it.copy(drawerOpen = false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
intents += view.drawerOpenIntent.filter { it }.subscribe {
|
intents += view.drawerOpenIntent
|
||||||
newState { it.copy(drawerOpen = true) }
|
.filter { it }
|
||||||
}
|
.subscribe { newState { it.copy(drawerOpen = true) } }
|
||||||
|
|
||||||
intents += view.inboxIntent.subscribe {
|
intents += view.drawerItemIntent
|
||||||
newState { it.copy(page = Inbox(conversations), drawerOpen = false) }
|
.doOnNext { newState { it.copy(drawerOpen = false) } }
|
||||||
}
|
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
|
||||||
|
.distinctUntilChanged()
|
||||||
intents += view.archivedIntent.subscribe {
|
.doOnNext {
|
||||||
newState { it.copy(page = Archived(messageRepo.getConversations(true)), drawerOpen = false) }
|
when (it) {
|
||||||
}
|
DrawerItem.INBOX -> newState { it.copy(page = Inbox(conversations)) }
|
||||||
|
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||||
intents += view.scheduledIntent.subscribe {
|
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||||
newState { it.copy(page = Scheduled(), drawerOpen = false) }
|
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked()) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
intents += view.blockedIntent.subscribe {
|
.subscribe()
|
||||||
newState { it.copy(page = Blocked(), drawerOpen = false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
intents += view.settingsIntent.subscribe {
|
|
||||||
navigator.showSettings()
|
|
||||||
newState { it.copy(drawerOpen = false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
intents += view.deleteConversationIntent
|
intents += view.deleteConversationIntent
|
||||||
.subscribe { threadId -> deleteConversation.execute(threadId) }
|
.subscribe { threadId -> deleteConversation.execute(threadId) }
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
<string name="app_name">QKSMS</string>
|
<string name="app_name">QKSMS</string>
|
||||||
|
|
||||||
|
<string name="title_archived">Archived</string>
|
||||||
|
<string name="title_scheduled">Scheduled</string>
|
||||||
|
<string name="title_blocked">Blocked</string>
|
||||||
<string name="title_settings">Settings</string>
|
<string name="title_settings">Settings</string>
|
||||||
<string name="title_conversations">Search inbox…</string>
|
<string name="title_conversations">Search inbox…</string>
|
||||||
<string name="title_compose">Type a name or number</string>
|
<string name="title_compose">Type a name or number</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user