forked from upstream-mirrors/quik
Use View to expose Intents instead of performing logic inside of Activity
This commit is contained in:
+13
-11
@@ -7,7 +7,7 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.ActionBarDrawerToggle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.RxView
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.karumi.dexter.Dexter
|
||||
import com.karumi.dexter.MultiplePermissionsReport
|
||||
import com.karumi.dexter.PermissionToken
|
||||
@@ -29,28 +29,30 @@ class ConversationsActivity : QkActivity(), ConversationsView {
|
||||
|
||||
private lateinit var viewModel: ConversationsViewModel
|
||||
|
||||
override val composeIntent by lazy { compose.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 fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
setContentView(R.layout.conversation_list_activity)
|
||||
ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0).syncState()
|
||||
|
||||
onNewIntent(intent)
|
||||
requestPermissions()
|
||||
|
||||
viewModel = ViewModelProviders.of(this)[ConversationsViewModel::class.java]
|
||||
viewModel.state.observe(this, Observer { it?.let { render(it) } })
|
||||
viewModel.view = this
|
||||
viewModel.setView(this)
|
||||
|
||||
conversationList.layoutManager = LinearLayoutManager(this)
|
||||
|
||||
swipeRefresh.setOnRefreshListener { viewModel.onRefresh() }
|
||||
RxView.clicks(compose).subscribe { }
|
||||
RxView.clicks(drawer).subscribe { }
|
||||
RxView.clicks(archived).subscribe { }
|
||||
RxView.clicks(scheduled).subscribe { }
|
||||
RxView.clicks(blocked).subscribe { }
|
||||
RxView.clicks(settings).subscribe { }
|
||||
// Don't allow clicks to pass through the drawer layout
|
||||
drawer.clicks().subscribe()
|
||||
|
||||
// Refresh support for debugging purposes
|
||||
swipeRefresh.setOnRefreshListener { viewModel.onRefresh() } // TODO remove
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package com.moez.QKSMS.presentation.conversations
|
||||
|
||||
import com.moez.QKSMS.presentation.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface ConversationsView : QkView<ConversationsState>
|
||||
interface ConversationsView : QkView<ConversationsState> {
|
||||
|
||||
val composeIntent: Observable<Unit>
|
||||
val archivedIntent: Observable<Unit>
|
||||
val scheduledIntent: Observable<Unit>
|
||||
val blockedIntent: Observable<Unit>
|
||||
val settingsIntent: Observable<Unit>
|
||||
|
||||
}
|
||||
+10
@@ -26,6 +26,16 @@ class ConversationsViewModel : QkViewModel<ConversationsView, ConversationsState
|
||||
markAllSeen.execute(Unit)
|
||||
}
|
||||
|
||||
override fun bindIntents(view: ConversationsView) {
|
||||
super.bindIntents(view)
|
||||
|
||||
view.composeIntent.subscribe()
|
||||
view.archivedIntent.subscribe()
|
||||
view.scheduledIntent.subscribe()
|
||||
view.blockedIntent.subscribe()
|
||||
view.settingsIntent.subscribe()
|
||||
}
|
||||
|
||||
fun onRefresh() {
|
||||
newState { it.copy(refreshing = true) }
|
||||
syncConversations.execute(Unit, {
|
||||
|
||||
Reference in New Issue
Block a user