forked from upstream-mirrors/quik
Move lambdas outside of parentheses
This commit is contained in:
@@ -108,7 +108,7 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
// Update the colours of the menu items
|
||||
Observables.combineLatest(menu, theme, { menu, theme ->
|
||||
Observables.combineLatest(menu, theme) { menu, theme ->
|
||||
val text = resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
(0 until menu.size())
|
||||
.map { position -> menu.getItem(position) }
|
||||
@@ -122,7 +122,7 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
menuItem.icon = this
|
||||
}
|
||||
}
|
||||
}).autoDisposable(scope(Lifecycle.Event.ON_DESTROY)).subscribe()
|
||||
}.autoDisposable(scope(Lifecycle.Event.ON_DESTROY)).subscribe()
|
||||
}
|
||||
|
||||
open fun getColoredMenuItems(): List<Int> {
|
||||
|
||||
@@ -65,7 +65,7 @@ class BlockedActivity : QkThemedActivity(), BlockedView {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.blocked_unblock_dialog_title)
|
||||
.setMessage(R.string.blocked_unblock_dialog_message)
|
||||
.setPositiveButton(R.string.button_unblock, { _, _ -> confirmUnblockIntent.onNext(Unit) })
|
||||
.setPositiveButton(R.string.button_unblock) { _, _ -> confirmUnblockIntent.onNext(Unit) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class BlockedViewModel @Inject constructor(
|
||||
?: false
|
||||
}
|
||||
.doOnNext { installed -> if (!installed) navigator.showSia() }
|
||||
.withLatestFrom(prefs.sia.asObservable(), { installed, enabled -> installed && !enabled })
|
||||
.withLatestFrom(prefs.sia.asObservable()) { installed, enabled -> installed && !enabled }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { shouldEnable -> prefs.sia.set(shouldEnable) }
|
||||
|
||||
@@ -67,7 +67,7 @@ class BlockedViewModel @Inject constructor(
|
||||
|
||||
// Unblock conversation
|
||||
view.confirmUnblockIntent
|
||||
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
|
||||
.withLatestFrom(view.unblockIntent) { _, threadId -> threadId }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnblocked.execute(listOf(threadId)) }
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
disposables += contactsReducer
|
||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||
.scan(listOf<Contact>()) { previousState, reducer -> reducer(previousState) }
|
||||
.doOnNext { contacts -> newState { copy(selectedContacts = contacts) } }
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
@@ -209,9 +209,9 @@ class ComposeViewModel @Inject constructor(
|
||||
// Set the contact suggestions list to visible at all times when in editing mode and there are no contacts
|
||||
// selected yet, and also visible while in editing mode and there is text entered in the query field
|
||||
Observables
|
||||
.combineLatest(view.queryChangedIntent, selectedContacts, { query, selectedContacts ->
|
||||
.combineLatest(view.queryChangedIntent, selectedContacts) { query, selectedContacts ->
|
||||
selectedContacts.isEmpty() || query.isNotEmpty()
|
||||
})
|
||||
}
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.distinctUntilChanged()
|
||||
@@ -221,7 +221,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||
// that have already been selected
|
||||
Observables
|
||||
.combineLatest(view.queryChangedIntent, contacts, selectedContacts, { query, contacts, selectedContacts ->
|
||||
.combineLatest(view.queryChangedIntent, contacts, selectedContacts) { query, contacts, selectedContacts ->
|
||||
|
||||
// Strip the accents from the query. This can be an expensive operation, so
|
||||
// cache the result instead of doing it for each contact
|
||||
@@ -240,7 +240,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
filteredContacts
|
||||
})
|
||||
}
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
.subscribeOn(Schedulers.computation())
|
||||
@@ -250,18 +250,18 @@ class ComposeViewModel @Inject constructor(
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
view.queryBackspaceIntent
|
||||
.withLatestFrom(selectedContacts, view.queryChangedIntent, { event, contacts, query ->
|
||||
.withLatestFrom(selectedContacts, view.queryChangedIntent) { event, contacts, query ->
|
||||
if (contacts.isNotEmpty() && query.isEmpty()) {
|
||||
contactsReducer.onNext { it.dropLast(1) }
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Enter the first contact suggestion if the enter button is pressed
|
||||
view.queryEditorActionIntent
|
||||
.filter { actionId -> actionId == EditorInfo.IME_ACTION_DONE }
|
||||
.withLatestFrom(state, { _, state -> state })
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { state ->
|
||||
state.contacts.firstOrNull()?.let { contact ->
|
||||
@@ -290,7 +290,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Open the phone dialer if the call button is clicked
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.call }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> conversation.recipients.first() }
|
||||
.map { recipient -> recipient.address }
|
||||
.autoDisposable(view.scope())
|
||||
@@ -299,19 +299,19 @@ class ComposeViewModel @Inject constructor(
|
||||
// Open the conversation settings if info button is clicked
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.info }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> navigator.showConversationInfo(conversation.id) }
|
||||
|
||||
// Copy the message contents
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.copy }
|
||||
.withLatestFrom(view.messagesSelectedIntent, { _, messages ->
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages ->
|
||||
messages?.firstOrNull()?.let { messageRepo.getMessage(it) }?.let { message ->
|
||||
ClipboardUtils.copy(context, message.getText())
|
||||
context.makeToast(R.string.toast_copied)
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
@@ -328,21 +328,21 @@ class ComposeViewModel @Inject constructor(
|
||||
// Delete the messages
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
.withLatestFrom(view.messagesSelectedIntent, conversation, { _, messages, conversation ->
|
||||
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
|
||||
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
// Forward the message
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.forward }
|
||||
.withLatestFrom(view.messagesSelectedIntent, { _, messages ->
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages ->
|
||||
messages?.firstOrNull()?.let { messageRepo.getMessage(it) }?.let { message ->
|
||||
val images = message.parts.filter { it.isImage() }.mapNotNull { it.getUri() }
|
||||
navigator.showCompose(message.body, images)
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
@@ -416,18 +416,18 @@ class ComposeViewModel @Inject constructor(
|
||||
// Save draft when the activity goes into the background
|
||||
view.activityVisibleIntent
|
||||
.filter { visible -> !visible }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation.id })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation.id }
|
||||
.observeOn(Schedulers.io())
|
||||
.withLatestFrom(view.textChangedIntent, { threadId, draft ->
|
||||
.withLatestFrom(view.textChangedIntent) { threadId, draft ->
|
||||
conversationRepo.saveDraft(threadId, draft.toString())
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Mark the conversation read, if in foreground
|
||||
Observables.combineLatest(messages, view.activityVisibleIntent, { _, visible -> visible })
|
||||
Observables.combineLatest(messages, view.activityVisibleIntent) { _, visible -> visible }
|
||||
.filter { visible -> visible }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.mapNotNull { conversation -> conversation.takeIf { it.isValid }?.id }
|
||||
.debounce(200, TimeUnit.MILLISECONDS)
|
||||
.autoDisposable(view.scope())
|
||||
@@ -457,14 +457,14 @@ class ComposeViewModel @Inject constructor(
|
||||
Observable.merge(
|
||||
view.attachmentSelectedIntent.map { uri -> Attachment(uri) },
|
||||
view.inputContentIntent.map { inputContent -> Attachment(inputContent = inputContent) })
|
||||
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
|
||||
.withLatestFrom(attachments) { attachment, attachments -> attachments + attachment }
|
||||
.doOnNext { attachments.onNext(it) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
|
||||
// Detach a photo
|
||||
view.attachmentDeletedIntent
|
||||
.withLatestFrom(attachments, { bitmap, attachments -> attachments.filter { it !== bitmap } })
|
||||
.withLatestFrom(attachments) { bitmap, attachments -> attachments.filter { it !== bitmap } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { attachments.onNext(it) }
|
||||
|
||||
@@ -488,9 +488,9 @@ class ComposeViewModel @Inject constructor(
|
||||
// Enable the send button when there is text input into the new message body or there's
|
||||
// an attachment, disable otherwise
|
||||
Observables
|
||||
.combineLatest(view.textChangedIntent, attachments, { text, attachments ->
|
||||
.combineLatest(view.textChangedIntent, attachments) { text, attachments ->
|
||||
text.isNotBlank() || attachments.isNotEmpty()
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
|
||||
@@ -531,7 +531,7 @@ class ComposeViewModel @Inject constructor(
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(state, attachments, conversation, selectedContacts, { body, state, attachments, conversation, contacts ->
|
||||
.withLatestFrom(state, attachments, conversation, selectedContacts) { body, state, attachments, conversation, contacts ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
|
||||
if (state.sendAsGroup) {
|
||||
@@ -561,7 +561,7 @@ class ComposeViewModel @Inject constructor(
|
||||
if (state.editingMode) {
|
||||
newState { copy(editingMode = false, sendAsGroup = true, hasError = !state.sendAsGroup) }
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -570,12 +570,12 @@ class ComposeViewModel @Inject constructor(
|
||||
.filter { it == android.R.id.home }
|
||||
.map { Unit }
|
||||
.mergeWith(view.backPressedIntent)
|
||||
.withLatestFrom(state, { _, state ->
|
||||
.withLatestFrom(state) { _, state ->
|
||||
when {
|
||||
state.selectedMessages > 0 -> view.clearSelection()
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
|
||||
+2
-2
@@ -129,7 +129,7 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.info_name)
|
||||
.setView(editText)
|
||||
.setPositiveButton(R.string.button_save, { _, _ -> nameChangedIntent.onNext(editText.text.toString()) })
|
||||
.setPositiveButton(R.string.button_save) { _, _ -> nameChangedIntent.onNext(editText.text.toString()) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(R.string.dialog_delete_message)
|
||||
.setPositiveButton(R.string.button_delete, { _, _ -> confirmDeleteIntent.onNext(Unit) })
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(Unit) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
+5
-5
@@ -118,19 +118,19 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
|
||||
// Show the notifications settings for the conversation
|
||||
view.notificationsIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
|
||||
|
||||
// Show the theme settings for the conversation
|
||||
view.themeIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> navigator.showThemePicker(conversation.id) }
|
||||
|
||||
// Toggle the archived state of the conversation
|
||||
view.archiveIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation ->
|
||||
when (conversation.archived) {
|
||||
@@ -141,7 +141,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
|
||||
// Toggle the blocked state of the conversation
|
||||
view.blockIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation ->
|
||||
when (conversation.blocked) {
|
||||
@@ -157,7 +157,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
|
||||
// Delete the conversation
|
||||
view.confirmDeleteIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> deleteConversations.execute(listOf(conversation.id)) }
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class GalleryViewModel @Inject constructor(
|
||||
|
||||
// When the screen is touched, toggle the visibility of the navigation UI
|
||||
view.screenTouchedIntent
|
||||
.withLatestFrom(state, { _, state -> state.navigationVisible })
|
||||
.withLatestFrom(state) { _, state -> state.navigationVisible }
|
||||
.map { navigationVisible -> !navigationVisible }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigationVisible -> newState { copy(navigationVisible = navigationVisible) } }
|
||||
@@ -70,7 +70,7 @@ class GalleryViewModel @Inject constructor(
|
||||
// Save image to device
|
||||
view.optionsItemSelectedIntent
|
||||
.filter { itemId -> itemId == R.id.save }
|
||||
.withLatestFrom(partIdFlowable.toObservable(), { _, partId -> partId })
|
||||
.withLatestFrom(partIdFlowable.toObservable()) { _, partId -> partId }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { partId -> saveImage.execute(partId) { context.makeToast(R.string.gallery_toast_saved) } }
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
|
||||
private val archiveSnackbar by lazy {
|
||||
Snackbar.make(drawerLayout, R.string.toast_archived, Snackbar.LENGTH_INDEFINITE).apply {
|
||||
setAction(R.string.button_undo, { undoSwipeConversationIntent.onNext(Unit) })
|
||||
setAction(R.string.button_undo) { undoSwipeConversationIntent.onNext(Unit) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(R.string.dialog_delete_message)
|
||||
.setPositiveButton(R.string.button_delete, { _, _ -> confirmDeleteIntent.onNext(Unit) })
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(Unit) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
@@ -112,10 +112,10 @@ class MainViewModel @Inject constructor(
|
||||
Observables.combineLatest(
|
||||
view.activityResumedIntent.map { permissionManager.isDefaultSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged(),
|
||||
{ defaultSms, smsPermission, contactPermission ->
|
||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
})
|
||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged())
|
||||
{ defaultSms, smsPermission, contactPermission ->
|
||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -138,12 +138,12 @@ class MainViewModel @Inject constructor(
|
||||
.debounce(200, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { query -> query.removeAccents() }
|
||||
.withLatestFrom(state, { query, state ->
|
||||
.withLatestFrom(state) { query, state ->
|
||||
if (query.isEmpty() && state.page is Searching) {
|
||||
newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
|
||||
}
|
||||
query
|
||||
})
|
||||
}
|
||||
.filter { query -> query.length >= 2 }
|
||||
.doOnNext {
|
||||
newState {
|
||||
@@ -161,7 +161,7 @@ class MainViewModel @Inject constructor(
|
||||
.subscribe { navigator.showCompose() }
|
||||
|
||||
view.homeIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
.withLatestFrom(state) { _, state ->
|
||||
when {
|
||||
state.page is Searching -> view.clearSearch()
|
||||
|
||||
@@ -172,7 +172,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
else -> newState { copy(drawerOpen = true) }
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -199,7 +199,7 @@ class MainViewModel @Inject constructor(
|
||||
.subscribe()
|
||||
|
||||
view.optionsItemIntent
|
||||
.withLatestFrom(view.conversationsSelectedIntent, { itemId, conversations ->
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { itemId, conversations ->
|
||||
when (itemId) {
|
||||
R.id.read -> {
|
||||
markRead.execute(conversations)
|
||||
@@ -228,7 +228,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
R.id.delete -> view.showDeleteDialog()
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -244,7 +244,7 @@ class MainViewModel @Inject constructor(
|
||||
.subscribe { ratingManager.dismiss() }
|
||||
|
||||
view.conversationsSelectedIntent
|
||||
.withLatestFrom(state, { selection, state ->
|
||||
.withLatestFrom(state) { selection, state ->
|
||||
val read = selection
|
||||
.mapNotNull(conversationRepo::getConversation)
|
||||
.sumBy { if (it.read) -1 else 1 } >= 0
|
||||
@@ -261,13 +261,13 @@ class MainViewModel @Inject constructor(
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Delete the conversation
|
||||
view.confirmDeleteIntent
|
||||
.withLatestFrom(view.conversationsSelectedIntent, { _, conversations -> conversations })
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations -> conversations }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversations ->
|
||||
deleteConversations.execute(conversations)
|
||||
@@ -275,44 +275,44 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
view.swipeConversationIntent
|
||||
.withLatestFrom(state, { threadId, state ->
|
||||
.withLatestFrom(state) { threadId, state ->
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = true)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
.switchMap { Observable.timer(2750, TimeUnit.MILLISECONDS) }
|
||||
.withLatestFrom(state, { threadId, state ->
|
||||
.withLatestFrom(state) { threadId, state ->
|
||||
markArchived.execute(listOf(threadId)) {
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(showArchivedSnackbar = false)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.undoSwipeConversationIntent
|
||||
.withLatestFrom(view.swipeConversationIntent, { _, threadId -> threadId })
|
||||
.withLatestFrom(view.swipeConversationIntent) { _, threadId -> threadId }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnarchived.execute(listOf(threadId)) }
|
||||
|
||||
view.snackbarButtonIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
.withLatestFrom(state) { _, state ->
|
||||
when {
|
||||
!state.smsPermission -> view.requestPermissions()
|
||||
!state.defaultSms -> navigator.showDefaultSmsDialog()
|
||||
!state.contactPermission -> view.requestPermissions()
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.backPressedIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
.withLatestFrom(state) { _, state ->
|
||||
when {
|
||||
state.drawerOpen -> newState { copy(drawerOpen = false) }
|
||||
|
||||
@@ -327,7 +327,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
// Mark read
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.read }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> conversation.id }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId ->
|
||||
@@ -121,7 +121,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
// Call
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.call }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.mapNotNull { conversation -> conversation.recipients.first()?.address }
|
||||
.doOnNext { address -> navigator.makePhoneCall(address) }
|
||||
.autoDisposable(view.scope())
|
||||
@@ -130,7 +130,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
// Show all messages
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.expand }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> messageRepo.getMessages(conversation.id) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
@@ -139,7 +139,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
// Show unread messages only
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.collapse }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
@@ -148,7 +148,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
// View conversation
|
||||
view.menuItemIntent
|
||||
.filter { id -> id == R.id.view }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> conversation.id }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
.autoDisposable(view.scope())
|
||||
@@ -184,9 +184,9 @@ class QkReplyViewModel @Inject constructor(
|
||||
.debounce(100, TimeUnit.MILLISECONDS)
|
||||
.map { draft -> draft.toString() }
|
||||
.observeOn(Schedulers.io())
|
||||
.withLatestFrom(conversation.map { it.id }, { draft, threadId ->
|
||||
.withLatestFrom(conversation.map { it.id }) { draft, threadId ->
|
||||
conversationRepo.saveDraft(threadId, draft)
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -207,16 +207,16 @@ class QkReplyViewModel @Inject constructor(
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
||||
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(state, conversation, { body, state, conversation ->
|
||||
.withLatestFrom(state, conversation) { body, state, conversation ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body))
|
||||
view.setDraft("")
|
||||
threadId
|
||||
})
|
||||
}
|
||||
.doOnNext { threadId ->
|
||||
markRead.execute(listOf(threadId)) {
|
||||
newState { copy(hasError = true) }
|
||||
|
||||
@@ -140,7 +140,7 @@ class SettingsActivity : QkThemedActivity(), SettingsView {
|
||||
|
||||
override fun showQksmsPlusSnackbar() {
|
||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||
setAction(R.string.button_more, { viewQksmsPlusIntent.onNext(Unit) })
|
||||
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,9 +153,9 @@ class SettingsViewModel @Inject constructor(
|
||||
|
||||
R.id.sync -> {
|
||||
newState { copy(syncing = true) }
|
||||
syncMessages.execute(Unit, {
|
||||
syncMessages.execute(Unit) {
|
||||
newState { copy(syncing = false) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
R.id.about -> navigator.showAbout()
|
||||
@@ -163,13 +163,13 @@ class SettingsViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
view.nightModeSelectedIntent
|
||||
.withLatestFrom(billingManager.upgradeStatus, { mode, upgraded ->
|
||||
.withLatestFrom(billingManager.upgradeStatus) { mode, upgraded ->
|
||||
if (!upgraded && mode == Preferences.NIGHT_MODE_AUTO) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
nightModeManager.updateNightMode(mode)
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -190,13 +190,13 @@ class SettingsViewModel @Inject constructor(
|
||||
.subscribe { prefs.textSize.set(it) }
|
||||
|
||||
view.sendDelayChangedIntent
|
||||
.withLatestFrom(billingManager.upgradeStatus, { duration, upgraded ->
|
||||
.withLatestFrom(billingManager.upgradeStatus) { duration, upgraded ->
|
||||
if (!upgraded && duration != 0) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
prefs.sendDelay.set(duration)
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ class ThemePickerActivity : QkThemedActivity(), ThemePickerView {
|
||||
|
||||
override fun showQksmsPlusSnackbar() {
|
||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||
setAction(R.string.button_more, { viewQksmsPlusIntent.onNext(Unit) })
|
||||
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -62,20 +62,20 @@ class ThemePickerViewModel @Inject constructor(
|
||||
.subscribe()
|
||||
|
||||
// Toggle the visibility of the apply group
|
||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent, { old, new -> old != new })
|
||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent) { old, new -> old != new }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
||||
|
||||
// Update the theme, when apply is clicked
|
||||
view.hsvThemeAppliedIntent
|
||||
.withLatestFrom(view.hsvThemeSelectedIntent, { _, color -> color })
|
||||
.withLatestFrom(billingManager.upgradeStatus, { color, upgraded ->
|
||||
.withLatestFrom(view.hsvThemeSelectedIntent) { _, color -> color }
|
||||
.withLatestFrom(billingManager.upgradeStatus) { color, upgraded ->
|
||||
if (!upgraded) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
theme.set(color)
|
||||
}
|
||||
})
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -86,7 +86,7 @@ class ThemePickerViewModel @Inject constructor(
|
||||
|
||||
// Reset the theme
|
||||
view.hsvThemeClearedIntent
|
||||
.withLatestFrom(theme.asObservable(), { _, color -> color })
|
||||
.withLatestFrom(theme.asObservable()) { _, color -> color }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color -> view.setCurrentTheme(color) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user