From 9b624d33d52fb7661f2057b243550219ccfee251 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 21 Jun 2018 08:57:08 -0400 Subject: [PATCH] Move lambdas outside of parentheses --- .../moez/QKSMS/extensions/CursorExtensions.kt | 4 +- .../moez/QKSMS/mapper/RatingManagerImpl.kt | 4 +- .../receiver/DefaultSmsChangedReceiver.kt | 2 +- .../com/moez/QKSMS/receiver/SmsReceiver.kt | 2 +- .../QKSMS/common/base/QkThemedActivity.kt | 4 +- .../QKSMS/feature/blocked/BlockedActivity.kt | 2 +- .../QKSMS/feature/blocked/BlockedViewModel.kt | 4 +- .../QKSMS/feature/compose/ComposeViewModel.kt | 58 +++++++++---------- .../ConversationInfoActivity.kt | 4 +- .../ConversationInfoViewModel.kt | 10 ++-- .../QKSMS/feature/gallery/GalleryViewModel.kt | 4 +- .../moez/QKSMS/feature/main/MainActivity.kt | 4 +- .../moez/QKSMS/feature/main/MainViewModel.kt | 44 +++++++------- .../QKSMS/feature/qkreply/QkReplyViewModel.kt | 20 +++---- .../feature/settings/SettingsActivity.kt | 2 +- .../feature/settings/SettingsViewModel.kt | 12 ++-- .../themepicker/ThemePickerActivity.kt | 2 +- .../themepicker/ThemePickerViewModel.kt | 10 ++-- 18 files changed, 96 insertions(+), 96 deletions(-) diff --git a/data/src/main/java/com/moez/QKSMS/extensions/CursorExtensions.kt b/data/src/main/java/com/moez/QKSMS/extensions/CursorExtensions.kt index 81af40c8..1214d0be 100644 --- a/data/src/main/java/com/moez/QKSMS/extensions/CursorExtensions.kt +++ b/data/src/main/java/com/moez/QKSMS/extensions/CursorExtensions.kt @@ -35,10 +35,10 @@ fun Cursor.forEach(closeOnComplete: Boolean = true, method: (Cursor) -> Unit = { } fun Cursor.map(map: (Cursor) -> T): List { - return List(count, { position -> + return List(count) { position -> moveToPosition(position) map(this) - }) + } } fun Cursor.mapWhile(map: (Cursor) -> T, predicate: (T) -> Boolean): ArrayList { diff --git a/data/src/main/java/com/moez/QKSMS/mapper/RatingManagerImpl.kt b/data/src/main/java/com/moez/QKSMS/mapper/RatingManagerImpl.kt index b3c0a322..161b0ed5 100644 --- a/data/src/main/java/com/moez/QKSMS/mapper/RatingManagerImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/mapper/RatingManagerImpl.kt @@ -40,10 +40,10 @@ class RatingManagerImpl @Inject constructor( override val shouldShowRating = Observables.combineLatest( sessions.asObservable(), rated.asObservable(), - dismissed.asObservable(), { sessions, rated, dismissed -> + dismissed.asObservable()) { sessions, rated, dismissed -> sessions > SESSION_THRESHOLD && !rated && !dismissed - }) + } override fun addSession() { sessions.set(sessions.get() + 1) diff --git a/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt b/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt index feeb1412..8f3b2d9c 100644 --- a/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt +++ b/data/src/main/java/com/moez/QKSMS/receiver/DefaultSmsChangedReceiver.kt @@ -40,7 +40,7 @@ class DefaultSmsChangedReceiver : BroadcastReceiver() { if (intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)) { val pendingResult = goAsync() - syncMessages.execute(Unit, { pendingResult.finish() }) + syncMessages.execute(Unit) { pendingResult.finish() } } } diff --git a/data/src/main/java/com/moez/QKSMS/receiver/SmsReceiver.kt b/data/src/main/java/com/moez/QKSMS/receiver/SmsReceiver.kt index ca94b094..b881843d 100644 --- a/data/src/main/java/com/moez/QKSMS/receiver/SmsReceiver.kt +++ b/data/src/main/java/com/moez/QKSMS/receiver/SmsReceiver.kt @@ -37,7 +37,7 @@ class SmsReceiver : BroadcastReceiver() { val subId = intent.extras?.getInt("subscription", -1) ?: -1 val pendingResult = goAsync() - receiveMessage.execute(ReceiveSms.Params(subId, messages), { pendingResult.finish() }) + receiveMessage.execute(ReceiveSms.Params(subId, messages)) { pendingResult.finish() } } } diff --git a/presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt b/presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt index 7c4c3b01..57c2a0fd 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt @@ -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 { diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt index f53cfc86..c0b1c9bd 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt @@ -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() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt index a90c48f4..b24338b7 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt @@ -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)) } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt index bc9a4a98..5df21e4e 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt @@ -143,7 +143,7 @@ class ComposeViewModel @Inject constructor( } disposables += contactsReducer - .scan(listOf(), { previousState, reducer -> reducer(previousState) }) + .scan(listOf()) { 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() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoActivity.kt index 81106231..bbb0c9f6 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoActivity.kt @@ -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() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoViewModel.kt index cc2a175b..a80860ca 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoViewModel.kt @@ -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)) } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt index 14be3add..dd565d3d 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt @@ -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) } } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt index b5831c5d..89c63dab 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt @@ -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() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt index 424df908..621d982f 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt @@ -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() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/qkreply/QkReplyViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/qkreply/QkReplyViewModel.kt index b02647fe..6d6648d0 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/qkreply/QkReplyViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/qkreply/QkReplyViewModel.kt @@ -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) } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsActivity.kt index 9476c98e..00393c8c 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsActivity.kt @@ -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() } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsViewModel.kt index 7c729204..4d7fd71e 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsViewModel.kt @@ -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() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerActivity.kt index 85653675..be49a9cb 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerActivity.kt @@ -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() } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerViewModel.kt index 67daf053..89328b2b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/themepicker/ThemePickerViewModel.kt @@ -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) } }