mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Allow changing page via navigation menu
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.89 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.11 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_material_light">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/white" />
|
||||
<corners android:radius="2dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -6,11 +6,27 @@
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/inbox"
|
||||
style="@style/DrawerRow">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/inboxIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_inbox_black_24dp" />
|
||||
|
||||
<TextView
|
||||
style="@style/DrawerText"
|
||||
android:text="@string/drawer_inbox" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/archived"
|
||||
style="@style/DrawerRow">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/archivedIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_folder_black_24dp" />
|
||||
|
||||
@@ -25,6 +41,7 @@
|
||||
style="@style/DrawerRow">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/scheduledIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_event_black_24dp" />
|
||||
|
||||
@@ -39,6 +56,7 @@
|
||||
style="@style/DrawerRow">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/blockedIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_block_black_24dp" />
|
||||
|
||||
|
||||
@@ -16,4 +16,5 @@
|
||||
<color name="statusLight">#F1F1F1</color>
|
||||
|
||||
<color name="list_separator">#F2F2F2</color>
|
||||
<color name="row_selected">#F5F5F5</color>
|
||||
</resources>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<string name="compose_hint">Write a message</string>
|
||||
|
||||
<string name="drawer_inbox">Inbox</string>
|
||||
<string name="drawer_archived">Archived</string>
|
||||
<string name="drawer_scheduled">Scheduled</string>
|
||||
<string name="drawer_blocked">Blocked</string>
|
||||
|
||||
Reference in New Issue
Block a user