From 74394445c98d01259c555d14bfa545741bebd16a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 4 Feb 2025 13:53:49 +0100 Subject: [PATCH] Improved toast API --- .../java/org/linphone/ui/GenericViewModel.kt | 18 ++++++++ .../viewmodel/AccountCreationViewModel.kt | 9 +--- .../viewmodel/AccountLoginViewModel.kt | 18 +------- .../ThirdPartySipAccountLoginViewModel.kt | 9 +--- .../viewmodel/ConferenceViewModel.kt | 18 +------- .../ui/call/viewmodel/CallsViewModel.kt | 9 +--- .../ui/call/viewmodel/CurrentCallViewModel.kt | 9 +--- .../ui/fileviewer/viewmodel/FileViewModel.kt | 42 ++--------------- .../ConversationForwardMessageFragment.kt | 7 +-- .../AbstractConversationViewModel.kt | 18 +------- .../ConversationForwardMessageViewModel.kt | 27 ++--------- .../viewmodel/ConversationInfoViewModel.kt | 46 ++++--------------- .../chat/viewmodel/ConversationViewModel.kt | 24 ++-------- .../viewmodel/ConversationsListViewModel.kt | 7 +-- .../SendMessageInConversationViewModel.kt | 28 ++--------- .../viewmodel/ContactNewOrEditViewModel.kt | 9 +--- .../viewmodel/ContactsListViewModel.kt | 4 +- .../history/viewmodel/StartCallViewModel.kt | 18 +------- .../viewmodel/ScheduleMeetingViewModel.kt | 36 ++------------- .../RecordingMediaPlayerViewModel.kt | 7 +-- .../viewmodel/AccountProfileViewModel.kt | 9 +--- .../settings/viewmodel/CardDavViewModel.kt | 36 ++------------- .../main/settings/viewmodel/LdapViewModel.kt | 15 +----- .../settings/viewmodel/SettingsViewModel.kt | 2 +- 24 files changed, 70 insertions(+), 355 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/GenericViewModel.kt b/app/src/main/java/org/linphone/ui/GenericViewModel.kt index 5ca903d01..b31e4ef38 100644 --- a/app/src/main/java/org/linphone/ui/GenericViewModel.kt +++ b/app/src/main/java/org/linphone/ui/GenericViewModel.kt @@ -19,6 +19,8 @@ */ package org.linphone.ui +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.linphone.utils.Event @@ -41,4 +43,20 @@ open class GenericViewModel : ViewModel() { val showFormattedRedToastEvent: MutableLiveData>> by lazy { MutableLiveData>>() } + + fun showGreenToast(@StringRes message: Int, @DrawableRes icon: Int) { + showGreenToastEvent.postValue(Event(Pair(message, icon))) + } + + fun showFormattedGreenToast(message: String, @DrawableRes icon: Int) { + showFormattedGreenToastEvent.postValue(Event(Pair(message, icon))) + } + + fun showRedToast(@StringRes message: Int, @DrawableRes icon: Int) { + showRedToastEvent.postValue(Event(Pair(message, icon))) + } + + fun showFormattedRedToast(message: String, @DrawableRes icon: Int) { + showFormattedRedToastEvent.postValue(Event(Pair(message, icon))) + } } diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt index d5bd307a1..493470f9f 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt @@ -168,14 +168,7 @@ class AccountCreationViewModel operationInProgress.postValue(false) if (!errorMessage.isNullOrEmpty()) { - showFormattedRedToastEvent.postValue( - Event( - Pair( - errorMessage, - R.drawable.warning_circle - ) - ) - ) + showFormattedRedToast(errorMessage, R.drawable.warning_circle) } for (parameter in parameterErrors?.keys.orEmpty()) { diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountLoginViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountLoginViewModel.kt index 629d73df5..285b0c42f 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountLoginViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountLoginViewModel.kt @@ -175,14 +175,7 @@ open class AccountLoginViewModel val identityAddress = Factory.instance().createAddress(identity) if (identityAddress == null) { Log.e("$TAG Can't parse [$identity] as Address!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.assistant_login_cant_parse_address_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.assistant_login_cant_parse_address_toast, R.drawable.warning_circle) return@postOnCoreThread } @@ -191,14 +184,7 @@ open class AccountLoginViewModel Log.e( "$TAG Address [${identityAddress.asStringUriOnly()}] doesn't contains an username!" ) - showRedToastEvent.postValue( - Event( - Pair( - R.string.assistant_login_address_without_username_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.assistant_login_address_without_username_toast, R.drawable.warning_circle) return@postOnCoreThread } diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt index 40a33b649..0e193edd8 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt @@ -199,14 +199,7 @@ class ThirdPartySipAccountLoginViewModel val identityAddress = Factory.instance().createAddress(identity) if (identityAddress == null) { Log.e("$TAG Can't parse [$identity] as Address!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.assistant_login_cant_parse_address_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.assistant_login_cant_parse_address_toast, R.drawable.warning_circle) return@postOnCoreThread } diff --git a/app/src/main/java/org/linphone/ui/call/conference/viewmodel/ConferenceViewModel.kt b/app/src/main/java/org/linphone/ui/call/conference/viewmodel/ConferenceViewModel.kt index ea4132f2d..6bfc4d5b1 100644 --- a/app/src/main/java/org/linphone/ui/call/conference/viewmodel/ConferenceViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/conference/viewmodel/ConferenceViewModel.kt @@ -410,14 +410,7 @@ class ConferenceViewModel Log.e( "$TAG Failed to parse SIP URI [$uri] into address, can't add it to the conference!" ) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_add_participant_invalid_address_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_add_participant_invalid_address_toast, R.drawable.warning_circle) } } val addressesArray = arrayOfNulls
(addresses.size) @@ -810,14 +803,7 @@ class ConferenceViewModel "$TAG Too many participant devices for grid layout, switching to active speaker layout" ) setNewLayout(ACTIVE_SPEAKER_LAYOUT) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_too_many_participants_for_mosaic_layout_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_too_many_participants_for_mosaic_layout_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt index db2cd71d1..f0480543c 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt @@ -231,14 +231,7 @@ class CallsViewModel val conference = LinphoneUtils.createGroupCall(defaultAccount, subject) if (conference == null) { Log.e("$TAG Failed to create conference!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_merge_calls_into_conference_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_merge_calls_into_conference_toast, R.drawable.warning_circle) } else { conference.addParticipants(core.calls) } diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 7a56c5295..6b6052fef 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -1486,13 +1486,6 @@ class CurrentCallViewModel @AnyThread private fun showRecordingToast() { - showGreenToastEvent.postValue( - Event( - Pair( - R.string.call_is_being_recorded, - R.drawable.record_fill - ) - ) - ) + showGreenToast(R.string.call_is_being_recorded, R.drawable.record_fill) } } diff --git a/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/FileViewModel.kt b/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/FileViewModel.kt index 31e4e6266..a2fb1bb25 100644 --- a/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/FileViewModel.kt +++ b/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/FileViewModel.kt @@ -239,24 +239,10 @@ class FileViewModel Log.i( "$TAG File [$filePath] has been successfully exported to documents" ) - showGreenToastEvent.postValue( - Event( - Pair( - R.string.file_successfully_exported_to_documents_toast, - R.drawable.check - ) - ) - ) + showGreenToast(R.string.file_successfully_exported_to_documents_toast, R.drawable.check) } else { Log.e("$TAG Failed to export file [$filePath] to documents!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.export_file_to_documents_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.export_file_to_documents_error_toast, R.drawable.warning_circle) } } } @@ -272,24 +258,13 @@ class FileViewModel Log.i( "$TAG Text has been successfully exported to documents" ) - showGreenToastEvent.postValue( - Event( - Pair( + showGreenToast( R.string.file_successfully_exported_to_documents_toast, R.drawable.check ) - ) - ) } else { Log.e("$TAG Failed to save text to documents!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.export_file_to_documents_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.export_file_to_documents_error_toast, R.drawable.warning_circle) } } } @@ -337,14 +312,7 @@ class FileViewModel // TODO FIXME : improve performances ! } catch (e: Exception) { Log.e("$TAG Exception trying to read file [$filePath] as text: $e") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_file_cant_be_opened_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_file_cant_be_opened_error_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationForwardMessageFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationForwardMessageFragment.kt index 71ceb7b56..a451df537 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationForwardMessageFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationForwardMessageFragment.kt @@ -38,7 +38,6 @@ import org.linphone.ui.main.contacts.model.ContactNumberOrAddressModel import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel import org.linphone.ui.main.fragment.SlidingPaneChildFragment import org.linphone.utils.DialogUtils -import org.linphone.utils.Event import org.linphone.utils.RecyclerViewHeaderDecoration @UiThread @@ -66,11 +65,7 @@ class ConversationForwardMessageFragment : SlidingPaneChildFragment() { override fun goBack(): Boolean { sharedViewModel.messageToForwardEvent.value?.consume { Log.w("$TAG Cancelling message forward") - viewModel.showRedToastEvent.postValue( - Event( - Pair(R.string.conversation_message_forward_cancelled_toast, R.drawable.forward) - ) - ) + viewModel.showRedToast(R.string.conversation_message_forward_cancelled_toast, R.drawable.forward) } return findNavController().popBackStack() diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/AbstractConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/AbstractConversationViewModel.kt index ca647937a..a5a9f1098 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/AbstractConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/AbstractConversationViewModel.kt @@ -173,14 +173,7 @@ abstract class AbstractConversationViewModel : GenericViewModel() { val conference = LinphoneUtils.createGroupCall(account, chatRoom.subject.orEmpty()) if (conference == null) { Log.e("$TAG Failed to create group call!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_create_group_call_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_create_group_call_toast, R.drawable.warning_circle) return@postOnCoreThread } @@ -199,14 +192,7 @@ abstract class AbstractConversationViewModel : GenericViewModel() { ) if (conference.inviteParticipants(participants, callParams) != 0) { Log.e("$TAG Failed to invite participants into group call!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_create_group_call_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_create_group_call_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationForwardMessageViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationForwardMessageViewModel.kt index 495c3170e..1ef593232 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationForwardMessageViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationForwardMessageViewModel.kt @@ -102,14 +102,7 @@ class ConversationForwardMessageViewModel Log.e("$TAG Conversation [$id] creation has failed!") chatRoom.removeListener(this) operationInProgress.postValue(false) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_failed_to_create_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_failed_to_create_toast, R.drawable.warning_circle) } } } @@ -222,14 +215,7 @@ class ConversationForwardMessageViewModel "$TAG Account is in secure mode, can't chat with SIP address of different domain [${remote.asStringUriOnly()}]" ) operationInProgress.postValue(false) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_invalid_participant_due_to_security_mode_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_invalid_participant_due_to_security_mode_toast, R.drawable.warning_circle) return } @@ -275,14 +261,7 @@ class ConversationForwardMessageViewModel } else { Log.e("$TAG Failed to create 1-1 conversation with [${remote.asStringUriOnly()}]!") operationInProgress.postValue(false) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_failed_to_create_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_failed_to_create_toast, R.drawable.warning_circle) } } else { Log.w( diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt index e9f1c2724..173c0d8eb 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt @@ -108,7 +108,7 @@ class ConversationInfoViewModel R.string.conversation_info_participant_added_to_conversation_toast, getParticipant(eventLog) ) - showFormattedGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle))) + showFormattedGreenToast(message, R.drawable.user_circle) computeParticipantsList() infoChangedEvent.postValue(Event(true)) @@ -121,7 +121,7 @@ class ConversationInfoViewModel R.string.conversation_info_participant_removed_from_conversation_toast, getParticipant(eventLog) ) - showFormattedGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle))) + showFormattedGreenToast(message, R.drawable.user_circle) computeParticipantsList() infoChangedEvent.postValue(Event(true)) @@ -143,7 +143,7 @@ class ConversationInfoViewModel getParticipant(eventLog) ) } - showFormattedGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle))) + showFormattedGreenToast(message, R.drawable.user_circle) computeParticipantsList() } @@ -153,9 +153,7 @@ class ConversationInfoViewModel Log.i( "$TAG Conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] has a new subject [${chatRoom.subject}]" ) - showGreenToastEvent.postValue( - Event(Pair(R.string.conversation_subject_changed_toast, R.drawable.check)) - ) + showGreenToast(R.string.conversation_subject_changed_toast, R.drawable.check) subject.postValue(chatRoom.subject) infoChangedEvent.postValue(Event(true)) @@ -166,34 +164,13 @@ class ConversationInfoViewModel Log.i("$TAG Ephemeral event [${eventLog.type}]") when (eventLog.type) { EventLog.Type.ConferenceEphemeralMessageEnabled -> { - showGreenToastEvent.postValue( - Event( - Pair( - R.string.conversation_ephemeral_messages_enabled_toast, - R.drawable.clock_countdown - ) - ) - ) + showGreenToast(R.string.conversation_ephemeral_messages_enabled_toast, R.drawable.clock_countdown) } EventLog.Type.ConferenceEphemeralMessageDisabled -> { - showGreenToastEvent.postValue( - Event( - Pair( - R.string.conversation_ephemeral_messages_disabled_toast, - R.drawable.clock_countdown - ) - ) - ) + showGreenToast(R.string.conversation_ephemeral_messages_disabled_toast, R.drawable.clock_countdown) } else -> { - showGreenToastEvent.postValue( - Event( - Pair( - R.string.conversation_ephemeral_messages_lifetime_changed_toast, - R.drawable.clock_countdown - ) - ) - ) + showGreenToast(R.string.conversation_ephemeral_messages_lifetime_changed_toast, R.drawable.clock_countdown) } } } @@ -431,14 +408,7 @@ class ConversationInfoViewModel val ok = chatRoom.addParticipants(toAddList.toTypedArray()) if (!ok) { Log.w("$TAG Failed to add some/all participants to the group!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_failed_to_add_participant_to_group_conversation_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_failed_to_add_participant_to_group_conversation_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt index 788346f7e..ad5227034 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt @@ -925,11 +925,7 @@ class ConversationViewModel } else { R.string.conversation_search_no_more_match } - showRedToastEvent.postValue( - Event( - Pair(message, R.drawable.magnifying_glass) - ) - ) + showRedToast(message, R.drawable.magnifying_glass) } else { Log.i( "$TAG Found result [${match.chatMessage?.messageId}] while looking up for message with text [$textToSearch] in direction [$direction] starting from message [${latestMatch?.chatMessage?.messageId}]" @@ -971,24 +967,10 @@ class ConversationViewModel Log.i( "$TAG File [$filePath] has been successfully exported to documents" ) - showGreenToastEvent.postValue( - Event( - Pair( - R.string.file_successfully_exported_to_documents_toast, - R.drawable.check - ) - ) - ) + showGreenToast(R.string.file_successfully_exported_to_documents_toast, R.drawable.check) } else { Log.e("$TAG Failed to export file [$filePath] to documents!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.export_file_to_documents_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.export_file_to_documents_error_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationsListViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationsListViewModel.kt index 996571137..55313548b 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationsListViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationsListViewModel.kt @@ -33,7 +33,6 @@ import org.linphone.core.Friend import org.linphone.core.tools.Log import org.linphone.ui.main.chat.model.ConversationModel import org.linphone.ui.main.viewmodel.AbstractMainViewModel -import org.linphone.utils.Event import org.linphone.utils.LinphoneUtils class ConversationsListViewModel @@ -231,11 +230,7 @@ class ConversationsListViewModel ) } - showGreenToastEvent.postValue( - Event( - Pair(R.string.conversation_deleted_toast, R.drawable.chat_teardrop_text) - ) - ) + showGreenToast(R.string.conversation_deleted_toast, R.drawable.chat_teardrop_text) } @WorkerThread diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt index eaf106b5b..c225aa2a2 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt @@ -364,14 +364,7 @@ class SendMessageInConversationViewModel Log.w( "$TAG Max number of attachments [$MAX_FILES_TO_ATTACH] reached, file [$file] won't be attached" ) - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_maximum_number_of_attachments_reached, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_maximum_number_of_attachments_reached, R.drawable.warning_circle) viewModelScope.launch { Log.i("$TAG Deleting temporary file [$file]") FileUtils.deleteFile(file) @@ -434,9 +427,7 @@ class SendMessageInConversationViewModel Log.i("$TAG Sending forwarded message") forwardedMessage.send() - showGreenToastEvent.postValue( - Event(Pair(R.string.conversation_message_forwarded_toast, R.drawable.forward)) - ) + showGreenToast(R.string.conversation_message_forwarded_toast, R.drawable.forward) } } } @@ -591,14 +582,7 @@ class SendMessageInConversationViewModel "$TAG Max duration for voice recording exceeded (${maxVoiceRecordDuration}ms), stopping." ) stopVoiceRecorder() - showRedToastEvent.postValue( - Event( - Pair( - R.string.conversation_voice_recording_max_duration_reached_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conversation_voice_recording_max_duration_reached_toast, R.drawable.warning_circle) } } }.launchIn(viewModelScope) @@ -663,11 +647,7 @@ class SendMessageInConversationViewModel val lowMediaVolume = AudioUtils.isMediaVolumeLow(context) if (lowMediaVolume) { Log.w("$TAG Media volume is low, notifying user as they may not hear voice message") - showRedToastEvent.postValue( - Event( - Pair(R.string.media_playback_low_volume_warning_toast, R.drawable.speaker_slash) - ) - ) + showRedToast(R.string.media_playback_low_volume_warning_toast, R.drawable.speaker_slash) } if (voiceRecordAudioFocusRequest == null) { diff --git a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt index 6a82e7d5c..7dab45091 100644 --- a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt @@ -145,14 +145,7 @@ class ContactNewOrEditViewModel val organization = company.value.orEmpty().trim() if (fn.isEmpty() && ln.isEmpty() && organization.isEmpty()) { Log.e("$TAG At least a mandatory field wasn't filled, aborting save") - showRedToastEvent.postValue( - Event( - Pair( - R.string.contact_editor_mandatory_field_not_filled_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.contact_editor_mandatory_field_not_filled_toast, R.drawable.warning_circle) return } diff --git a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactsListViewModel.kt b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactsListViewModel.kt index a42e96482..13b28858f 100644 --- a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactsListViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactsListViewModel.kt @@ -242,9 +242,7 @@ class ContactsListViewModel coreContext.contactsManager.contactRemoved(contactModel.friend) contactModel.friend.remove() coreContext.contactsManager.notifyContactsListChanged() - showGreenToastEvent.postValue( - Event(Pair(R.string.contact_deleted_toast, R.drawable.warning_circle)) - ) + showGreenToast(R.string.contact_deleted_toast, R.drawable.warning_circle) } } diff --git a/app/src/main/java/org/linphone/ui/main/history/viewmodel/StartCallViewModel.kt b/app/src/main/java/org/linphone/ui/main/history/viewmodel/StartCallViewModel.kt index 8c284e7ce..1be93d9f1 100644 --- a/app/src/main/java/org/linphone/ui/main/history/viewmodel/StartCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/history/viewmodel/StartCallViewModel.kt @@ -187,14 +187,7 @@ class StartCallViewModel val conference = LinphoneUtils.createGroupCall(account, subject.value.orEmpty()) if (conference == null) { Log.e("$TAG Failed to create group call!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_create_group_call_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_create_group_call_toast, R.drawable.warning_circle) operationInProgress.postValue(false) return@postOnCoreThread } @@ -215,14 +208,7 @@ class StartCallViewModel conference.addListener(conferenceListener) if (conference.inviteParticipants(participants, callParams) != 0) { Log.e("$TAG Failed to invite participants into group call!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.conference_failed_to_create_group_call_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.conference_failed_to_create_group_call_toast, R.drawable.warning_circle) operationInProgress.postValue(false) } } diff --git a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt index 8f1ffb02d..6b7af73bc 100644 --- a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt @@ -111,14 +111,7 @@ class ScheduleMeetingViewModel when (state) { ConferenceScheduler.State.Error -> { operationInProgress.postValue(false) - showRedToastEvent.postValue( - Event( - Pair( - R.string.meeting_failed_to_schedule_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.meeting_failed_to_schedule_toast, R.drawable.warning_circle) } ConferenceScheduler.State.Ready -> { val conferenceAddress = conferenceScheduler.info?.uri @@ -166,28 +159,14 @@ class ScheduleMeetingViewModel } participants.value.orEmpty().size -> { Log.e("$TAG No invitation sent!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.meeting_failed_to_send_invites_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.meeting_failed_to_send_invites_toast, R.drawable.warning_circle) } else -> { Log.w("$TAG [$failedCount] invitations couldn't have been sent for:") for (failed in failedInvitations.orEmpty()) { Log.w(failed.asStringUriOnly()) } - showRedToastEvent.postValue( - Event( - Pair( - R.string.meeting_failed_to_send_part_of_invites_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.meeting_failed_to_send_part_of_invites_toast, R.drawable.warning_circle) } } @@ -398,14 +377,7 @@ class ScheduleMeetingViewModel Log.e( "$TAG Either no subject was set or no participant was selected, can't schedule meeting." ) - showRedToastEvent.postValue( - Event( - Pair( - R.string.meeting_schedule_mandatory_field_not_filled_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.meeting_schedule_mandatory_field_not_filled_toast, R.drawable.warning_circle) return } diff --git a/app/src/main/java/org/linphone/ui/main/recordings/viewmodel/RecordingMediaPlayerViewModel.kt b/app/src/main/java/org/linphone/ui/main/recordings/viewmodel/RecordingMediaPlayerViewModel.kt index 9d1a017ee..f070e668b 100644 --- a/app/src/main/java/org/linphone/ui/main/recordings/viewmodel/RecordingMediaPlayerViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/recordings/viewmodel/RecordingMediaPlayerViewModel.kt @@ -38,7 +38,6 @@ import org.linphone.core.tools.Log import org.linphone.ui.GenericViewModel import org.linphone.ui.main.recordings.model.RecordingModel import org.linphone.utils.AudioUtils -import org.linphone.utils.Event class RecordingMediaPlayerViewModel @UiThread @@ -122,11 +121,7 @@ class RecordingMediaPlayerViewModel val lowMediaVolume = AudioUtils.isMediaVolumeLow(coreContext.context) if (lowMediaVolume) { Log.w("$TAG Media volume is low, notifying user as they may not hear voice message") - showRedToastEvent.postValue( - Event( - Pair(R.string.media_playback_low_volume_warning_toast, R.drawable.speaker_slash) - ) - ) + showRedToast(R.string.media_playback_low_volume_warning_toast, R.drawable.speaker_slash) } if (player.state == Player.State.Closed) { diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt index becd320b7..617e82747 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt @@ -156,14 +156,7 @@ class AccountProfileViewModel if (!errorMessage.isNullOrEmpty()) { when (request.type) { AccountManagerServicesRequest.Type.GetDevicesList, AccountManagerServicesRequest.Type.DeleteDevice -> { - showFormattedRedToastEvent.postValue( - Event( - Pair( - errorMessage, - R.drawable.warning_circle - ) - ) - ) + showFormattedRedToast(errorMessage, R.drawable.warning_circle) devicesFetchInProgress.postValue(false) } else -> {} diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/CardDavViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/CardDavViewModel.kt index 7ed1f7eb7..c4c26bdd8 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/CardDavViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/CardDavViewModel.kt @@ -81,14 +81,7 @@ class CardDavViewModel when (status) { FriendList.SyncStatus.Successful -> { syncInProgress.postValue(false) - showGreenToastEvent.postValue( - Event( - Pair( - R.string.settings_contacts_carddav_sync_successful_toast, - R.drawable.check - ) - ) - ) + showGreenToast(R.string.settings_contacts_carddav_sync_successful_toast, R.drawable.check) Log.i("$TAG Notifying contacts manager that contacts have changed") coreContext.contactsManager.notifyContactsListChanged() @@ -97,14 +90,7 @@ class CardDavViewModel } FriendList.SyncStatus.Failure -> { syncInProgress.postValue(false) - showRedToastEvent.postValue( - Event( - Pair( - R.string.settings_contacts_carddav_sync_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.settings_contacts_carddav_sync_error_toast, R.drawable.warning_circle) if (isEdit.value == false) { Log.e("$TAG Synchronization failed, removing Friend list from Core") friendList.removeListener(this) @@ -166,14 +152,7 @@ class CardDavViewModel } core.removeFriendList(friendList) Log.i("$TAG Removed friends list with display name [$name]") - showGreenToastEvent.postValue( - Event( - Pair( - R.string.settings_contacts_carddav_deleted_toast, - R.drawable.trash_simple - ) - ) - ) + showGreenToast(R.string.settings_contacts_carddav_deleted_toast, R.drawable.trash_simple) Log.i("$TAG Notifying contacts manager that contacts have changed") coreContext.contactsManager.notifyContactsListChanged() @@ -193,14 +172,7 @@ class CardDavViewModel val name = displayName.value.orEmpty().trim() val server = serverUrl.value.orEmpty().trim() if (name.isEmpty() || server.isEmpty()) { - showRedToastEvent.postValue( - Event( - Pair( - R.string.settings_contacts_carddav_mandatory_field_not_filled_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.settings_contacts_carddav_mandatory_field_not_filled_toast, R.drawable.warning_circle) return } diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/LdapViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/LdapViewModel.kt index dbfe0395c..45034be08 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/LdapViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/LdapViewModel.kt @@ -139,14 +139,7 @@ class LdapViewModel : GenericViewModel() { val server = serverUrl.value.orEmpty().trim() if (server.isEmpty()) { Log.e("$TAG Server field can't be empty!") - showRedToastEvent.postValue( - Event( - Pair( - R.string.settings_contacts_ldap_empty_server_error_toast, - R.drawable.warning_circle - ) - ) - ) + showRedToast(R.string.settings_contacts_ldap_empty_server_error_toast, R.drawable.warning_circle) return@postOnCoreThread } @@ -181,11 +174,7 @@ class LdapViewModel : GenericViewModel() { ldapServerOperationSuccessfulEvent.postValue(Event(true)) } catch (e: Exception) { Log.e("$TAG Exception while creating LDAP: $e") - showRedToastEvent.postValue( - Event( - Pair(R.string.settings_contacts_ldap_error_toast, R.drawable.warning_circle) - ) - ) + showRedToast(R.string.settings_contacts_ldap_error_toast, R.drawable.warning_circle) } } } diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt index ddee54845..daae133a0 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt @@ -332,7 +332,7 @@ class SettingsViewModel Log.i("$TAG VFS has been enabled") } } else { - showRedToastEvent.postValue(Event(Pair(R.string.settings_security_enable_vfs_failure_toast, R.drawable.warning_circle))) + showRedToast(R.string.settings_security_enable_vfs_failure_toast, R.drawable.warning_circle) isVfsEnabled.postValue(false) Log.e("$TAG Failed to enable VFS!") }