Allow changing page via navigation menu

This commit is contained in:
Moez Bhatti
2017-11-01 18:12:36 -07:00
parent 3c63d7b5b3
commit e0ea54f1f4
11 changed files with 99 additions and 7 deletions
@@ -9,4 +9,8 @@ class ThemeManager @Inject constructor() {
val color = 0xFF008389.toInt()
val bubbleColor = 0xFFF4F4F4.toInt()
val textPrimary = 0xFF49555F.toInt()
val textSecondary = 0xFF70808D.toInt()
val textTertiary = 0xFFB7B9C0.toInt()
}
@@ -15,10 +15,12 @@ import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.moez.QKSMS.R
import com.moez.QKSMS.common.di.AppComponentManager
import com.moez.QKSMS.common.util.ThemeManager
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.presentation.Navigator
import com.moez.QKSMS.presentation.base.QkActivity
import kotlinx.android.synthetic.main.conversation_list_activity.*
import kotlinx.android.synthetic.main.drawer_view.*
import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.android.synthetic.main.toolbar.*
import timber.log.Timber
import javax.inject.Inject
@@ -26,10 +28,12 @@ import javax.inject.Inject
class MainActivity : QkActivity<MainViewModel, MainState>(), MainView {
@Inject lateinit var navigator: Navigator
@Inject lateinit var themeManager: ThemeManager
override val viewModelClass = MainViewModel::class
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() }
@@ -38,7 +42,7 @@ class MainActivity : QkActivity<MainViewModel, MainState>(), MainView {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AppComponentManager.appComponent.inject(this)
setContentView(R.layout.conversation_list_activity)
setContentView(R.layout.main_activity)
ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0).syncState()
requestPermissions()
viewModel.setView(this)
@@ -61,10 +65,27 @@ class MainActivity : QkActivity<MainViewModel, MainState>(), MainView {
conversationList.adapter = state.adapter
}
inbox.setBackgroundResource(getRowBackground(state.page == MainPage.INBOX))
inboxIcon.setTint(getIconColor(state.page == MainPage.INBOX))
archived.setBackgroundResource(getRowBackground(state.page == MainPage.ARCHIVED))
archivedIcon.setTint(getIconColor(state.page == MainPage.ARCHIVED))
scheduled.setBackgroundResource(getRowBackground(state.page == MainPage.SCHEDULED))
scheduledIcon.setTint(getIconColor(state.page == MainPage.SCHEDULED))
blocked.setBackgroundResource(getRowBackground(state.page == MainPage.BLOCKED))
blockedIcon.setTint(getIconColor(state.page == MainPage.BLOCKED))
if (drawerLayout.isDrawerOpen(Gravity.START) && !state.drawerOpen) drawerLayout.closeDrawer(Gravity.START)
else if (!drawerLayout.isDrawerVisible(Gravity.START) && state.drawerOpen) drawerLayout.openDrawer(Gravity.START)
}
private fun getIconColor(selected: Boolean): Int {
return if (selected) themeManager.color else themeManager.textSecondary
}
private fun getRowBackground(selected: Boolean): Int {
return if (selected) R.color.row_selected else R.drawable.ripple
}
private fun requestPermissions() {
Dexter.withActivity(this)
.withPermissions(arrayListOf(Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS))
@@ -3,7 +3,10 @@ package com.moez.QKSMS.presentation.main
import android.support.v7.widget.RecyclerView
data class MainState(
val page: MainPage = MainPage.INBOX,
val adapter: RecyclerView.Adapter<*>? = null,
val refreshing: Boolean = false,
val drawerOpen: Boolean = false
)
)
enum class MainPage { INBOX, ARCHIVED, SCHEDULED, BLOCKED }
@@ -7,6 +7,7 @@ interface MainView : QkView<MainState> {
val composeIntent: Observable<Unit>
val drawerOpenIntent: Observable<Boolean>
val inboxIntent: Observable<Unit>
val archivedIntent: Observable<Unit>
val scheduledIntent: Observable<Unit>
val blockedIntent: Observable<Unit>
@@ -19,7 +19,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
disposables += markAllSeen
newState { it.copy(adapter = ConversationsAdapter(messageRepo.getConversationMessagesAsync())) }
newState { it.copy(page = MainPage.INBOX, adapter = ConversationsAdapter(messageRepo.getConversationMessagesAsync())) }
markAllSeen.execute(Unit)
}
@@ -35,16 +35,40 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
newState { it.copy(drawerOpen = true) }
}
intents += view.inboxIntent.subscribe {
newState {
it.copy(
page = MainPage.INBOX,
adapter = ConversationsAdapter(messageRepo.getConversationMessagesAsync()),
drawerOpen = false)
}
}
intents += view.archivedIntent.subscribe {
newState { it.copy(drawerOpen = false) }
newState {
it.copy(
page = MainPage.ARCHIVED,
adapter = null,
drawerOpen = false)
}
}
intents += view.scheduledIntent.subscribe {
newState { it.copy(drawerOpen = false) }
newState {
it.copy(
page = MainPage.SCHEDULED,
adapter = null,
drawerOpen = false)
}
}
intents += view.blockedIntent.subscribe {
newState { it.copy(drawerOpen = false) }
newState {
it.copy(
page = MainPage.BLOCKED,
adapter = null,
drawerOpen = false)
}
}
intents += view.settingsIntent.subscribe {