forked from upstream-mirrors/quik
Update newState signature to not require calling it.copy()
This commit is contained in:
@@ -40,10 +40,10 @@ class BlockedViewModel @Inject constructor(
|
||||
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
|
||||
init {
|
||||
newState { it.copy(data = messageRepo.getBlockedConversations()) }
|
||||
newState { copy(data = messageRepo.getBlockedConversations()) }
|
||||
|
||||
disposables += prefs.sia.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(siaEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(siaEnabled = enabled) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: BlockedView) {
|
||||
|
||||
@@ -121,12 +121,12 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
val initialConversation: Observable<Conversation> = when {
|
||||
threadId != 0L -> {
|
||||
newState { it.copy(selectedConversation = threadId, editingMode = false) }
|
||||
newState { copy(selectedConversation = threadId, editingMode = false) }
|
||||
messageRepo.getConversationAsync(threadId).asObservable()
|
||||
}
|
||||
|
||||
address.isNotBlank() -> {
|
||||
newState { it.copy(editingMode = false) }
|
||||
newState { copy(editingMode = false) }
|
||||
Observable.just(address)
|
||||
.mapNotNull { messageRepo.getOrCreateConversation(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
@@ -134,14 +134,14 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
else -> {
|
||||
newState { it.copy(editingMode = true) }
|
||||
newState { copy(editingMode = true) }
|
||||
Observable.empty()
|
||||
}
|
||||
}
|
||||
|
||||
selectedContacts = contactsReducer
|
||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||
.doOnNext { contacts -> newState { copy(selectedContacts = contacts) } }
|
||||
|
||||
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||
@@ -154,7 +154,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
@@ -168,7 +168,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { conversation ->
|
||||
val messages = messageRepo.getMessages(conversation.id)
|
||||
newState { it.copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
newState { copy(selectedConversation = conversation.id, messages = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
@@ -177,10 +177,10 @@ class ComposeViewModel @Inject constructor(
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { it.copy(conversationtitle = title) } }
|
||||
.subscribe { title -> newState { copy(conversationtitle = title) } }
|
||||
|
||||
disposables += attachments
|
||||
.subscribe { attachments -> newState { it.copy(attachments = attachments) } }
|
||||
.subscribe { attachments -> newState { copy(attachments = attachments) } }
|
||||
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.id }
|
||||
@@ -197,7 +197,7 @@ class ComposeViewModel @Inject constructor(
|
||||
messages.lastOrNull()?.let { message -> searchSelection.onNext(message.id) }
|
||||
} else {
|
||||
val position = messages.indexOfFirst { it.id == selected } + 1
|
||||
newState { it.copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
newState { copy(searchSelectionPosition = position, searchResults = messages.size) }
|
||||
}
|
||||
}.subscribe()
|
||||
|
||||
@@ -207,7 +207,7 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { it.copy(subscription = sub) }
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
|
||||
if (threadId == 0L) {
|
||||
@@ -228,7 +228,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contactsVisible -> newState { it.copy(contactsVisible = contactsVisible && it.editingMode) } }
|
||||
.subscribe { contactsVisible -> newState { copy(contactsVisible = contactsVisible && editingMode) } }
|
||||
|
||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||
// that have already been selected
|
||||
@@ -257,7 +257,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
|
||||
.subscribe { contacts -> newState { copy(contacts = contacts) } }
|
||||
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
@@ -297,7 +297,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// When the menu is loaded, trigger a new state so that the menu options can be rendered correctly
|
||||
view.menuReadyIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy() } }
|
||||
.subscribe { newState { copy() } }
|
||||
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
@@ -379,19 +379,19 @@ class ComposeViewModel @Inject constructor(
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.clear }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(query = "", searchSelectionId = -1) } }
|
||||
.subscribe { newState { copy(query = "", searchSelectionId = -1) } }
|
||||
|
||||
|
||||
// Toggle the group sending mode
|
||||
view.sendAsGroupIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(sendAsGroup = !it.sendAsGroup) } }
|
||||
.subscribe { newState { copy(sendAsGroup = !sendAsGroup) } }
|
||||
|
||||
|
||||
// Scroll to search position
|
||||
searchSelection
|
||||
.filter { id -> id != -1L }
|
||||
.doOnNext { id -> newState { it.copy(searchSelectionId = id) } }
|
||||
.doOnNext { id -> newState { copy(searchSelectionId = id) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::scrollToMessage)
|
||||
|
||||
@@ -407,7 +407,7 @@ class ComposeViewModel @Inject constructor(
|
||||
view.messagesSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { messages -> newState { it.copy(selectedMessages = messages, editingMode = false) } }
|
||||
.subscribe { messages -> newState { copy(selectedMessages = messages, editingMode = false) } }
|
||||
|
||||
// Cancel sending a message
|
||||
view.cancelSendingIntent
|
||||
@@ -438,7 +438,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Open the attachment options
|
||||
view.attachIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = !it.attaching) } }
|
||||
.subscribe { newState { copy(attaching = !attaching) } }
|
||||
|
||||
// Attach a photo from camera
|
||||
view.cameraIntent
|
||||
@@ -462,7 +462,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
|
||||
.doOnNext { attachments.onNext(it) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(attaching = false) } }
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
|
||||
// Detach a photo
|
||||
view.attachmentDeletedIntent
|
||||
@@ -494,7 +494,7 @@ class ComposeViewModel @Inject constructor(
|
||||
text.isNotBlank() || attachments.isNotEmpty()
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -512,7 +512,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
@@ -524,7 +524,7 @@ class ComposeViewModel @Inject constructor(
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { it.copy(subscription = subscription) }
|
||||
newState { copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -557,7 +557,7 @@ class ComposeViewModel @Inject constructor(
|
||||
this.attachments.onNext(ArrayList())
|
||||
|
||||
if (state.editingMode) {
|
||||
newState { it.copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
newState { copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -571,7 +571,7 @@ class ComposeViewModel @Inject constructor(
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.selectedMessages > 0 -> view.clearSelection()
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -57,7 +57,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
@@ -73,19 +73,19 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.recipients }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { recipients -> newState { it.copy(recipients = recipients) } }
|
||||
.subscribe { recipients -> newState { copy(recipients = recipients) } }
|
||||
|
||||
// Update the view's archived state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.archived }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { archived -> newState { it.copy(archived = archived) } }
|
||||
.subscribe { archived -> newState { copy(archived = archived) } }
|
||||
|
||||
// Update the view's blocked state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.blocked }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { blocked -> newState { it.copy(blocked = blocked) } }
|
||||
.subscribe { blocked -> newState { copy(blocked = blocked) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: ConversationInfoView) {
|
||||
|
||||
@@ -48,12 +48,12 @@ class GalleryViewModel @Inject constructor(
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getPart(partId) }
|
||||
.mapNotNull { part -> part.getUri() }
|
||||
.subscribe { uri -> newState { it.copy(imageUri = uri) } }
|
||||
.subscribe { uri -> newState { copy(imageUri = uri) } }
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||
.mapNotNull { message -> messageRepo.getConversation(message.threadId) }
|
||||
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||
.subscribe { conversation -> newState { copy(title = conversation.getTitle()) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: GalleryView) {
|
||||
@@ -64,7 +64,7 @@ class GalleryViewModel @Inject constructor(
|
||||
.withLatestFrom(state, { _, state -> state.navigationVisible })
|
||||
.map { navigationVisible -> !navigationVisible }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigationVisible -> newState { it.copy(navigationVisible = navigationVisible) } }
|
||||
.subscribe { navigationVisible -> newState { copy(navigationVisible = navigationVisible) } }
|
||||
|
||||
// Save image to device
|
||||
view.optionsItemSelectedIntent
|
||||
|
||||
@@ -72,12 +72,12 @@ class MainViewModel @Inject constructor(
|
||||
// Show the syncing UI
|
||||
disposables += syncRepository.syncProgress
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
||||
.subscribe { syncing -> newState { copy(syncing = syncing) } }
|
||||
|
||||
|
||||
// Show the rating UI
|
||||
disposables += ratingManager.shouldShowRating
|
||||
.subscribe { show -> newState { it.copy(showRating = show) } }
|
||||
.subscribe { show -> newState { copy(showRating = show) } }
|
||||
|
||||
|
||||
// Migrate the preferences from 2.7.3
|
||||
@@ -108,7 +108,7 @@ class MainViewModel @Inject constructor(
|
||||
view.activityResumedIntent.map { permissionManager.hasSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged(),
|
||||
{ defaultSms, smsPermission, contactPermission ->
|
||||
newState { it.copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -134,21 +134,21 @@ class MainViewModel @Inject constructor(
|
||||
.map { query -> query.removeAccents() }
|
||||
.withLatestFrom(state, { query, state ->
|
||||
if (query.isEmpty() && state.page is Searching) {
|
||||
newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
}
|
||||
query
|
||||
})
|
||||
.filter { query -> query.length >= 2 }
|
||||
.doOnNext {
|
||||
newState { state ->
|
||||
val page = (state.page as? Searching) ?: Searching()
|
||||
state.copy(page = page.copy(loading = true))
|
||||
newState {
|
||||
val page = (page as? Searching) ?: Searching()
|
||||
copy(page = page.copy(loading = true))
|
||||
}
|
||||
}
|
||||
.observeOn(Schedulers.io())
|
||||
.switchMap { query -> Observable.just(query).map { messageRepo.searchConversations(it) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { data -> newState { it.copy(page = Searching(loading = false, data = data)) } }
|
||||
.subscribe { data -> newState { copy(page = Searching(loading = false, data = data)) } }
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
@@ -164,7 +164,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
else -> newState { it.copy(drawerOpen = true) }
|
||||
else -> newState { copy(drawerOpen = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
@@ -172,19 +172,19 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
view.drawerOpenIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { open -> newState { it.copy(drawerOpen = open) } }
|
||||
.subscribe { open -> newState { copy(drawerOpen = open) } }
|
||||
|
||||
view.drawerItemIntent
|
||||
.doOnNext { newState { it.copy(drawerOpen = false) } }
|
||||
.doOnNext { newState { copy(drawerOpen = false) } }
|
||||
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
|
||||
.doOnNext { if (it == DrawerItem.PLUS) navigator.showQksmsPlusActivity() }
|
||||
.doOnNext { if (it == DrawerItem.HELP) navigator.showSupport() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
DrawerItem.INBOX -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
DrawerItem.ARCHIVED -> newState { copy(page = Archived(data = messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { copy(page = Scheduled()) }
|
||||
else -> {
|
||||
} // Do nothing
|
||||
}
|
||||
@@ -233,12 +233,12 @@ class MainViewModel @Inject constructor(
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
val page = state.page.copy(selected = selected, showClearButton = selected > 0)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -259,7 +259,7 @@ class MainViewModel @Inject constructor(
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = true)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -268,7 +268,7 @@ class MainViewModel @Inject constructor(
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = false)
|
||||
newState { it.copy(page = page) }
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -294,7 +294,7 @@ class MainViewModel @Inject constructor(
|
||||
view.backPressedIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
state.drawerOpen -> newState { it.copy(drawerOpen = false) }
|
||||
state.drawerOpen -> newState { copy(drawerOpen = false) }
|
||||
|
||||
state.page is Searching -> view.clearSearch()
|
||||
|
||||
@@ -303,9 +303,9 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
|
||||
|
||||
state.page !is Inbox -> newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
state.page !is Inbox -> newState { copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
|
||||
else -> newState { it.copy(hasError = true) }
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -61,19 +61,19 @@ class NotificationPrefsViewModel @Inject constructor(
|
||||
.mapNotNull { threadId -> messageRepo.getConversation(threadId) }
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { title -> newState { it.copy(conversationTitle = title) } }
|
||||
.subscribe { title -> newState { copy(conversationTitle = title) } }
|
||||
|
||||
disposables += notifications.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||
|
||||
val previewLabels = context.resources.getStringArray(R.array.notification_preview_options)
|
||||
disposables += previews.asObservable()
|
||||
.subscribe { previewId ->
|
||||
newState { it.copy(previewSummary = previewLabels[previewId], previewId = previewId) }
|
||||
newState { copy(previewSummary = previewLabels[previewId], previewId = previewId) }
|
||||
}
|
||||
|
||||
disposables += vibration.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(vibrationEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(vibrationEnabled = enabled) } }
|
||||
|
||||
disposables += ringtone.asObservable()
|
||||
.map { uriString ->
|
||||
@@ -82,13 +82,13 @@ class NotificationPrefsViewModel @Inject constructor(
|
||||
?.let { uri -> RingtoneManager.getRingtone(context, uri) }?.getTitle(context)
|
||||
?: context.getString(R.string.settings_ringtone_none)
|
||||
}
|
||||
.subscribe { title -> newState { it.copy(ringtoneName = title) } }
|
||||
.subscribe { title -> newState { copy(ringtoneName = title) } }
|
||||
|
||||
disposables += prefs.qkreply.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(qkReplyEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(qkReplyEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.qkreplyTapDismiss.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(qkReplyTapDismiss = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(qkReplyTapDismiss = enabled) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: NotificationPrefsView) {
|
||||
|
||||
@@ -38,14 +38,14 @@ class PlusViewModel @Inject constructor(
|
||||
analyticsManager.track("Viewed QKSMS+")
|
||||
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { it.copy(upgraded = upgraded) } }
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
|
||||
disposables += billingManager.products
|
||||
.subscribe { products ->
|
||||
newState {
|
||||
val upgrade = products.firstOrNull { it.sku == BillingManager.SKU_PLUS }
|
||||
val upgradeDonate = products.firstOrNull { it.sku == BillingManager.SKU_PLUS_DONATE }
|
||||
it.copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
|
||||
copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
|
||||
currency = upgrade?.priceCurrencyCode ?: upgradeDonate?.priceCurrencyCode ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,19 +71,19 @@ class QkReplyViewModel @Inject constructor(
|
||||
// If we're ever showing an empty set of messages, then it's time to shut down to activity
|
||||
disposables += Observables
|
||||
.combineLatest(messages, conversation) { messages, conversation ->
|
||||
newState { it.copy(data = Pair(conversation, messages)) }
|
||||
newState { copy(data = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
.filter { it.isEmpty() }
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { it.copy(title = title) } }
|
||||
.subscribe { title -> newState { copy(title = title) } }
|
||||
|
||||
val latestSubId = messages
|
||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||
@@ -91,7 +91,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { it.copy(subscription = sub) }
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> conversation.id }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId ->
|
||||
markRead.execute(threadId) { newState { it.copy(hasError = true) } }
|
||||
markRead.execute(threadId) { newState { copy(hasError = true) } }
|
||||
}
|
||||
|
||||
// Call
|
||||
@@ -121,7 +121,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.mapNotNull { conversation -> conversation.recipients.first()?.address }
|
||||
.doOnNext { address -> navigator.makePhoneCall(address) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
// Show all messages
|
||||
view.menuItemIntent
|
||||
@@ -130,7 +130,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> messageRepo.getMessages(conversation.id) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = true) } }
|
||||
.subscribe { newState { copy(expanded = true) } }
|
||||
|
||||
// Show unread messages only
|
||||
view.menuItemIntent
|
||||
@@ -139,7 +139,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = false) } }
|
||||
.subscribe { newState { copy(expanded = false) } }
|
||||
|
||||
// View conversation
|
||||
view.menuItemIntent
|
||||
@@ -148,14 +148,14 @@ class QkReplyViewModel @Inject constructor(
|
||||
.map { conversation -> conversation.id }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
.subscribe { newState { copy(hasError = true) } }
|
||||
|
||||
// Enable the send button when there is text input into the new message body or there's
|
||||
// an attachment, disable otherwise
|
||||
view.textChangedIntent
|
||||
.map { text -> text.isNotBlank() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -173,7 +173,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
||||
|
||||
// Update the draft whenever the text is changed
|
||||
view.textChangedIntent
|
||||
@@ -196,7 +196,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { it.copy(subscription = subscription) }
|
||||
newState { copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -215,7 +215,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
})
|
||||
.doOnNext { threadId ->
|
||||
markRead.execute(threadId) {
|
||||
newState { it.copy(hasError = true) }
|
||||
newState { copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -27,11 +27,11 @@ import common.base.QkViewModel
|
||||
import common.util.BillingManager
|
||||
import common.util.Colors
|
||||
import common.util.DateFormatter
|
||||
import util.NightModeManager
|
||||
import interactor.SyncMessages
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import timber.log.Timber
|
||||
import util.NightModeManager
|
||||
import util.Preferences
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -49,60 +49,60 @@ class SettingsViewModel @Inject constructor(
|
||||
|
||||
|
||||
init {
|
||||
newState { it.copy(theme = colors.theme().theme) }
|
||||
newState { copy(theme = colors.theme().theme) }
|
||||
|
||||
val nightModeLabels = context.resources.getStringArray(R.array.night_modes)
|
||||
disposables += prefs.nightMode.asObservable()
|
||||
.subscribe { nightMode ->
|
||||
newState { it.copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||
newState { copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||
}
|
||||
|
||||
disposables += prefs.nightStart.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightStart -> newState { it.copy(nightStart = nightStart) } }
|
||||
.subscribe { nightStart -> newState { copy(nightStart = nightStart) } }
|
||||
|
||||
disposables += prefs.nightEnd.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightEnd -> newState { it.copy(nightEnd = nightEnd) } }
|
||||
.subscribe { nightEnd -> newState { copy(nightEnd = nightEnd) } }
|
||||
|
||||
disposables += prefs.black.asObservable()
|
||||
.subscribe { black -> newState { it.copy(black = black) } }
|
||||
.subscribe { black -> newState { copy(black = black) } }
|
||||
|
||||
disposables += prefs.notifications().asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.autoEmoji.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(autoEmojiEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(autoEmojiEnabled = enabled) } }
|
||||
|
||||
val delayedSendingLabels = context.resources.getStringArray(R.array.delayed_sending_labels)
|
||||
disposables += prefs.sendDelay.asObservable()
|
||||
.subscribe { id -> newState { it.copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
|
||||
disposables += prefs.delivery.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||
|
||||
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
|
||||
disposables += prefs.textSize.asObservable()
|
||||
.subscribe { textSize ->
|
||||
newState { it.copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
}
|
||||
|
||||
disposables += prefs.systemFont.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(systemFontEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.unicode.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(stripUnicodeEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
||||
|
||||
val mmsSizeLabels = context.resources.getStringArray(R.array.mms_sizes)
|
||||
val mmsSizeIds = context.resources.getIntArray(R.array.mms_sizes_ids)
|
||||
disposables += prefs.mmsSize.asObservable()
|
||||
.subscribe { maxMmsSize ->
|
||||
val index = mmsSizeIds.indexOf(maxMmsSize)
|
||||
newState { it.copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
}
|
||||
|
||||
disposables += syncMessages
|
||||
@@ -152,9 +152,9 @@ class SettingsViewModel @Inject constructor(
|
||||
R.id.mmsSize -> view.showMmsSizePicker()
|
||||
|
||||
R.id.sync -> {
|
||||
newState { it.copy(syncing = true) }
|
||||
newState { copy(syncing = true) }
|
||||
syncMessages.execute(Unit, {
|
||||
newState { it.copy(syncing = false) }
|
||||
newState { copy(syncing = false) }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -55,16 +55,16 @@ class ThemePickerViewModel @Inject constructor(
|
||||
|
||||
// Update the color of the apply button
|
||||
view.hsvThemeSelectedIntent
|
||||
.doOnNext { color -> newState { it.copy(newColor = color) } }
|
||||
.doOnNext { color -> newState { copy(newColor = color) } }
|
||||
.map { color -> colors.textPrimaryOnThemeForColor(color) }
|
||||
.doOnNext { color -> newState { it.copy(newTextColor = color) } }
|
||||
.doOnNext { color -> newState { copy(newTextColor = color) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Toggle the visibility of the apply group
|
||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent, { old, new -> old != new })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { themeChanged -> newState { it.copy(applyThemeVisible = themeChanged) } }
|
||||
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
||||
|
||||
// Update the theme, when apply is clicked
|
||||
view.hsvThemeAppliedIntent
|
||||
|
||||
Reference in New Issue
Block a user