forked from upstream-mirrors/quik
Merge pull request #213 from gavine99/unread_at_top
make unread conversations float at the top of conversation lists
This commit is contained in:
@@ -136,7 +136,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
// Otherwise, we'll monitor the conversations until our expected conversation is created
|
||||
conversationRepo.getConversations().asObservable()
|
||||
conversationRepo.getConversations(prefs.unreadAtTop.get()).asObservable()
|
||||
.filter { it.isLoaded }
|
||||
.observeOn(Schedulers.io())
|
||||
.map { conversationRepo.getOrCreateConversation(addresses)?.id ?: 0 }
|
||||
|
||||
@@ -83,7 +83,7 @@ class MainViewModel @Inject constructor(
|
||||
private val ratingManager: RatingManager,
|
||||
private val syncContacts: SyncContacts,
|
||||
private val syncMessages: SyncMessages
|
||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations()))) {
|
||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get())))) {
|
||||
|
||||
init {
|
||||
disposables += deleteConversations
|
||||
@@ -140,6 +140,25 @@ class MainViewModel @Inject constructor(
|
||||
!permissionManager.hasReadSms() || !permissionManager.hasContacts() -> view.requestPermissions()
|
||||
}
|
||||
|
||||
|
||||
// when unreadAtTop preference changes, reload the model view data to refresh view
|
||||
prefs.unreadAtTop.asObservable()
|
||||
.skip(1)
|
||||
.debounce(400, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.withLatestFrom(state) { _, state ->
|
||||
if (state.page is Inbox)
|
||||
newState {
|
||||
copy(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get())))
|
||||
}
|
||||
else if (state.page is Archived)
|
||||
newState {
|
||||
copy(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get(), true)))
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If the default SMS state changes, reflect it in the State
|
||||
view.activityResumedIntent
|
||||
.filter { resumed -> resumed }
|
||||
@@ -226,7 +245,7 @@ class MainViewModel @Inject constructor(
|
||||
.map { query -> query.trim() }
|
||||
.withLatestFrom(state) { query, state ->
|
||||
if (query.isEmpty() && state.page is Searching) {
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get()))) }
|
||||
}
|
||||
query
|
||||
}
|
||||
@@ -288,7 +307,7 @@ class MainViewModel @Inject constructor(
|
||||
state.page is Inbox && state.page.selected > 0 -> view.clearSelection()
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
state.page !is Inbox -> {
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get()))) }
|
||||
}
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
@@ -306,8 +325,8 @@ class MainViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { drawerItem ->
|
||||
when (drawerItem) {
|
||||
NavItem.INBOX -> newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
NavItem.ARCHIVED -> newState { copy(page = Archived(data = conversationRepo.getConversations(true))) }
|
||||
NavItem.INBOX -> newState { copy(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get()))) }
|
||||
NavItem.ARCHIVED -> newState { copy(page = Archived(data = conversationRepo.getConversations(prefs.unreadAtTop.get(), true))) }
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
|
||||
delivery.checkbox.isChecked = state.deliveryEnabled
|
||||
|
||||
unreadAtTop.checkbox.isChecked = state.unreadAtTopEnabled
|
||||
|
||||
signature.summary = state.signature.takeIf { it.isNotBlank() }
|
||||
?: context.getString(R.string.settings_signature_summary)
|
||||
|
||||
|
||||
@@ -98,7 +98,10 @@ class SettingsPresenter @Inject constructor(
|
||||
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
|
||||
disposables += prefs.delivery.asObservable()
|
||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.unreadAtTop.asObservable()
|
||||
.subscribe { enabled -> newState { copy(unreadAtTopEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.signature.asObservable()
|
||||
.subscribe { signature -> newState { copy(signature = signature) } }
|
||||
@@ -178,6 +181,8 @@ class SettingsPresenter @Inject constructor(
|
||||
|
||||
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
|
||||
|
||||
R.id.unreadAtTop -> prefs.unreadAtTop.set(!prefs.unreadAtTop.get())
|
||||
|
||||
R.id.signature -> view.showSignatureDialog(prefs.signature.get())
|
||||
|
||||
R.id.textSize -> view.showTextSizePicker()
|
||||
|
||||
@@ -34,6 +34,7 @@ data class SettingsState(
|
||||
val sendDelaySummary: String = "",
|
||||
val sendDelayId: Int = 0,
|
||||
val deliveryEnabled: Boolean = false,
|
||||
val unreadAtTopEnabled: Boolean = false,
|
||||
val signature: String = "",
|
||||
val textSizeSummary: String = "",
|
||||
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package dev.octoshrimpy.quik.feature.widget
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.SpannableStringBuilder
|
||||
@@ -34,8 +33,6 @@ import dev.octoshrimpy.quik.common.util.Colors
|
||||
import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
|
||||
import dev.octoshrimpy.quik.common.util.extensions.getColorCompat
|
||||
import dev.octoshrimpy.quik.feature.compose.ComposeActivity
|
||||
import dev.octoshrimpy.quik.feature.main.MainActivity
|
||||
import dev.octoshrimpy.quik.injection.appComponent
|
||||
import dev.octoshrimpy.quik.model.Contact
|
||||
import dev.octoshrimpy.quik.model.Conversation
|
||||
@@ -85,7 +82,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
}
|
||||
|
||||
override fun onDataSetChanged() {
|
||||
conversations = conversationRepo.getConversationsSnapshot()
|
||||
conversations = conversationRepo.getConversationsSnapshot(prefs.unreadAtTop.get())
|
||||
|
||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget)
|
||||
appWidgetManager.partiallyUpdateAppWidget(appWidgetId, remoteViews)
|
||||
|
||||
Reference in New Issue
Block a user