forked from upstream-mirrors/quik
Add empty state to inbox and archived
This commit is contained in:
@@ -21,8 +21,11 @@ package common.util.extensions
|
||||
|
||||
import common.util.Optional
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Observable
|
||||
|
||||
fun <T, R> Flowable<T>.mapNotNull(mapper: (T) -> R?): Flowable<R>
|
||||
= map { input -> Optional(mapper(input)) }
|
||||
.filter { optional -> optional.notNull() }
|
||||
.map { optional -> optional.value }
|
||||
.map { optional -> optional.value }
|
||||
|
||||
fun <T> Observable<T>.toFlowable(): Flowable<T> = this.toFlowable(io.reactivex.BackpressureStrategy.BUFFER)
|
||||
@@ -206,6 +206,8 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView)
|
||||
menuItemAdapter.data = state.page.menu
|
||||
empty.setText(R.string.inbox_empty_text)
|
||||
empty.setVisible(state.page.empty)
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
@@ -214,6 +216,8 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
menuItemAdapter.data = state.page.menu
|
||||
empty.setText(R.string.archived_empty_text)
|
||||
empty.setVisible(state.page.empty)
|
||||
}
|
||||
|
||||
is Scheduled -> {
|
||||
@@ -221,6 +225,8 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
recyclerView.adapter = null
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
menuItemAdapter.data = ArrayList()
|
||||
empty.setText(R.string.scheduled_empty_text)
|
||||
empty.setVisible(state.page.empty)
|
||||
}
|
||||
|
||||
is Blocked -> {
|
||||
@@ -228,6 +234,8 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
recyclerView.adapter = null
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
menuItemAdapter.data = ArrayList()
|
||||
empty.setText(R.string.blocked_empty_text)
|
||||
empty.setVisible(state.page.empty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +33,19 @@ sealed class MainPage
|
||||
data class Inbox(
|
||||
val showClearButton: Boolean = false,
|
||||
val data: Flowable<List<InboxItem>>? = null,
|
||||
val empty: Boolean = false,
|
||||
val menu: List<MenuItem> = ArrayList(),
|
||||
val showArchivedSnackbar: Boolean = false) : MainPage()
|
||||
|
||||
data class Archived(
|
||||
val data: Flowable<List<InboxItem>>?,
|
||||
val empty: Boolean = false,
|
||||
val menu: List<MenuItem> = ArrayList()) : MainPage()
|
||||
|
||||
data class Scheduled(
|
||||
val data: Any? = null) : MainPage()
|
||||
val data: Any? = null,
|
||||
val empty: Boolean = false) : MainPage()
|
||||
|
||||
data class Blocked(
|
||||
val data: Any? = null) : MainPage()
|
||||
val data: Any? = null,
|
||||
val empty: Boolean = false) : MainPage()
|
||||
@@ -28,6 +28,7 @@ import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.BillingManager
|
||||
import common.util.extensions.toFlowable
|
||||
import common.util.filter.ConversationFilter
|
||||
import data.model.MenuItem
|
||||
import data.model.SyncLog
|
||||
@@ -56,7 +57,25 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
|
||||
private val conversations by lazy { messageRepo.getConversations() }
|
||||
private val conversations by lazy {
|
||||
messageRepo.getConversations()
|
||||
.withLatestFrom(state.toFlowable(), { conversations, state ->
|
||||
(state.page as? Inbox)?.let { page ->
|
||||
newState { it.copy(page = page.copy(empty = conversations.isEmpty())) }
|
||||
}
|
||||
conversations
|
||||
})
|
||||
}
|
||||
|
||||
private val archivedConversations by lazy {
|
||||
messageRepo.getConversations(true)
|
||||
.withLatestFrom(state.toFlowable(), { conversations, state ->
|
||||
(state.page as? Archived)?.let { page ->
|
||||
newState { it.copy(page = page.copy(empty = conversations.isEmpty())) }
|
||||
}
|
||||
conversations
|
||||
})
|
||||
}
|
||||
|
||||
private val menuArchive = MenuItem(R.string.menu_archive, 0)
|
||||
private val menuUnarchive = MenuItem(R.string.menu_unarchive, 1)
|
||||
@@ -143,7 +162,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = conversations)) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(archivedConversations)) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked()) }
|
||||
else -> {
|
||||
|
||||
@@ -61,6 +61,15 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<presentation.common.widget.QkTextView
|
||||
android:id="@+id/empty"
|
||||
style="@style/TextSecondary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="56dp" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -60,6 +60,11 @@
|
||||
<string name="drawer_settings">Settings</string>
|
||||
<string name="drawer_help">Help & feedback</string>
|
||||
|
||||
<string name="inbox_empty_text">Your conversations will appear here</string>
|
||||
<string name="archived_empty_text">Your archived conversations will appear here</string>
|
||||
<string name="scheduled_empty_text">Your scheduled messages will appear here</string>
|
||||
<string name="blocked_empty_text">Your blocked senders will appear here</string>
|
||||
|
||||
<string name="settings_default_sms_title">Default SMS app</string>
|
||||
<string name="settings_default_sms_summary_true">QKSMS is your default SMS app</string>
|
||||
<string name="settings_default_sms_summary_false">Set QKSMS as your default SMS app</string>
|
||||
|
||||
Reference in New Issue
Block a user