diff --git a/app/src/main/java/org/linphone/activities/Navigation.kt b/app/src/main/java/org/linphone/activities/Navigation.kt index 13c15d3e5..fa05d2006 100644 --- a/app/src/main/java/org/linphone/activities/Navigation.kt +++ b/app/src/main/java/org/linphone/activities/Navigation.kt @@ -448,7 +448,8 @@ internal fun ChatRoomCreationFragment.navigateToEmptyChatRoom() { internal fun GroupInfoFragment.navigateToChatRoomCreation(args: Bundle?) { if (findNavController().currentDestination?.id == R.id.groupInfoFragment) { - findNavController().navigate(R.id.action_groupInfoFragment_to_chatRoomCreationFragment, + findNavController().navigate( + R.id.action_groupInfoFragment_to_chatRoomCreationFragment, args, getLeftToRightAnimationNavOptions(R.id.chatRoomCreationFragment, true) ) diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/AbstractPhoneFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/AbstractPhoneFragment.kt index 4a8af9127..7620ee81b 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/AbstractPhoneFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/AbstractPhoneFragment.kt @@ -71,9 +71,9 @@ abstract class AbstractPhoneFragment : GenericFragment() .setTitle(getString(R.string.assistant_phone_number_info_title)) .setMessage( getString(R.string.assistant_phone_number_link_info_content) + "\n" + - getString( - R.string.assistant_phone_number_link_info_content_already_account - ) + getString( + R.string.assistant_phone_number_link_info_content_already_account + ) ) .setNegativeButton(getString(R.string.dialog_ok), null) .show() diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/AccountLoginFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/AccountLoginFragment.kt index 025f1f9f8..7d24a6a03 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/AccountLoginFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/AccountLoginFragment.kt @@ -74,51 +74,66 @@ class AccountLoginFragment : AbstractPhoneFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.invalidCredentialsEvent.observe( + viewLifecycleOwner, + { + it.consume { + val dialogViewModel = DialogViewModel(getString(R.string.assistant_error_invalid_credentials)) + val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel) + + dialogViewModel.showCancelButton { + viewModel.removeInvalidProxyConfig() + dialog.dismiss() + } + + dialogViewModel.showDeleteButton( + { + viewModel.continueEvenIfInvalidCredentials() + dialog.dismiss() + }, + getString(R.string.assistant_continue_even_if_credentials_invalid) + ) + + dialog.show() + } } - }) + ) + + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } + } + ) checkPermission() } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/EchoCancellerCalibrationFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/EchoCancellerCalibrationFragment.kt index 1fabd8b21..a2bd4de09 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/EchoCancellerCalibrationFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/EchoCancellerCalibrationFragment.kt @@ -43,11 +43,14 @@ class EchoCancellerCalibrationFragment : GenericFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } } - }) + ) } } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/EmailAccountValidationFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/EmailAccountValidationFragment.kt index bfadb786c..f862bd86f 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/EmailAccountValidationFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/EmailAccountValidationFragment.kt @@ -48,22 +48,28 @@ class EmailAccountValidationFragment : GenericFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } } - }) + ) } } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/GenericAccountLoginFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/GenericAccountLoginFragment.kt index 5e3f6a8d6..2e75bfa78 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/GenericAccountLoginFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/GenericAccountLoginFragment.kt @@ -53,41 +53,53 @@ class GenericAccountLoginFragment : GenericFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } } - }) + ) } } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountCreationFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountCreationFragment.kt index ddba38f88..e9c3f860c 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountCreationFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountCreationFragment.kt @@ -56,20 +56,26 @@ class PhoneAccountCreationFragment : AbstractPhoneFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } } - }) + ) checkPermission() } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountLinkingFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountLinkingFragment.kt index 288ebe5e8..59349028a 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountLinkingFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountLinkingFragment.kt @@ -71,30 +71,39 @@ class PhoneAccountLinkingFragment : AbstractPhoneFragment - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.leaveAssistantEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (LinphoneApplication.coreContext.core.isEchoCancellerCalibrationRequired) { + navigateToEchoCancellerCalibration() + } else { + requireActivity().finish() + } + } } - }) + ) + + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } + } + ) checkPermission() } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountValidationFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountValidationFragment.kt index eb33ed587..1d8f8d97c 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountValidationFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/PhoneAccountValidationFragment.kt @@ -58,32 +58,38 @@ class PhoneAccountValidationFragment : GenericFragment { - coreContext.contactsManager.updateLocalContacts() + viewModel.leaveAssistantEvent.observe( + viewLifecycleOwner, + { + it.consume { + when { + viewModel.isLogin.value == true || viewModel.isCreation.value == true -> { + coreContext.contactsManager.updateLocalContacts() - if (coreContext.core.isEchoCancellerCalibrationRequired) { - navigateToEchoCancellerCalibration() - } else { - requireActivity().finish() + if (coreContext.core.isEchoCancellerCalibrationRequired) { + navigateToEchoCancellerCalibration() + } else { + requireActivity().finish() + } + } + viewModel.isLinking.value == true -> { + val args = Bundle() + args.putString("Identity", "sip:${viewModel.accountCreator.username}@${viewModel.accountCreator.domain}") + navigateToAccountSettings(args) } - } - viewModel.isLinking.value == true -> { - val args = Bundle() - args.putString("Identity", "sip:${viewModel.accountCreator.username}@${viewModel.accountCreator.domain}") - navigateToAccountSettings(args) } } } - }) + ) - viewModel.onErrorEvent.observe(viewLifecycleOwner, { - it.consume { message -> - (requireActivity() as AssistantActivity).showSnackBar(message) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { message -> + (requireActivity() as AssistantActivity).showSnackBar(message) + } } - }) + ) val clipboard = requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager clipboard.addPrimaryClipChangedListener { diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/QrCodeFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/QrCodeFragment.kt index 404c75caa..720ade39d 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/QrCodeFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/QrCodeFragment.kt @@ -51,12 +51,15 @@ class QrCodeFragment : GenericFragment() { viewModel = ViewModelProvider(this).get(QrCodeViewModel::class.java) binding.viewModel = viewModel - viewModel.qrCodeFoundEvent.observe(viewLifecycleOwner, { - it.consume { url -> - sharedViewModel.remoteProvisioningUrl.value = url - findNavController().navigateUp() + viewModel.qrCodeFoundEvent.observe( + viewLifecycleOwner, + { + it.consume { url -> + sharedViewModel.remoteProvisioningUrl.value = url + findNavController().navigateUp() + } } - }) + ) viewModel.setBackCamera() if (!PermissionHelper.required(requireContext()).hasCameraPermission()) { diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/RemoteProvisioningFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/RemoteProvisioningFragment.kt index c2a15d650..8d8e5d163 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/RemoteProvisioningFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/RemoteProvisioningFragment.kt @@ -54,20 +54,23 @@ class RemoteProvisioningFragment : GenericFragment - if (success) { - if (coreContext.core.isEchoCancellerCalibrationRequired) { - navigateToEchoCancellerCalibration() + viewModel.fetchSuccessfulEvent.observe( + viewLifecycleOwner, + { + it.consume { success -> + if (success) { + if (coreContext.core.isEchoCancellerCalibrationRequired) { + navigateToEchoCancellerCalibration() + } else { + requireActivity().finish() + } } else { - requireActivity().finish() + val activity = requireActivity() as AssistantActivity + activity.showSnackBar(R.string.assistant_remote_provisioning_failure) } - } else { - val activity = requireActivity() as AssistantActivity - activity.showSnackBar(R.string.assistant_remote_provisioning_failure) } } - }) + ) viewModel.urlToFetch.value = sharedViewModel.remoteProvisioningUrl.value ?: coreContext.core.provisioningUri } diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt index 687e3e195..f198b517b 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt @@ -72,9 +72,12 @@ class WelcomeFragment : GenericFragment() { navigateToRemoteProvisioning() } - viewModel.termsAndPrivacyAccepted.observe(viewLifecycleOwner, { - if (it) corePreferences.readAndAgreeTermsAndPrivacy = true - }) + viewModel.termsAndPrivacyAccepted.observe( + viewLifecycleOwner, + { + if (it) corePreferences.readAndAgreeTermsAndPrivacy = true + } + ) setUpTermsAndPrivacyLinks() } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt index 4141b7a4f..3daca0267 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt @@ -30,7 +30,8 @@ import org.linphone.core.DialPlan import org.linphone.core.tools.Log import org.linphone.utils.PhoneNumberUtils -abstract class AbstractPhoneViewModel(val accountCreator: AccountCreator) : ViewModel(), +abstract class AbstractPhoneViewModel(val accountCreator: AccountCreator) : + ViewModel(), CountryPickerFragment.CountryPickedListener { val prefix = MutableLiveData() diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt index d8a20c7c1..c4b6c3de0 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt @@ -84,12 +84,12 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM private var proxyConfigToCheck: ProxyConfig? = null private val coreListener = object : CoreListenerStub() { - override fun onRegistrationStateChanged( - core: Core, - cfg: ProxyConfig, - state: RegistrationState, - message: String - ) { + override fun onRegistrationStateChanged( + core: Core, + cfg: ProxyConfig, + state: RegistrationState, + message: String + ) { if (cfg == proxyConfigToCheck) { Log.i("[Assistant] [Account Login] Registration state is $state: $message") if (state == RegistrationState.Ok) { diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt index 0d2734263..301a639ab 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt @@ -158,13 +158,13 @@ class EmailAccountCreationViewModel(val accountCreator: AccountCreator) : ViewMo private fun isCreateButtonEnabled(): Boolean { return username.value.orEmpty().isNotEmpty() && - email.value.orEmpty().isNotEmpty() && - password.value.orEmpty().isNotEmpty() && - passwordConfirmation.value.orEmpty().isNotEmpty() && - password.value == passwordConfirmation.value && - usernameError.value.orEmpty().isEmpty() && - emailError.value.orEmpty().isEmpty() && - passwordError.value.orEmpty().isEmpty() && - passwordConfirmationError.value.orEmpty().isEmpty() + email.value.orEmpty().isNotEmpty() && + password.value.orEmpty().isNotEmpty() && + passwordConfirmation.value.orEmpty().isNotEmpty() && + password.value == passwordConfirmation.value && + usernameError.value.orEmpty().isEmpty() && + emailError.value.orEmpty().isEmpty() && + passwordError.value.orEmpty().isEmpty() && + passwordConfirmationError.value.orEmpty().isEmpty() } } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt index dc2eb1273..12f533426 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt @@ -160,9 +160,11 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh private fun isCreateButtonEnabled(): Boolean { val usernameRegexp = corePreferences.config.getString("assistant", "username_regex", "^[a-z0-9+_.\\-]*\$") return isPhoneNumberOk() && usernameRegexp != null && - (useUsername.value == false || + ( + useUsername.value == false || username.value.orEmpty().matches(Regex(usernameRegexp)) && username.value.orEmpty().isNotEmpty() && - usernameError.value.orEmpty().isEmpty()) + usernameError.value.orEmpty().isEmpty() + ) } } diff --git a/app/src/main/java/org/linphone/activities/call/CallActivity.kt b/app/src/main/java/org/linphone/activities/call/CallActivity.kt index b9d28eee9..022537728 100644 --- a/app/src/main/java/org/linphone/activities/call/CallActivity.kt +++ b/app/src/main/java/org/linphone/activities/call/CallActivity.kt @@ -62,21 +62,27 @@ class CallActivity : ProximitySensorActivity() { sharedViewModel = ViewModelProvider(this).get(SharedCallViewModel::class.java) - sharedViewModel.toggleDrawerEvent.observe(this, { - it.consume { - if (binding.statsMenu.isDrawerOpen(Gravity.LEFT)) { - binding.statsMenu.closeDrawer(binding.sideMenuContent, true) - } else { - binding.statsMenu.openDrawer(binding.sideMenuContent, true) + sharedViewModel.toggleDrawerEvent.observe( + this, + { + it.consume { + if (binding.statsMenu.isDrawerOpen(Gravity.LEFT)) { + binding.statsMenu.closeDrawer(binding.sideMenuContent, true) + } else { + binding.statsMenu.openDrawer(binding.sideMenuContent, true) + } } } - }) + ) - sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.observe(this, { - it.consume { - viewModel.showMomentarily() + sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.observe( + this, + { + it.consume { + viewModel.showMomentarily() + } } - }) + ) coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface coreContext.core.nativePreviewWindowId = binding.localPreviewVideoSurface @@ -104,9 +110,12 @@ class CallActivity : ProximitySensorActivity() { videoZoomHelper = VideoZoomHelper(this, binding.remoteVideoSurface) - viewModel.proximitySensorEnabled.observe(this, { - enableProximitySensor(it) - }) + viewModel.proximitySensorEnabled.observe( + this, + { + enableProximitySensor(it) + } + ) } override fun onResume() { @@ -191,10 +200,10 @@ class CallActivity : ProximitySensorActivity() { private fun hideSystemUI() { window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN or - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or - View.SYSTEM_UI_FLAG_IMMERSIVE or - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or - View.SYSTEM_UI_FLAG_LAYOUT_STABLE or - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or + View.SYSTEM_UI_FLAG_IMMERSIVE or + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or + View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION } } diff --git a/app/src/main/java/org/linphone/activities/call/IncomingCallActivity.kt b/app/src/main/java/org/linphone/activities/call/IncomingCallActivity.kt index 4ce7ec9a2..76fb75e3d 100644 --- a/app/src/main/java/org/linphone/activities/call/IncomingCallActivity.kt +++ b/app/src/main/java/org/linphone/activities/call/IncomingCallActivity.kt @@ -78,19 +78,25 @@ class IncomingCallActivity : GenericActivity() { )[IncomingCallViewModel::class.java] binding.viewModel = viewModel - viewModel.callEndedEvent.observe(this, { - it.consume { - Log.i("[Incoming Call Activity] Call ended, finish activity") - finish() + viewModel.callEndedEvent.observe( + this, + { + it.consume { + Log.i("[Incoming Call Activity] Call ended, finish activity") + finish() + } } - }) + ) - viewModel.earlyMediaVideoEnabled.observe(this, { - if (it) { - Log.i("[Incoming Call Activity] Early media video being received, set native window id") - coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface + viewModel.earlyMediaVideoEnabled.observe( + this, + { + if (it) { + Log.i("[Incoming Call Activity] Early media video being received, set native window id") + coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface + } } - }) + ) val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val keyguardLocked = keyguardManager.isKeyguardLocked @@ -169,7 +175,8 @@ class IncomingCallActivity : GenericActivity() { private fun findIncomingCall(): Call? { for (call in coreContext.core.calls) { if (call.state == Call.State.IncomingReceived || - call.state == Call.State.IncomingEarlyMedia) { + call.state == Call.State.IncomingEarlyMedia + ) { return call } } diff --git a/app/src/main/java/org/linphone/activities/call/OutgoingCallActivity.kt b/app/src/main/java/org/linphone/activities/call/OutgoingCallActivity.kt index f8084213c..99bdaca4b 100644 --- a/app/src/main/java/org/linphone/activities/call/OutgoingCallActivity.kt +++ b/app/src/main/java/org/linphone/activities/call/OutgoingCallActivity.kt @@ -79,41 +79,56 @@ class OutgoingCallActivity : ProximitySensorActivity() { controlsViewModel = ViewModelProvider(this).get(ControlsViewModel::class.java) binding.controlsViewModel = controlsViewModel - viewModel.callEndedEvent.observe(this, { - it.consume { - Log.i("[Outgoing Call Activity] Call ended, finish activity") - finish() + viewModel.callEndedEvent.observe( + this, + { + it.consume { + Log.i("[Outgoing Call Activity] Call ended, finish activity") + finish() + } } - }) + ) - viewModel.callConnectedEvent.observe(this, { - it.consume { - Log.i("[Outgoing Call Activity] Call connected, finish activity") - finish() + viewModel.callConnectedEvent.observe( + this, + { + it.consume { + Log.i("[Outgoing Call Activity] Call connected, finish activity") + finish() + } } - }) + ) - controlsViewModel.isSpeakerSelected.observe(this, { - enableProximitySensor(!it) - }) - - controlsViewModel.askPermissionEvent.observe(this, { - it.consume { permission -> - requestPermissions(arrayOf(permission), 0) + controlsViewModel.isSpeakerSelected.observe( + this, + { + enableProximitySensor(!it) } - }) + ) - controlsViewModel.toggleNumpadEvent.observe(this, { - it.consume { open -> - if (this::numpadAnimator.isInitialized) { - if (open) { - numpadAnimator.start() - } else { - numpadAnimator.reverse() + controlsViewModel.askPermissionEvent.observe( + this, + { + it.consume { permission -> + requestPermissions(arrayOf(permission), 0) + } + } + ) + + controlsViewModel.toggleNumpadEvent.observe( + this, + { + it.consume { open -> + if (this::numpadAnimator.isInitialized) { + if (open) { + numpadAnimator.start() + } else { + numpadAnimator.reverse() + } } } } - }) + ) if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) { checkPermissions() @@ -192,7 +207,8 @@ class OutgoingCallActivity : ProximitySensorActivity() { for (call in coreContext.core.calls) { if (call.state == Call.State.OutgoingInit || call.state == Call.State.OutgoingProgress || - call.state == Call.State.OutgoingRinging) { + call.state == Call.State.OutgoingRinging + ) { return call } } diff --git a/app/src/main/java/org/linphone/activities/call/VideoZoomHelper.kt b/app/src/main/java/org/linphone/activities/call/VideoZoomHelper.kt index 5e8a377c9..820bd3e95 100644 --- a/app/src/main/java/org/linphone/activities/call/VideoZoomHelper.kt +++ b/app/src/main/java/org/linphone/activities/call/VideoZoomHelper.kt @@ -39,26 +39,29 @@ class VideoZoomHelper(context: Context, private var videoDisplayView: View) : Ge init { val gestureDetector = GestureDetector(context, this) - scaleDetector = ScaleGestureDetector(context, object : - ScaleGestureDetector.SimpleOnScaleGestureListener() { - override fun onScale(detector: ScaleGestureDetector): Boolean { - zoomFactor *= detector.scaleFactor - // Don't let the object get too small or too large. - // Zoom to make the video fill the screen vertically - val portraitZoomFactor = videoDisplayView.height.toFloat() / (3 * videoDisplayView.width / 4) - // Zoom to make the video fill the screen horizontally - val landscapeZoomFactor = videoDisplayView.width.toFloat() / (3 * videoDisplayView.height / 4) - zoomFactor = max(0.1f, min(zoomFactor, max(portraitZoomFactor, landscapeZoomFactor))) + scaleDetector = ScaleGestureDetector( + context, + object : + ScaleGestureDetector.SimpleOnScaleGestureListener() { + override fun onScale(detector: ScaleGestureDetector): Boolean { + zoomFactor *= detector.scaleFactor + // Don't let the object get too small or too large. + // Zoom to make the video fill the screen vertically + val portraitZoomFactor = videoDisplayView.height.toFloat() / (3 * videoDisplayView.width / 4) + // Zoom to make the video fill the screen horizontally + val landscapeZoomFactor = videoDisplayView.width.toFloat() / (3 * videoDisplayView.height / 4) + zoomFactor = max(0.1f, min(zoomFactor, max(portraitZoomFactor, landscapeZoomFactor))) - val currentCall: Call? = coreContext.core.currentCall - if (currentCall != null) { - currentCall.zoom(zoomFactor, zoomCenterX, zoomCenterY) - return true + val currentCall: Call? = coreContext.core.currentCall + if (currentCall != null) { + currentCall.zoom(zoomFactor, zoomCenterX, zoomCenterY) + return true + } + + return false } - - return false } - }) + ) videoDisplayView.setOnTouchListener { _, event -> val currentZoomFactor = zoomFactor diff --git a/app/src/main/java/org/linphone/activities/call/fragments/ControlsFragment.kt b/app/src/main/java/org/linphone/activities/call/fragments/ControlsFragment.kt index eb47ad216..2537ddde7 100644 --- a/app/src/main/java/org/linphone/activities/call/fragments/ControlsFragment.kt +++ b/app/src/main/java/org/linphone/activities/call/fragments/ControlsFragment.kt @@ -80,101 +80,131 @@ class ControlsFragment : GenericFragment() { conferenceViewModel = ViewModelProvider(this).get(ConferenceViewModel::class.java) binding.conferenceViewModel = conferenceViewModel - callsViewModel.currentCallViewModel.observe(viewLifecycleOwner, { - if (it != null) { - binding.activeCallTimer.base = - SystemClock.elapsedRealtime() - (1000 * it.call.duration) // Linphone timestamps are in seconds - binding.activeCallTimer.start() - } - }) - - callsViewModel.noMoreCallEvent.observe(viewLifecycleOwner, { - it.consume { - requireActivity().finish() - } - }) - - callsViewModel.askWriteExternalStoragePermissionEvent.observe(viewLifecycleOwner, { - it.consume { - if (!PermissionHelper.get().hasWriteExternalStorage()) { - Log.i("[Controls Fragment] Asking for WRITE_EXTERNAL_STORAGE permission") - requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) + callsViewModel.currentCallViewModel.observe( + viewLifecycleOwner, + { + if (it != null) { + binding.activeCallTimer.base = + SystemClock.elapsedRealtime() - (1000 * it.call.duration) // Linphone timestamps are in seconds + binding.activeCallTimer.start() } } - }) + ) - callsViewModel.callUpdateEvent.observe(viewLifecycleOwner, { - it.consume { call -> - if (call.state == Call.State.StreamsRunning) { - dialog?.dismiss() - } else if (call.state == Call.State.UpdatedByRemote) { - if (coreContext.core.videoCaptureEnabled() || coreContext.core.videoDisplayEnabled()) { - if (call.currentParams.videoEnabled() != call.remoteParams?.videoEnabled()) { - showCallVideoUpdateDialog(call) + callsViewModel.noMoreCallEvent.observe( + viewLifecycleOwner, + { + it.consume { + requireActivity().finish() + } + } + ) + + callsViewModel.askWriteExternalStoragePermissionEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (!PermissionHelper.get().hasWriteExternalStorage()) { + Log.i("[Controls Fragment] Asking for WRITE_EXTERNAL_STORAGE permission") + requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) + } + } + } + ) + + callsViewModel.callUpdateEvent.observe( + viewLifecycleOwner, + { + it.consume { call -> + if (call.state == Call.State.StreamsRunning) { + dialog?.dismiss() + } else if (call.state == Call.State.UpdatedByRemote) { + if (coreContext.core.videoCaptureEnabled() || coreContext.core.videoDisplayEnabled()) { + if (call.currentParams.videoEnabled() != call.remoteParams?.videoEnabled()) { + showCallVideoUpdateDialog(call) + } + } else { + Log.w("[Controls Fragment] Video display & capture are disabled, don't show video dialog") } - } else { - Log.w("[Controls Fragment] Video display & capture are disabled, don't show video dialog") } } } - }) + ) - controlsViewModel.chatClickedEvent.observe(viewLifecycleOwner, { - it.consume { - val intent = Intent() - intent.setClass(requireContext(), MainActivity::class.java) - intent.putExtra("Chat", true) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(intent) + controlsViewModel.chatClickedEvent.observe( + viewLifecycleOwner, + { + it.consume { + val intent = Intent() + intent.setClass(requireContext(), MainActivity::class.java) + intent.putExtra("Chat", true) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + } } - }) + ) - controlsViewModel.addCallClickedEvent.observe(viewLifecycleOwner, { - it.consume { - val intent = Intent() - intent.setClass(requireContext(), MainActivity::class.java) - intent.putExtra("Dialer", true) - intent.putExtra("Transfer", false) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(intent) + controlsViewModel.addCallClickedEvent.observe( + viewLifecycleOwner, + { + it.consume { + val intent = Intent() + intent.setClass(requireContext(), MainActivity::class.java) + intent.putExtra("Dialer", true) + intent.putExtra("Transfer", false) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + } } - }) + ) - controlsViewModel.transferCallClickedEvent.observe(viewLifecycleOwner, { - it.consume { - val intent = Intent() - intent.setClass(requireContext(), MainActivity::class.java) - intent.putExtra("Dialer", true) - intent.putExtra("Transfer", true) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(intent) + controlsViewModel.transferCallClickedEvent.observe( + viewLifecycleOwner, + { + it.consume { + val intent = Intent() + intent.setClass(requireContext(), MainActivity::class.java) + intent.putExtra("Dialer", true) + intent.putExtra("Transfer", true) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + } } - }) + ) - controlsViewModel.askPermissionEvent.observe(viewLifecycleOwner, { - it.consume { permission -> - Log.i("[Controls Fragment] Asking for $permission permission") - requestPermissions(arrayOf(permission), 0) + controlsViewModel.askPermissionEvent.observe( + viewLifecycleOwner, + { + it.consume { permission -> + Log.i("[Controls Fragment] Asking for $permission permission") + requestPermissions(arrayOf(permission), 0) + } } - }) + ) - controlsViewModel.toggleNumpadEvent.observe(viewLifecycleOwner, { - it.consume { open -> - if (this::numpadAnimator.isInitialized) { - if (open) { - numpadAnimator.start() - } else { - numpadAnimator.reverse() + controlsViewModel.toggleNumpadEvent.observe( + viewLifecycleOwner, + { + it.consume { open -> + if (this::numpadAnimator.isInitialized) { + if (open) { + numpadAnimator.start() + } else { + numpadAnimator.reverse() + } } } } - }) + ) - controlsViewModel.somethingClickedEvent.observe(viewLifecycleOwner, { - it.consume { - sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.value = Event(true) + controlsViewModel.somethingClickedEvent.observe( + viewLifecycleOwner, + { + it.consume { + sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.value = Event(true) + } } - }) + ) if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) { checkPermissions() @@ -245,15 +275,21 @@ class ControlsFragment : GenericFragment() { val viewModel = DialogViewModel(AppUtils.getString(R.string.call_video_update_requested_dialog)) dialog = DialogUtils.getDialog(requireContext(), viewModel) - viewModel.showCancelButton({ - callsViewModel.answerCallVideoUpdateRequest(call, false) - dialog?.dismiss() - }, getString(R.string.dialog_decline)) + viewModel.showCancelButton( + { + callsViewModel.answerCallVideoUpdateRequest(call, false) + dialog?.dismiss() + }, + getString(R.string.dialog_decline) + ) - viewModel.showOkButton({ - callsViewModel.answerCallVideoUpdateRequest(call, true) - dialog?.dismiss() - }, getString(R.string.dialog_accept)) + viewModel.showOkButton( + { + callsViewModel.answerCallVideoUpdateRequest(call, true) + dialog?.dismiss() + }, + getString(R.string.dialog_accept) + ) dialog?.show() } diff --git a/app/src/main/java/org/linphone/activities/call/fragments/StatusFragment.kt b/app/src/main/java/org/linphone/activities/call/fragments/StatusFragment.kt index f04002642..7ee0f5632 100644 --- a/app/src/main/java/org/linphone/activities/call/fragments/StatusFragment.kt +++ b/app/src/main/java/org/linphone/activities/call/fragments/StatusFragment.kt @@ -62,13 +62,16 @@ class StatusFragment : GenericFragment() { viewModel.refreshRegister() } - viewModel.showZrtpDialogEvent.observe(viewLifecycleOwner, { - it.consume { call -> - if (call.state == Call.State.Connected || call.state == Call.State.StreamsRunning) { - showZrtpDialog(call) + viewModel.showZrtpDialogEvent.observe( + viewLifecycleOwner, + { + it.consume { call -> + if (call.state == Call.State.Connected || call.state == Call.State.StreamsRunning) { + showZrtpDialog(call) + } } } - }) + ) } override fun onCreate(savedInstanceState: Bundle?) { @@ -117,19 +120,25 @@ class StatusFragment : GenericFragment() { val dialog: Dialog = DialogUtils.getDialog(requireContext(), viewModel) - viewModel.showDeleteButton({ - call.authenticationTokenVerified = false - this@StatusFragment.viewModel.updateEncryptionInfo(call) - dialog.dismiss() - zrtpDialog = null - }, getString(R.string.zrtp_dialog_deny_button_label)) + viewModel.showDeleteButton( + { + call.authenticationTokenVerified = false + this@StatusFragment.viewModel.updateEncryptionInfo(call) + dialog.dismiss() + zrtpDialog = null + }, + getString(R.string.zrtp_dialog_deny_button_label) + ) - viewModel.showOkButton({ - call.authenticationTokenVerified = true - this@StatusFragment.viewModel.updateEncryptionInfo(call) - dialog.dismiss() - zrtpDialog = null - }, getString(R.string.zrtp_dialog_ok_button_label)) + viewModel.showOkButton( + { + call.authenticationTokenVerified = true + this@StatusFragment.viewModel.updateEncryptionInfo(call) + dialog.dismiss() + zrtpDialog = null + }, + getString(R.string.zrtp_dialog_ok_button_label) + ) zrtpDialog = dialog dialog.show() diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt index 881d298b4..3d317634a 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt @@ -148,15 +148,18 @@ open class CallViewModel(val call: Call) : GenericContactViewModel(call.remoteAd timer?.cancel() timer = Timer("Call update timeout") - timer?.schedule(object : TimerTask() { - override fun run() { - // Decline call update - viewModelScope.launch { - withContext(Dispatchers.Main) { - coreContext.answerCallVideoUpdateRequest(call, false) + timer?.schedule( + object : TimerTask() { + override fun run() { + // Decline call update + viewModelScope.launch { + withContext(Dispatchers.Main) { + coreContext.answerCallVideoUpdateRequest(call, false) + } } } - } - }, 30000) + }, + 30000 + ) } } diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsFadingViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsFadingViewModel.kt index 43eee9d1e..d2a8745f0 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsFadingViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsFadingViewModel.kt @@ -123,15 +123,18 @@ class ControlsFadingViewModel : ViewModel() { timer?.cancel() timer = Timer("Hide UI controls scheduler") - timer?.schedule(object : TimerTask() { - override fun run() { - viewModelScope.launch { - withContext(Dispatchers.Main) { - val videoEnabled = coreContext.isVideoCallOrConferenceActive() - areControlsHidden.postValue(videoEnabled) + timer?.schedule( + object : TimerTask() { + override fun run() { + viewModelScope.launch { + withContext(Dispatchers.Main) { + val videoEnabled = coreContext.isVideoCallOrConferenceActive() + areControlsHidden.postValue(videoEnabled) + } } } - } - }, 3000) + }, + 3000 + ) } } diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt index cb440ed10..35668bd37 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt @@ -445,8 +445,10 @@ class ControlsViewModel : ViewModel() { val core = coreContext.core val currentCall = core.currentCall isVideoAvailable.value = (core.videoCaptureEnabled() || core.videoPreviewEnabled()) && - ((currentCall != null && !currentCall.mediaInProgress()) || - core.conference?.isIn == true) + ( + (currentCall != null && !currentCall.mediaInProgress()) || + core.conference?.isIn == true + ) } private fun updateVideoEnabled() { diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/IncomingCallViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/IncomingCallViewModel.kt index bc35aedfb..64d4dc3fd 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/IncomingCallViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/IncomingCallViewModel.kt @@ -62,8 +62,8 @@ class IncomingCallViewModel(call: Call) : CallViewModel(call) { screenLocked.value = false inviteWithVideo.value = call.remoteParams?.videoEnabled() == true && coreContext.core.videoActivationPolicy.automaticallyAccept earlyMediaVideoEnabled.value = corePreferences.acceptEarlyMedia && - call.state == Call.State.IncomingEarlyMedia && - call.currentParams.videoEnabled() + call.state == Call.State.IncomingEarlyMedia && + call.currentParams.videoEnabled() } override fun onCleared() { diff --git a/app/src/main/java/org/linphone/activities/chat_bubble/ChatBubbleActivity.kt b/app/src/main/java/org/linphone/activities/chat_bubble/ChatBubbleActivity.kt index 11358e07c..607a0b9f4 100644 --- a/app/src/main/java/org/linphone/activities/chat_bubble/ChatBubbleActivity.kt +++ b/app/src/main/java/org/linphone/activities/chat_bubble/ChatBubbleActivity.kt @@ -73,7 +73,8 @@ class ChatBubbleActivity : GenericActivity() { val localAddress = Factory.instance().createAddress(localSipUri) val remoteSipAddress = Factory.instance().createAddress(remoteSipUri) chatRoom = coreContext.core.searchChatRoom( - null, localAddress, remoteSipAddress, arrayOfNulls( + null, localAddress, remoteSipAddress, + arrayOfNulls( 0 ) ) @@ -114,27 +115,36 @@ class ChatBubbleActivity : GenericActivity() { // Disable context menu on each message adapter.disableContextMenu() - adapter.openContentEvent.observe(this, { - it.consume { content -> - if (content.isFileEncrypted) { - Toast.makeText(this, R.string.chat_bubble_cant_open_enrypted_file, Toast.LENGTH_LONG).show() - } else { - FileUtils.openFileInThirdPartyApp(this, content.filePath.orEmpty(), true) + adapter.openContentEvent.observe( + this, + { + it.consume { content -> + if (content.isFileEncrypted) { + Toast.makeText(this, R.string.chat_bubble_cant_open_enrypted_file, Toast.LENGTH_LONG).show() + } else { + FileUtils.openFileInThirdPartyApp(this, content.filePath.orEmpty(), true) + } } } - }) + ) val layoutManager = LinearLayoutManager(this) layoutManager.stackFromEnd = true binding.chatMessagesList.layoutManager = layoutManager - listViewModel.events.observe(this, { events -> - adapter.submitList(events) - }) + listViewModel.events.observe( + this, + { events -> + adapter.submitList(events) + } + ) - chatSendingViewModel.textToSend.observe(this, { - chatSendingViewModel.onTextToSendChanged(it) - }) + chatSendingViewModel.textToSend.observe( + this, + { + chatSendingViewModel.onTextToSendChanged(it) + } + ) binding.setOpenAppClickListener { val intent = Intent(this, MainActivity::class.java) diff --git a/app/src/main/java/org/linphone/activities/main/MainActivity.kt b/app/src/main/java/org/linphone/activities/main/MainActivity.kt index 53fe64c31..ca8257781 100644 --- a/app/src/main/java/org/linphone/activities/main/MainActivity.kt +++ b/app/src/main/java/org/linphone/activities/main/MainActivity.kt @@ -121,21 +121,27 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin callOverlayViewModel = ViewModelProvider(this).get(CallOverlayViewModel::class.java) binding.callOverlayViewModel = callOverlayViewModel - sharedViewModel.toggleDrawerEvent.observe(this, { - it.consume { - if (binding.sideMenu.isDrawerOpen(Gravity.LEFT)) { - binding.sideMenu.closeDrawer(binding.sideMenuContent, true) - } else { - binding.sideMenu.openDrawer(binding.sideMenuContent, true) + sharedViewModel.toggleDrawerEvent.observe( + this, + { + it.consume { + if (binding.sideMenu.isDrawerOpen(Gravity.LEFT)) { + binding.sideMenu.closeDrawer(binding.sideMenuContent, true) + } else { + binding.sideMenu.openDrawer(binding.sideMenuContent, true) + } } } - }) + ) - coreContext.callErrorMessageResourceId.observe(this, { - it.consume { message -> - showSnackBar(message) + coreContext.callErrorMessageResourceId.observe( + this, + { + it.consume { message -> + showSnackBar(message) + } } - }) + ) if (coreContext.core.accountList.isEmpty()) { if (corePreferences.firstStart) { @@ -486,7 +492,8 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin } MotionEvent.ACTION_UP -> { if (abs(initPosX - view.x) < CorePreferences.OVERLAY_CLICK_SENSITIVITY && - abs(initPosY - view.y) < CorePreferences.OVERLAY_CLICK_SENSITIVITY) { + abs(initPosY - view.y) < CorePreferences.OVERLAY_CLICK_SENSITIVITY + ) { view.performClick() } } diff --git a/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatMessagesListAdapter.kt b/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatMessagesListAdapter.kt index 2d763370e..afc18450a 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatMessagesListAdapter.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatMessagesListAdapter.kt @@ -153,9 +153,12 @@ class ChatMessagesListAdapter( // This is for item selection through ListTopBarFragment selectionListViewModel = selectionViewModel - selectionViewModel.isEditionEnabled.observe(viewLifecycleOwner, { - position = adapterPosition - }) + selectionViewModel.isEditionEnabled.observe( + viewLifecycleOwner, + { + position = adapterPosition + } + ) setClickListener { if (selectionViewModel.isEditionEnabled.value == true) { @@ -213,7 +216,8 @@ class ChatMessagesListAdapter( val itemSize = AppUtils.getDimension(R.dimen.chat_message_popup_item_height).toInt() var totalSize = itemSize * 7 if (chatMessage.chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) || - chatMessage.state == ChatMessage.State.NotDelivered) { // No message id + chatMessage.state == ChatMessage.State.NotDelivered + ) { // No message id popupView.imdnHidden = true totalSize -= itemSize } @@ -236,7 +240,8 @@ class ChatMessagesListAdapter( // When using WRAP_CONTENT instead of real size, fails to place the // popup window above if not enough space is available below - val popupWindow = PopupWindow(popupView.root, + val popupWindow = PopupWindow( + popupView.root, AppUtils.getDimension(R.dimen.chat_message_popup_width).toInt(), totalSize, true @@ -354,9 +359,12 @@ class ChatMessagesListAdapter( // This is for item selection through ListTopBarFragment selectionListViewModel = selectionViewModel - selectionViewModel.isEditionEnabled.observe(viewLifecycleOwner, { - position = adapterPosition - }) + selectionViewModel.isEditionEnabled.observe( + viewLifecycleOwner, + { + position = adapterPosition + } + ) binding.setClickListener { if (selectionViewModel.isEditionEnabled.value == true) { @@ -376,9 +384,10 @@ private class ChatMessageDiffCallback : DiffUtil.ItemCallback() { newItem: EventLogData ): Boolean { return if (oldItem.eventLog.type == EventLog.Type.ConferenceChatMessage && - newItem.eventLog.type == EventLog.Type.ConferenceChatMessage) { + newItem.eventLog.type == EventLog.Type.ConferenceChatMessage + ) { oldItem.eventLog.chatMessage?.time == newItem.eventLog.chatMessage?.time && - oldItem.eventLog.chatMessage?.isOutgoing == newItem.eventLog.chatMessage?.isOutgoing + oldItem.eventLog.chatMessage?.isOutgoing == newItem.eventLog.chatMessage?.isOutgoing } else oldItem.eventLog.notifyId == newItem.eventLog.notifyId } diff --git a/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatRoomsListAdapter.kt b/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatRoomsListAdapter.kt index 796f445be..d99eacb7d 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatRoomsListAdapter.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/adapters/ChatRoomsListAdapter.kt @@ -72,9 +72,12 @@ class ChatRoomsListAdapter( // This is for item selection through ListTopBarFragment selectionListViewModel = selectionViewModel - selectionViewModel.isEditionEnabled.observe(viewLifecycleOwner, { - position = adapterPosition - }) + selectionViewModel.isEditionEnabled.observe( + viewLifecycleOwner, + { + position = adapterPosition + } + ) forwardPending = isForwardPending diff --git a/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt b/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt index 37c44ea20..0623cf4ac 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt @@ -47,7 +47,7 @@ class ChatMessageContentData( ) { var listener: OnContentClickedListener? = null - + val isOutgoing = chatMessage.isOutgoing val isImage = MutableLiveData() @@ -214,7 +214,7 @@ class ChatMessageContentData( isVoiceRecording.value = isVoiceRecord if (isVoiceRecord) { - val duration = content.fileDuration// duration is in ms + val duration = content.fileDuration // duration is in ms voiceRecordDuration.value = duration formattedDuration.value = SimpleDateFormat("mm:ss", Locale.getDefault()).format(duration) Log.i("[Voice Recording] Duration is ${voiceRecordDuration.value} ($duration)") diff --git a/app/src/main/java/org/linphone/activities/main/chat/data/EventData.kt b/app/src/main/java/org/linphone/activities/main/chat/data/EventData.kt index ae9f33d3d..eb7d0c9cf 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/data/EventData.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/data/EventData.kt @@ -35,7 +35,8 @@ class EventData(private val eventLog: EventLog) : GenericContactData( } else { eventLog.participantAddress!! } - }) { + } +) { val text = MutableLiveData() val isSecurity: Boolean by lazy { diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/ChatRoomCreationFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/ChatRoomCreationFragment.kt index e5a60c086..75fcd82e8 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/ChatRoomCreationFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/ChatRoomCreationFragment.kt @@ -90,42 +90,63 @@ class ChatRoomCreationFragment : SecureFragment viewModel.sipContactsSelected.value = true } - viewModel.contactsList.observe(viewLifecycleOwner, { - adapter.submitList(it) - }) - - viewModel.isEncrypted.observe(viewLifecycleOwner, { - adapter.updateSecurity(it) - }) - - viewModel.sipContactsSelected.observe(viewLifecycleOwner, { - viewModel.updateContactsList() - }) - - viewModel.selectedAddresses.observe(viewLifecycleOwner, { - adapter.updateSelectedAddresses(it) - }) - - viewModel.chatRoomCreatedEvent.observe(viewLifecycleOwner, { - it.consume { chatRoom -> - sharedViewModel.selectedChatRoom.value = chatRoom - navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) + viewModel.contactsList.observe( + viewLifecycleOwner, + { + adapter.submitList(it) } - }) + ) - viewModel.filter.observe(viewLifecycleOwner, { - viewModel.applyFilter() - }) + viewModel.isEncrypted.observe( + viewLifecycleOwner, + { + adapter.updateSecurity(it) + } + ) - adapter.selectedContact.observe(viewLifecycleOwner, { - it.consume { searchResult -> - if (createGroup) { - viewModel.toggleSelectionForSearchResult(searchResult) - } else { - viewModel.createOneToOneChat(searchResult) + viewModel.sipContactsSelected.observe( + viewLifecycleOwner, + { + viewModel.updateContactsList() + } + ) + + viewModel.selectedAddresses.observe( + viewLifecycleOwner, + { + adapter.updateSelectedAddresses(it) + } + ) + + viewModel.chatRoomCreatedEvent.observe( + viewLifecycleOwner, + { + it.consume { chatRoom -> + sharedViewModel.selectedChatRoom.value = chatRoom + navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) } } - }) + ) + + viewModel.filter.observe( + viewLifecycleOwner, + { + viewModel.applyFilter() + } + ) + + adapter.selectedContact.observe( + viewLifecycleOwner, + { + it.consume { searchResult -> + if (createGroup) { + viewModel.toggleSelectionForSearchResult(searchResult) + } else { + viewModel.createOneToOneChat(searchResult) + } + } + } + ) addParticipantsFromSharedViewModel() @@ -136,11 +157,14 @@ class ChatRoomCreationFragment : SecureFragment navigateToGroupInfo() } - viewModel.onErrorEvent.observe(viewLifecycleOwner, { - it.consume { messageResourceId -> - (activity as MainActivity).showSnackBar(messageResourceId) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { messageResourceId -> + (activity as MainActivity).showSnackBar(messageResourceId) + } } - }) + ) if (!PermissionHelper.get().hasReadContactsPermission()) { Log.i("[Chat Room Creation] Asking for READ_CONTACTS permission") diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt index 70779b967..35eb72db8 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt @@ -115,7 +115,8 @@ class DetailChatRoomFragment : MasterFragment - adapter.submitList(events) - }) - - listViewModel.messageUpdatedEvent.observe(viewLifecycleOwner, { - it.consume { position -> - adapter.notifyItemChanged(position) - } - }) - - listViewModel.requestWriteExternalStoragePermissionEvent.observe(viewLifecycleOwner, { - it.consume { - requestPermissions(arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) - } - }) - - adapter.deleteMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - listViewModel.deleteMessage(chatMessage) - } - }) - - adapter.resendMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - listViewModel.resendMessage(chatMessage) - } - }) - - adapter.forwardMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - // Remove observer before setting the message to forward - // as we don't want to forward it in this chat room - sharedViewModel.messageToForwardEvent.removeObservers(viewLifecycleOwner) - sharedViewModel.messageToForwardEvent.value = Event(chatMessage) - sharedViewModel.isPendingMessageForward.value = true - - if (sharedViewModel.canSlidingPaneBeClosed.value == true) { - Log.i("[Chat Room] Forwarding message, going to chat rooms list") - sharedViewModel.closeSlidingPaneEvent.value = Event(true) + chatSendingViewModel.requestRecordAudioPermissionEvent.observe( + viewLifecycleOwner, + { + it.consume { + Log.i("[Chat Room] Asking for RECORD_AUDIO permission") + requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2) } } - }) + ) - adapter.replyMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - chatSendingViewModel.pendingChatMessageToReplyTo.value?.destroy() - chatSendingViewModel.pendingChatMessageToReplyTo.value = ChatMessageData(chatMessage) - chatSendingViewModel.isPendingAnswer.value = true + listViewModel.events.observe( + viewLifecycleOwner, + { events -> + adapter.submitList(events) } - }) + ) - adapter.showImdnForMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - val args = Bundle() - args.putString("MessageId", chatMessage.messageId) - navigateToImdn(args) + listViewModel.messageUpdatedEvent.observe( + viewLifecycleOwner, + { + it.consume { position -> + adapter.notifyItemChanged(position) + } } - }) + ) - adapter.addSipUriToContactEvent.observe(viewLifecycleOwner, { - it.consume { sipUri -> - Log.i("[Chat Room] Going to contacts list with SIP URI to add: $sipUri") - navigateToContacts(sipUri) + listViewModel.requestWriteExternalStoragePermissionEvent.observe( + viewLifecycleOwner, + { + it.consume { + requestPermissions(arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) + } } - }) + ) - adapter.openContentEvent.observe(viewLifecycleOwner, { - it.consume { content -> - val path = content.filePath.orEmpty() + adapter.deleteMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + listViewModel.deleteMessage(chatMessage) + } + } + ) - if (!File(path).exists()) { - (requireActivity() as MainActivity).showSnackBar(R.string.chat_room_file_not_found) - } else { - Log.i("[Chat Message] Opening file: $path") - sharedViewModel.contentToOpen.value = content + adapter.resendMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + listViewModel.resendMessage(chatMessage) + } + } + ) - if (corePreferences.useInAppFileViewerForNonEncryptedFiles || content.isFileEncrypted) { - val preventScreenshots = - viewModel.chatRoom.currentParams.encryptionEnabled() - when { - FileUtils.isExtensionImage(path) -> navigateToImageFileViewer( - preventScreenshots - ) - FileUtils.isExtensionVideo(path) -> navigateToVideoFileViewer( - preventScreenshots - ) - FileUtils.isExtensionAudio(path) -> navigateToAudioFileViewer( - preventScreenshots - ) - FileUtils.isExtensionPdf(path) -> navigateToPdfFileViewer( - preventScreenshots - ) - FileUtils.isPlainTextFile(path) -> navigateToTextFileViewer( - preventScreenshots - ) - else -> { - if (content.isFileEncrypted) { - Log.w("[Chat Message] File is encrypted and can't be opened in one of our viewers...") - showDialogForUserConsentBeforeExportingFileInThirdPartyApp(content) - } else if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) { - showDialogToSuggestOpeningFileAsText() + adapter.forwardMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + // Remove observer before setting the message to forward + // as we don't want to forward it in this chat room + sharedViewModel.messageToForwardEvent.removeObservers(viewLifecycleOwner) + sharedViewModel.messageToForwardEvent.value = Event(chatMessage) + sharedViewModel.isPendingMessageForward.value = true + + if (sharedViewModel.canSlidingPaneBeClosed.value == true) { + Log.i("[Chat Room] Forwarding message, going to chat rooms list") + sharedViewModel.closeSlidingPaneEvent.value = Event(true) + } + } + } + ) + + adapter.replyMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + chatSendingViewModel.pendingChatMessageToReplyTo.value?.destroy() + chatSendingViewModel.pendingChatMessageToReplyTo.value = ChatMessageData(chatMessage) + chatSendingViewModel.isPendingAnswer.value = true + } + } + ) + + adapter.showImdnForMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + val args = Bundle() + args.putString("MessageId", chatMessage.messageId) + navigateToImdn(args) + } + } + ) + + adapter.addSipUriToContactEvent.observe( + viewLifecycleOwner, + { + it.consume { sipUri -> + Log.i("[Chat Room] Going to contacts list with SIP URI to add: $sipUri") + navigateToContacts(sipUri) + } + } + ) + + adapter.openContentEvent.observe( + viewLifecycleOwner, + { + it.consume { content -> + val path = content.filePath.orEmpty() + + if (!File(path).exists()) { + (requireActivity() as MainActivity).showSnackBar(R.string.chat_room_file_not_found) + } else { + Log.i("[Chat Message] Opening file: $path") + sharedViewModel.contentToOpen.value = content + + if (corePreferences.useInAppFileViewerForNonEncryptedFiles || content.isFileEncrypted) { + val preventScreenshots = + viewModel.chatRoom.currentParams.encryptionEnabled() + when { + FileUtils.isExtensionImage(path) -> navigateToImageFileViewer( + preventScreenshots + ) + FileUtils.isExtensionVideo(path) -> navigateToVideoFileViewer( + preventScreenshots + ) + FileUtils.isExtensionAudio(path) -> navigateToAudioFileViewer( + preventScreenshots + ) + FileUtils.isExtensionPdf(path) -> navigateToPdfFileViewer( + preventScreenshots + ) + FileUtils.isPlainTextFile(path) -> navigateToTextFileViewer( + preventScreenshots + ) + else -> { + if (content.isFileEncrypted) { + Log.w("[Chat Message] File is encrypted and can't be opened in one of our viewers...") + showDialogForUserConsentBeforeExportingFileInThirdPartyApp(content) + } else if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) { + showDialogToSuggestOpeningFileAsText() + } } } - } - } else { - if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) { - showDialogToSuggestOpeningFileAsText() + } else { + if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) { + showDialogToSuggestOpeningFileAsText() + } } } } } - }) + ) - adapter.scrollToChatMessageEvent.observe(viewLifecycleOwner, { - it.consume { chatMessage -> - val events = listViewModel.events.value.orEmpty() - val eventLog = events.find { eventLog -> - if (eventLog.eventLog.type == EventLog.Type.ConferenceChatMessage) { - (eventLog.data as ChatMessageData).chatMessage.messageId == chatMessage.messageId - } else false - } - val index = events.indexOf(eventLog) - try { - binding.chatMessagesList.smoothScrollToPosition(index) - } catch (iae: IllegalArgumentException) { - Log.e("[Chat Room] Can't scroll to position $index") + adapter.scrollToChatMessageEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + val events = listViewModel.events.value.orEmpty() + val eventLog = events.find { eventLog -> + if (eventLog.eventLog.type == EventLog.Type.ConferenceChatMessage) { + (eventLog.data as ChatMessageData).chatMessage.messageId == chatMessage.messageId + } else false + } + val index = events.indexOf(eventLog) + try { + binding.chatMessagesList.smoothScrollToPosition(index) + } catch (iae: IllegalArgumentException) { + Log.e("[Chat Room] Can't scroll to position $index") + } } } - }) + ) binding.setBackClickListener { goBack() @@ -336,7 +376,8 @@ class DetailChatRoomFragment : MasterFragment - Log.i("[Chat Room] Found message to transfer") - showForwardConfirmationDialog(chatMessage) - sharedViewModel.isPendingMessageForward.value = false + sharedViewModel.messageToForwardEvent.observe( + viewLifecycleOwner, + { + it.consume { chatMessage -> + Log.i("[Chat Room] Found message to transfer") + showForwardConfirmationDialog(chatMessage) + sharedViewModel.isPendingMessageForward.value = false + } } - }) + ) } override fun deleteItems(indexesOfItemToDelete: ArrayList) { @@ -464,10 +509,12 @@ class DetailChatRoomFragment : MasterFragment - if (doNotAskAgain) corePreferences.limeSecurityPopupEnabled = false + dialogViewModel.showOkButton( + { doNotAskAgain -> + if (doNotAskAgain) corePreferences.limeSecurityPopupEnabled = false - val address = viewModel.onlyParticipantOnlyDeviceAddress - if (viewModel.oneParticipantOneDevice) { - if (address != null) { - coreContext.startCall(address, true) + val address = viewModel.onlyParticipantOnlyDeviceAddress + if (viewModel.oneParticipantOneDevice) { + if (address != null) { + coreContext.startCall(address, true) + } + } else { + navigateToDevices() } - } else { - navigateToDevices() - } - dialog.dismiss() - }, okLabel) + dialog.dismiss() + }, + okLabel + ) dialog.show() } else { @@ -551,11 +601,14 @@ class DetailChatRoomFragment : MasterFragment() { adapter = GroupInfoParticipantsAdapter( viewLifecycleOwner, chatRoom?.hasCapability(ChatRoomCapabilities.Encrypted.toInt()) ?: viewModel.isEncrypted.value == true - ) + ) binding.participants.adapter = adapter val layoutManager = LinearLayoutManager(activity) @@ -83,25 +83,37 @@ class GroupInfoFragment : SecureFragment() { // Divider between items binding.participants.addItemDecoration(AppUtils.getDividerDecoration(requireContext(), layoutManager)) - viewModel.participants.observe(viewLifecycleOwner, { - adapter.submitList(it) - }) - - viewModel.isMeAdmin.observe(viewLifecycleOwner, { isMeAdmin -> - adapter.showAdminControls(isMeAdmin && chatRoom != null) - }) - - viewModel.meAdminChangedEvent.observe(viewLifecycleOwner, { - it.consume { isMeAdmin -> - showMeAdminStateChanged(isMeAdmin) + viewModel.participants.observe( + viewLifecycleOwner, + { + adapter.submitList(it) } - }) + ) - adapter.participantRemovedEvent.observe(viewLifecycleOwner, { - it.consume { participant -> - viewModel.removeParticipant(participant) + viewModel.isMeAdmin.observe( + viewLifecycleOwner, + { isMeAdmin -> + adapter.showAdminControls(isMeAdmin && chatRoom != null) } - }) + ) + + viewModel.meAdminChangedEvent.observe( + viewLifecycleOwner, + { + it.consume { isMeAdmin -> + showMeAdminStateChanged(isMeAdmin) + } + } + ) + + adapter.participantRemovedEvent.observe( + viewLifecycleOwner, + { + it.consume { participant -> + viewModel.removeParticipant(participant) + } + } + ) addParticipantsFromSharedViewModel() @@ -109,12 +121,15 @@ class GroupInfoFragment : SecureFragment() { goBack() } - viewModel.createdChatRoomEvent.observe(viewLifecycleOwner, { - it.consume { chatRoom -> - sharedViewModel.selectedChatRoom.value = chatRoom - navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) + viewModel.createdChatRoomEvent.observe( + viewLifecycleOwner, + { + it.consume { chatRoom -> + sharedViewModel.selectedChatRoom.value = chatRoom + navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) + } } - }) + ) binding.setNextClickListener { if (viewModel.chatRoom != null) { @@ -143,10 +158,13 @@ class GroupInfoFragment : SecureFragment() { val dialogViewModel = DialogViewModel(getString(R.string.chat_room_group_info_leave_dialog_message)) val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel) - dialogViewModel.showDeleteButton({ - viewModel.leaveGroup() - dialog.dismiss() - }, getString(R.string.chat_room_group_info_leave_dialog_button)) + dialogViewModel.showDeleteButton( + { + viewModel.leaveGroup() + dialog.dismiss() + }, + getString(R.string.chat_room_group_info_leave_dialog_button) + ) dialogViewModel.showCancelButton { dialog.dismiss() @@ -155,11 +173,14 @@ class GroupInfoFragment : SecureFragment() { dialog.show() } - viewModel.onErrorEvent.observe(viewLifecycleOwner, { - it.consume { messageResourceId -> - (activity as MainActivity).showSnackBar(messageResourceId) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { messageResourceId -> + (activity as MainActivity).showSnackBar(messageResourceId) + } } - }) + ) } private fun addParticipantsFromSharedViewModel() { @@ -175,9 +196,11 @@ class GroupInfoFragment : SecureFragment() { if (exists != null) { list.add(exists) } else { - list.add(GroupInfoParticipantData( - GroupChatRoomMember(address, false, hasLimeX3DHCapability = viewModel.isEncrypted.value == true) - )) + list.add( + GroupInfoParticipantData( + GroupChatRoomMember(address, false, hasLimeX3DHCapability = viewModel.isEncrypted.value == true) + ) + ) } } diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/ImdnFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/ImdnFragment.kt index eedb6a044..b781a15b1 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/ImdnFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/ImdnFragment.kt @@ -97,9 +97,12 @@ class ImdnFragment : SecureFragment() { val headerItemDecoration = RecyclerViewHeaderDecoration(requireContext(), adapter) binding.participantsList.addItemDecoration(headerItemDecoration) - viewModel.participants.observe(viewLifecycleOwner, { - adapter.submitList(it) - }) + viewModel.participants.observe( + viewLifecycleOwner, + { + adapter.submitList(it) + } + ) binding.setBackClickListener { goBack() diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/MasterChatRoomsFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/MasterChatRoomsFragment.kt index 2b9b32eb4..5f78b7753 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/MasterChatRoomsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/MasterChatRoomsFragment.kt @@ -92,25 +92,31 @@ class MasterChatRoomsFragment : MasterFragment - adapter.submitList(chatRooms) - }) - - listViewModel.contactsUpdatedEvent.observe(viewLifecycleOwner, { - it.consume { - adapter.notifyDataSetChanged() + listViewModel.chatRooms.observe( + viewLifecycleOwner, + { chatRooms -> + adapter.submitList(chatRooms) } - }) + ) - adapter.selectedChatRoomEvent.observe(viewLifecycleOwner, { - it.consume { chatRoom -> - if ((requireActivity() as GenericActivity).isDestructionPending) { - Log.w("[Chat] Activity is pending destruction, don't start navigating now!") - sharedViewModel.destructionPendingChatRoom = chatRoom - } else { - binding.slidingPane.openPane() - sharedViewModel.selectedChatRoom.value = chatRoom - navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) + listViewModel.contactsUpdatedEvent.observe( + viewLifecycleOwner, + { + it.consume { + adapter.notifyDataSetChanged() } } - }) + ) + + adapter.selectedChatRoomEvent.observe( + viewLifecycleOwner, + { + it.consume { chatRoom -> + if ((requireActivity() as GenericActivity).isDestructionPending) { + Log.w("[Chat] Activity is pending destruction, don't start navigating now!") + sharedViewModel.destructionPendingChatRoom = chatRoom + } else { + binding.slidingPane.openPane() + sharedViewModel.selectedChatRoom.value = chatRoom + navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel)) + } + } + } + ) binding.setEditClickListener { listSelectionViewModel.isEditionEnabled.value = true @@ -268,43 +287,55 @@ class MasterChatRoomsFragment : MasterFragment - (activity as MainActivity).showSnackBar(messageResourceId) + listViewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { messageResourceId -> + (activity as MainActivity).showSnackBar(messageResourceId) + } } - }) + ) } } diff --git a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageSendingViewModel.kt b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageSendingViewModel.kt index 724ac6dce..db0ac2931 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageSendingViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageSendingViewModel.kt @@ -149,9 +149,11 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel() fun addAttachment(path: String) { val list = arrayListOf() list.addAll(attachments.value.orEmpty()) - list.add(ChatMessageAttachmentData(path) { - removeAttachment(it) - }) + list.add( + ChatMessageAttachmentData(path) { + removeAttachment(it) + } + ) attachments.value = list sendMessageEnabled.value = textToSend.value.orEmpty().isNotEmpty() || list.isNotEmpty() || isPendingVoiceRecord.value == true diff --git a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatRoomViewModel.kt b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatRoomViewModel.kt index 5b2a1d5ac..d6c97d653 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatRoomViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatRoomViewModel.kt @@ -47,7 +47,7 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf override val displayName: MutableLiveData = MutableLiveData() override val securityLevel: MutableLiveData = MutableLiveData() override val showGroupChatAvatar: Boolean = chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) && - !chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) + !chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) val subject = MutableLiveData() @@ -310,8 +310,8 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf else chatRoom.peerAddress.asStringUriOnly() oneParticipantOneDevice = chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) && - chatRoom.me?.devices?.size == 1 && - chatRoom.participants.firstOrNull()?.devices?.size == 1 + chatRoom.me?.devices?.size == 1 && + chatRoom.participants.firstOrNull()?.devices?.size == 1 addressToCall = if (chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())) chatRoom.peerAddress diff --git a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/GroupInfoViewModel.kt b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/GroupInfoViewModel.kt index 4767964e6..4afa8ace0 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/GroupInfoViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/GroupInfoViewModel.kt @@ -211,9 +211,11 @@ class GroupInfoViewModel(val chatRoom: ChatRoom?) : ErrorReportingViewModel() { if (chatRoom != null) { for (participant in chatRoom.participants) { - list.add(GroupInfoParticipantData( - GroupChatRoomMember(participant.address, participant.isAdmin, participant.securityLevel, canBeSetAdmin = true) - )) + list.add( + GroupInfoParticipantData( + GroupChatRoomMember(participant.address, participant.isAdmin, participant.securityLevel, canBeSetAdmin = true) + ) + ) } } diff --git a/app/src/main/java/org/linphone/activities/main/chat/views/MultiLineWrapContentWidthTextView.kt b/app/src/main/java/org/linphone/activities/main/chat/views/MultiLineWrapContentWidthTextView.kt index b682b7b36..059f24c9c 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/views/MultiLineWrapContentWidthTextView.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/views/MultiLineWrapContentWidthTextView.kt @@ -47,9 +47,11 @@ class MultiLineWrapContentWidthTextView : AppCompatTextView { if (widthMode == MeasureSpec.AT_MOST) { val layout = layout if (layout != null) { - val maxWidth = (ceil(getMaxLineWidth(layout).toDouble()).toInt() + + val maxWidth = ( + ceil(getMaxLineWidth(layout).toDouble()).toInt() + totalPaddingLeft + - totalPaddingRight) + totalPaddingRight + ) wSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST) } } diff --git a/app/src/main/java/org/linphone/activities/main/contact/adapters/ContactsListAdapter.kt b/app/src/main/java/org/linphone/activities/main/contact/adapters/ContactsListAdapter.kt index bcc0d5208..ee2e554cb 100644 --- a/app/src/main/java/org/linphone/activities/main/contact/adapters/ContactsListAdapter.kt +++ b/app/src/main/java/org/linphone/activities/main/contact/adapters/ContactsListAdapter.kt @@ -70,9 +70,12 @@ class ContactsListAdapter( // This is for item selection through ListTopBarFragment selectionListViewModel = selectionViewModel - selectionViewModel.isEditionEnabled.observe(viewLifecycleOwner, { - position = adapterPosition - }) + selectionViewModel.isEditionEnabled.observe( + viewLifecycleOwner, + { + position = adapterPosition + } + ) setClickListener { if (selectionViewModel.isEditionEnabled.value == true) { diff --git a/app/src/main/java/org/linphone/activities/main/contact/fragments/DetailContactFragment.kt b/app/src/main/java/org/linphone/activities/main/contact/fragments/DetailContactFragment.kt index bb9d70ae1..ea230c123 100644 --- a/app/src/main/java/org/linphone/activities/main/contact/fragments/DetailContactFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/contact/fragments/DetailContactFragment.kt @@ -78,35 +78,44 @@ class DetailContactFragment : GenericFragment() { )[ContactViewModel::class.java] binding.viewModel = viewModel - viewModel.sendSmsToEvent.observe(viewLifecycleOwner, { - it.consume { number -> - sendSms(number) - } - }) - - viewModel.startCallToEvent.observe(viewLifecycleOwner, { - it.consume { address -> - if (coreContext.core.callsNb > 0) { - Log.i("[Contact] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") - val args = Bundle() - args.putString("URI", address.asStringUriOnly()) - args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) - args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it - navigateToDialer(args) - } else { - coreContext.startCall(address) + viewModel.sendSmsToEvent.observe( + viewLifecycleOwner, + { + it.consume { number -> + sendSms(number) } } - }) + ) - viewModel.chatRoomCreatedEvent.observe(viewLifecycleOwner, { - it.consume { chatRoom -> - val args = Bundle() - args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly()) - args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly()) - navigateToChatRoom(args) + viewModel.startCallToEvent.observe( + viewLifecycleOwner, + { + it.consume { address -> + if (coreContext.core.callsNb > 0) { + Log.i("[Contact] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") + val args = Bundle() + args.putString("URI", address.asStringUriOnly()) + args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) + args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it + navigateToDialer(args) + } else { + coreContext.startCall(address) + } + } } - }) + ) + + viewModel.chatRoomCreatedEvent.observe( + viewLifecycleOwner, + { + it.consume { chatRoom -> + val args = Bundle() + args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly()) + args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly()) + navigateToChatRoom(args) + } + } + ) binding.setBackClickListener { goBack() @@ -120,11 +129,14 @@ class DetailContactFragment : GenericFragment() { confirmContactRemoval() } - viewModel.onErrorEvent.observe(viewLifecycleOwner, { - it.consume { messageResourceId -> - (activity as MainActivity).showSnackBar(messageResourceId) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { messageResourceId -> + (activity as MainActivity).showSnackBar(messageResourceId) + } } - }) + ) } override fun goBack() { @@ -143,11 +155,14 @@ class DetailContactFragment : GenericFragment() { dialog.dismiss() } - dialogViewModel.showDeleteButton({ - viewModel.deleteContact() - dialog.dismiss() - goBack() - }, getString(R.string.dialog_delete)) + dialogViewModel.showDeleteButton( + { + viewModel.deleteContact() + dialog.dismiss() + goBack() + }, + getString(R.string.dialog_delete) + ) dialog.show() } diff --git a/app/src/main/java/org/linphone/activities/main/contact/fragments/MasterContactsFragment.kt b/app/src/main/java/org/linphone/activities/main/contact/fragments/MasterContactsFragment.kt index c15918f23..f0f26346b 100644 --- a/app/src/main/java/org/linphone/activities/main/contact/fragments/MasterContactsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/contact/fragments/MasterContactsFragment.kt @@ -80,25 +80,31 @@ class MasterContactsFragment : MasterFragment - Log.i("[Contacts] Selected item in list changed: $contact") - sharedViewModel.selectedContact.value = contact - listViewModel.filter.value = "" + adapter.selectedContactEvent.observe( + viewLifecycleOwner, + { + it.consume { contact -> + Log.i("[Contacts] Selected item in list changed: $contact") + sharedViewModel.selectedContact.value = contact + listViewModel.filter.value = "" - binding.slidingPane.openPane() - if (editOnClick) { - navigateToContactEditor(sipUriToAdd) - editOnClick = false - sipUriToAdd = null - } else { - navigateToContact() + binding.slidingPane.openPane() + if (editOnClick) { + navigateToContactEditor(sipUriToAdd) + editOnClick = false + sipUriToAdd = null + } else { + navigateToContact() + } } } - }) + ) - listViewModel.contactsList.observe(viewLifecycleOwner, { - val id = contactIdToDisplay - if (id != null) { - val contact = coreContext.contactsManager.findContactById(id) - if (contact != null) { - contactIdToDisplay = null - Log.i("[Contacts] Found matching contact $contact after callback") - adapter.selectedContactEvent.value = Event(contact) + listViewModel.contactsList.observe( + viewLifecycleOwner, + { + val id = contactIdToDisplay + if (id != null) { + val contact = coreContext.contactsManager.findContactById(id) + if (contact != null) { + contactIdToDisplay = null + Log.i("[Contacts] Found matching contact $contact after callback") + adapter.selectedContactEvent.value = Event(contact) + } } + adapter.submitList(it) } - adapter.submitList(it) - }) + ) binding.setAllContactsToggleClickListener { listViewModel.sipContactsSelected.value = false @@ -216,13 +232,19 @@ class MasterContactsFragment : MasterFragment image = - ImageUtils.rotateImage(image, 90f) - ExifInterface.ORIENTATION_ROTATE_180 -> image = - ImageUtils.rotateImage(image, 180f) - ExifInterface.ORIENTATION_ROTATE_270 -> image = - ImageUtils.rotateImage(image, 270f) + ExifInterface.ORIENTATION_ROTATE_90 -> + image = + ImageUtils.rotateImage(image, 90f) + ExifInterface.ORIENTATION_ROTATE_180 -> + image = + ImageUtils.rotateImage(image, 180f) + ExifInterface.ORIENTATION_ROTATE_270 -> + image = + ImageUtils.rotateImage(image, 270f) } val stream = ByteArrayOutputStream() diff --git a/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt b/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt index e5a0c03a8..9d5f0d517 100644 --- a/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt @@ -95,35 +95,44 @@ class DialerFragment : SecureFragment() { } arguments?.clear() - viewModel.enteredUri.observe(viewLifecycleOwner, { - if (it == corePreferences.debugPopupCode) { - displayDebugPopup() - viewModel.enteredUri.value = "" - } - }) - - viewModel.uploadFinishedEvent.observe(viewLifecycleOwner, { - it.consume { url -> - // To prevent being trigger when using the Send Logs button in About page - if (uploadLogsInitiatedByUs) { - val clipboard = - requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clip = ClipData.newPlainText("Logs url", url) - clipboard.setPrimaryClip(clip) - - val activity = requireActivity() as MainActivity - activity.showSnackBar(R.string.logs_url_copied_to_clipboard) - - AppUtils.shareUploadedLogsUrl(activity, url) + viewModel.enteredUri.observe( + viewLifecycleOwner, + { + if (it == corePreferences.debugPopupCode) { + displayDebugPopup() + viewModel.enteredUri.value = "" } } - }) + ) - viewModel.updateAvailableEvent.observe(viewLifecycleOwner, { - it.consume { url -> - displayNewVersionAvailableDialog(url) + viewModel.uploadFinishedEvent.observe( + viewLifecycleOwner, + { + it.consume { url -> + // To prevent being trigger when using the Send Logs button in About page + if (uploadLogsInitiatedByUs) { + val clipboard = + requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("Logs url", url) + clipboard.setPrimaryClip(clip) + + val activity = requireActivity() as MainActivity + activity.showSnackBar(R.string.logs_url_copied_to_clipboard) + + AppUtils.shareUploadedLogsUrl(activity, url) + } + } } - }) + ) + + viewModel.updateAvailableEvent.observe( + viewLifecycleOwner, + { + it.consume { url -> + displayNewVersionAvailableDialog(url) + } + } + ) Log.i("[Dialer] Pending call transfer mode = ${sharedViewModel.pendingCallTransfer}") viewModel.transferVisibility.value = sharedViewModel.pendingCallTransfer @@ -204,11 +213,14 @@ class DialerFragment : SecureFragment() { dialog.dismiss() } - viewModel.showOkButton({ - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - startActivity(browserIntent) - dialog.dismiss() - }, getString(R.string.dialog_ok)) + viewModel.showOkButton( + { + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + startActivity(browserIntent) + dialog.dismiss() + }, + getString(R.string.dialog_ok) + ) dialog.show() } diff --git a/app/src/main/java/org/linphone/activities/main/fragments/MasterFragment.kt b/app/src/main/java/org/linphone/activities/main/fragments/MasterFragment.kt index c70a07da5..d90e55118 100644 --- a/app/src/main/java/org/linphone/activities/main/fragments/MasterFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/fragments/MasterFragment.kt @@ -62,42 +62,57 @@ abstract class MasterFragment : GenericFragment() { val flags: Int = window.attributes.flags if ((enable && flags and WindowManager.LayoutParams.FLAG_SECURE != 0) || - (!enable && flags and WindowManager.LayoutParams.FLAG_SECURE == 0)) { + (!enable && flags and WindowManager.LayoutParams.FLAG_SECURE == 0) + ) { Log.d("[Secure Fragment] Secure flag is already ${if (enable) "enabled" else "disabled"}, skipping...") return } diff --git a/app/src/main/java/org/linphone/activities/main/fragments/StatusFragment.kt b/app/src/main/java/org/linphone/activities/main/fragments/StatusFragment.kt index 234f4232b..9a42663fb 100644 --- a/app/src/main/java/org/linphone/activities/main/fragments/StatusFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/fragments/StatusFragment.kt @@ -49,13 +49,16 @@ class StatusFragment : GenericFragment() { ViewModelProvider(this).get(SharedMainViewModel::class.java) } - sharedViewModel.accountRemoved.observe(viewLifecycleOwner, { - Log.i("[Status Fragment] An account was removed, update default account state") - val defaultAccount = coreContext.core.defaultAccount - if (defaultAccount != null) { - viewModel.updateDefaultAccountRegistrationStatus(defaultAccount.state) + sharedViewModel.accountRemoved.observe( + viewLifecycleOwner, + { + Log.i("[Status Fragment] An account was removed, update default account state") + val defaultAccount = coreContext.core.defaultAccount + if (defaultAccount != null) { + viewModel.updateDefaultAccountRegistrationStatus(defaultAccount.state) + } } - }) + ) binding.setMenuClickListener { sharedViewModel.toggleDrawerEvent.value = Event(true) diff --git a/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt b/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt index ee8f91d3b..ae1e80203 100644 --- a/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt +++ b/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt @@ -72,9 +72,12 @@ class CallLogsListAdapter( // This is for item selection through ListTopBarFragment selectionListViewModel = selectionViewModel - selectionViewModel.isEditionEnabled.observe(viewLifecycleOwner, { - position = adapterPosition - }) + selectionViewModel.isEditionEnabled.observe( + viewLifecycleOwner, + { + position = adapterPosition + } + ) setClickListener { if (selectionViewModel.isEditionEnabled.value == true) { diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt index b1c9e91ef..2592bf74d 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt @@ -94,40 +94,49 @@ class DetailCallLogFragment : GenericFragment() { } } - viewModel.startCallEvent.observe(viewLifecycleOwner, { - it.consume { callLog -> - val address = callLog.remoteAddress - if (coreContext.core.callsNb > 0) { - Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") - val args = Bundle() - args.putString("URI", address.asStringUriOnly()) - args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) - args.putBoolean( - "SkipAutoCallStart", - true - ) // If auto start call setting is enabled, ignore it - navigateToDialer(args) - } else { - val localAddress = callLog.localAddress - coreContext.startCall(address, localAddress = localAddress) + viewModel.startCallEvent.observe( + viewLifecycleOwner, + { + it.consume { callLog -> + val address = callLog.remoteAddress + if (coreContext.core.callsNb > 0) { + Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") + val args = Bundle() + args.putString("URI", address.asStringUriOnly()) + args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) + args.putBoolean( + "SkipAutoCallStart", + true + ) // If auto start call setting is enabled, ignore it + navigateToDialer(args) + } else { + val localAddress = callLog.localAddress + coreContext.startCall(address, localAddress = localAddress) + } } } - }) + ) - viewModel.chatRoomCreatedEvent.observe(viewLifecycleOwner, { - it.consume { chatRoom -> - val args = Bundle() - args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly()) - args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly()) - navigateToChatRoom(args) + viewModel.chatRoomCreatedEvent.observe( + viewLifecycleOwner, + { + it.consume { chatRoom -> + val args = Bundle() + args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly()) + args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly()) + navigateToChatRoom(args) + } } - }) + ) - viewModel.onErrorEvent.observe(viewLifecycleOwner, { - it.consume { messageResourceId -> - (activity as MainActivity).showSnackBar(messageResourceId) + viewModel.onErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { messageResourceId -> + (activity as MainActivity).showSnackBar(messageResourceId) + } } - }) + ) } override fun goBack() { diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt index d51eaf8e0..5cc600955 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt @@ -83,25 +83,31 @@ class MasterCallLogsFragment : MasterFragment - if (listViewModel.missedCallLogsSelected.value == false) { - adapter.submitList(callLogs) - } - }) - - listViewModel.missedCallLogs.observe(viewLifecycleOwner, { callLogs -> - if (listViewModel.missedCallLogsSelected.value == true) { - adapter.submitList(callLogs) - } - }) - - listViewModel.missedCallLogsSelected.observe(viewLifecycleOwner, { - if (it) { - adapter.submitList(listViewModel.missedCallLogs.value) - } else { - adapter.submitList(listViewModel.callLogs.value) - } - }) - - listViewModel.contactsUpdatedEvent.observe(viewLifecycleOwner, { - it.consume { - adapter.notifyDataSetChanged() - } - }) - - adapter.selectedCallLogEvent.observe(viewLifecycleOwner, { - it.consume { callLog -> - sharedViewModel.selectedCallLogGroup.value = callLog - binding.slidingPane.openPane() - navigateToCallHistory() - } - }) - - adapter.startCallToEvent.observe(viewLifecycleOwner, { - it.consume { callLogGroup -> - val remoteAddress = callLogGroup.lastCallLog.remoteAddress - if (coreContext.core.callsNb > 0) { - Log.i("[History] Starting dialer with pre-filled URI ${remoteAddress.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") - val args = Bundle() - args.putString("URI", remoteAddress.asStringUriOnly()) - args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) - args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it - navigateToDialer(args) - } else { - val localAddress = callLogGroup.lastCallLog.localAddress - coreContext.startCall(remoteAddress, localAddress = localAddress) + listViewModel.callLogs.observe( + viewLifecycleOwner, + { callLogs -> + if (listViewModel.missedCallLogsSelected.value == false) { + adapter.submitList(callLogs) } } - }) + ) + + listViewModel.missedCallLogs.observe( + viewLifecycleOwner, + { callLogs -> + if (listViewModel.missedCallLogsSelected.value == true) { + adapter.submitList(callLogs) + } + } + ) + + listViewModel.missedCallLogsSelected.observe( + viewLifecycleOwner, + { + if (it) { + adapter.submitList(listViewModel.missedCallLogs.value) + } else { + adapter.submitList(listViewModel.callLogs.value) + } + } + ) + + listViewModel.contactsUpdatedEvent.observe( + viewLifecycleOwner, + { + it.consume { + adapter.notifyDataSetChanged() + } + } + ) + + adapter.selectedCallLogEvent.observe( + viewLifecycleOwner, + { + it.consume { callLog -> + sharedViewModel.selectedCallLogGroup.value = callLog + binding.slidingPane.openPane() + navigateToCallHistory() + } + } + ) + + adapter.startCallToEvent.observe( + viewLifecycleOwner, + { + it.consume { callLogGroup -> + val remoteAddress = callLogGroup.lastCallLog.remoteAddress + if (coreContext.core.callsNb > 0) { + Log.i("[History] Starting dialer with pre-filled URI ${remoteAddress.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") + val args = Bundle() + args.putString("URI", remoteAddress.asStringUriOnly()) + args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) + args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it + navigateToDialer(args) + } else { + val localAddress = callLogGroup.lastCallLog.localAddress + coreContext.startCall(remoteAddress, localAddress = localAddress) + } + } + } + ) binding.setAllCallLogsToggleClickListener { listViewModel.missedCallLogsSelected.value = false diff --git a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt index b9a4e7025..a14fcc859 100644 --- a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt @@ -109,7 +109,8 @@ class CallLogsListViewModel : ViewModel() { if (previousCallLogGroup == null) { previousCallLogGroup = GroupedCallLogData(callLog) } else if (previousCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && - previousCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { + previousCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress) + ) { if (TimestampUtils.isSameDay(previousCallLogGroup.lastCallLog.startDate, callLog.startDate)) { previousCallLogGroup.callLogs.add(callLog) previousCallLogGroup.lastCallLog = callLog @@ -126,7 +127,8 @@ class CallLogsListViewModel : ViewModel() { if (previousMissedCallLogGroup == null) { previousMissedCallLogGroup = GroupedCallLogData(callLog) } else if (previousMissedCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && - previousMissedCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { + previousMissedCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress) + ) { if (TimestampUtils.isSameDay(previousMissedCallLogGroup.lastCallLog.startDate, callLog.startDate)) { previousMissedCallLogGroup.callLogs.add(callLog) previousMissedCallLogGroup.lastCallLog = callLog diff --git a/app/src/main/java/org/linphone/activities/main/recordings/fragments/RecordingsFragment.kt b/app/src/main/java/org/linphone/activities/main/recordings/fragments/RecordingsFragment.kt index eb972cac8..6d9da0a10 100644 --- a/app/src/main/java/org/linphone/activities/main/recordings/fragments/RecordingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/recordings/fragments/RecordingsFragment.kt @@ -68,9 +68,12 @@ class RecordingsFragment : MasterFragment - adapter.submitList(recordings) - }) + viewModel.recordingsList.observe( + viewLifecycleOwner, + { recordings -> + adapter.submitList(recordings) + } + ) binding.setBackClickListener { goBack() } diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt index f018af091..95c052750 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt @@ -59,7 +59,8 @@ class AccountSettingsFragment : GenericFragment( try { viewModel = ViewModelProvider(this, AccountSettingsViewModelFactory(identity)).get( - AccountSettingsViewModel::class.java) + AccountSettingsViewModel::class.java + ) } catch (nsee: NoSuchElementException) { Log.e("[Account Settings] Failed to find Account object, aborting!") goBack() @@ -69,27 +70,33 @@ class AccountSettingsFragment : GenericFragment( binding.setBackClickListener { goBack() } - viewModel.linkPhoneNumberEvent.observe(viewLifecycleOwner, { - it.consume { - val authInfo = viewModel.account.findAuthInfo() - if (authInfo == null) { - Log.e("[Account Settings] Failed to find auth info for account ${viewModel.account}") - } else { - val args = Bundle() - args.putString("Username", authInfo.username) - args.putString("Password", authInfo.password) - args.putString("HA1", authInfo.ha1) - navigateToPhoneLinking(args) + viewModel.linkPhoneNumberEvent.observe( + viewLifecycleOwner, + { + it.consume { + val authInfo = viewModel.account.findAuthInfo() + if (authInfo == null) { + Log.e("[Account Settings] Failed to find auth info for account ${viewModel.account}") + } else { + val args = Bundle() + args.putString("Username", authInfo.username) + args.putString("Password", authInfo.password) + args.putString("HA1", authInfo.ha1) + navigateToPhoneLinking(args) + } } } - }) + ) - viewModel.accountRemovedEvent.observe(viewLifecycleOwner, { - it.consume { - sharedViewModel.accountRemoved.value = true - goBack() + viewModel.accountRemovedEvent.observe( + viewLifecycleOwner, + { + it.consume { + sharedViewModel.accountRemoved.value = true + goBack() + } } - }) + ) } override fun goBack() { diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/AdvancedSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/AdvancedSettingsFragment.kt index 6e2fee106..dbf2ab0f8 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/AdvancedSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/AdvancedSettingsFragment.kt @@ -61,77 +61,104 @@ class AdvancedSettingsFragment : GenericFragment - val clipboard = - requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clip = ClipData.newPlainText("Logs url", url) - clipboard.setPrimaryClip(clip) + viewModel.uploadFinishedEvent.observe( + viewLifecycleOwner, + { + it.consume { url -> + val clipboard = + requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("Logs url", url) + clipboard.setPrimaryClip(clip) - val activity = requireActivity() as MainActivity - activity.showSnackBar(R.string.logs_url_copied_to_clipboard) + val activity = requireActivity() as MainActivity + activity.showSnackBar(R.string.logs_url_copied_to_clipboard) - AppUtils.shareUploadedLogsUrl(activity, url) + AppUtils.shareUploadedLogsUrl(activity, url) + } } - }) + ) - viewModel.uploadErrorEvent.observe(viewLifecycleOwner, { - it.consume { - val activity = requireActivity() as MainActivity - activity.showSnackBar(R.string.logs_upload_failure) + viewModel.uploadErrorEvent.observe( + viewLifecycleOwner, + { + it.consume { + val activity = requireActivity() as MainActivity + activity.showSnackBar(R.string.logs_upload_failure) + } } - }) + ) - viewModel.resetCompleteEvent.observe(viewLifecycleOwner, { - it.consume { - val activity = requireActivity() as MainActivity - activity.showSnackBar(R.string.logs_reset_complete) + viewModel.resetCompleteEvent.observe( + viewLifecycleOwner, + { + it.consume { + val activity = requireActivity() as MainActivity + activity.showSnackBar(R.string.logs_reset_complete) + } } - }) + ) - viewModel.setNightModeEvent.observe(viewLifecycleOwner, { - it.consume { value -> - AppCompatDelegate.setDefaultNightMode( - when (value) { - 0 -> AppCompatDelegate.MODE_NIGHT_NO - 1 -> AppCompatDelegate.MODE_NIGHT_YES - else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM - } - ) + viewModel.setNightModeEvent.observe( + viewLifecycleOwner, + { + it.consume { value -> + AppCompatDelegate.setDefaultNightMode( + when (value) { + 0 -> AppCompatDelegate.MODE_NIGHT_NO + 1 -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + } + ) + } } - }) + ) viewModel.backgroundModeEnabled.value = !DeviceUtils.isAppUserRestricted(requireContext()) - viewModel.goToBatterySettingsEvent.observe(viewLifecycleOwner, { it.consume { - try { - val intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS") - startActivity(intent) - } catch (anfe: ActivityNotFoundException) { - Log.e("[Advanced Settings] ActivityNotFound exception: ", anfe) - } - } }) - - viewModel.powerManagerSettingsVisibility.value = PowerManagerUtils.getDevicePowerManagerIntent(requireContext()) != null - viewModel.goToPowerManagerSettingsEvent.observe(viewLifecycleOwner, { it.consume { - val intent = PowerManagerUtils.getDevicePowerManagerIntent(requireActivity()) - if (intent != null) { - try { - startActivity(intent) - } catch (se: SecurityException) { - Log.e("[Advanced Settings] Security exception: ", se) + viewModel.goToBatterySettingsEvent.observe( + viewLifecycleOwner, + { + it.consume { + try { + val intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS") + startActivity(intent) + } catch (anfe: ActivityNotFoundException) { + Log.e("[Advanced Settings] ActivityNotFound exception: ", anfe) + } } } - } }) + ) - viewModel.goToAndroidSettingsEvent.observe(viewLifecycleOwner, { it.consume { - val intent = Intent() - intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - intent.addCategory(Intent.CATEGORY_DEFAULT) - intent.data = Uri.parse("package:${requireContext().packageName}") - intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) - ContextCompat.startActivity(requireContext(), intent, null) - } }) + viewModel.powerManagerSettingsVisibility.value = PowerManagerUtils.getDevicePowerManagerIntent(requireContext()) != null + viewModel.goToPowerManagerSettingsEvent.observe( + viewLifecycleOwner, + { + it.consume { + val intent = PowerManagerUtils.getDevicePowerManagerIntent(requireActivity()) + if (intent != null) { + try { + startActivity(intent) + } catch (se: SecurityException) { + Log.e("[Advanced Settings] Security exception: ", se) + } + } + } + } + ) + + viewModel.goToAndroidSettingsEvent.observe( + viewLifecycleOwner, + { + it.consume { + val intent = Intent() + intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS + intent.addCategory(Intent.CATEGORY_DEFAULT) + intent.data = Uri.parse("package:${requireContext().packageName}") + intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) + ContextCompat.startActivity(requireContext(), intent, null) + } + } + ) } override fun goBack() { diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/AudioSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/AudioSettingsFragment.kt index 5e3bc6fcf..f03b70a3b 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/AudioSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/AudioSettingsFragment.kt @@ -60,19 +60,25 @@ class AudioSettingsFragment : GenericFragment() { binding.setBackClickListener { goBack() } - viewModel.askAudioRecordPermissionForEchoCancellerCalibrationEvent.observe(viewLifecycleOwner, { - it.consume { - Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo canceller calibration") - requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 1) + viewModel.askAudioRecordPermissionForEchoCancellerCalibrationEvent.observe( + viewLifecycleOwner, + { + it.consume { + Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo canceller calibration") + requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 1) + } } - }) + ) - viewModel.askAudioRecordPermissionForEchoTesterEvent.observe(viewLifecycleOwner, { - it.consume { - Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo tester") - requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2) + viewModel.askAudioRecordPermissionForEchoTesterEvent.observe( + viewLifecycleOwner, + { + it.consume { + Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo tester") + requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2) + } } - }) + ) initAudioCodecsList() @@ -107,11 +113,14 @@ class AudioSettingsFragment : GenericFragment() { binding.setVariable(BR.title, payload.mimeType) binding.setVariable(BR.subtitle, "${payload.clockRate} Hz") binding.setVariable(BR.checked, payload.enabled()) - binding.setVariable(BR.listener, object : SettingListenerStub() { - override fun onBoolValueChanged(newValue: Boolean) { - payload.enable(newValue) + binding.setVariable( + BR.listener, + object : SettingListenerStub() { + override fun onBoolValueChanged(newValue: Boolean) { + payload.enable(newValue) + } } - }) + ) binding.lifecycleOwner = this list.add(binding) } diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/CallSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/CallSettingsFragment.kt index 6e17fae37..500b70b28 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/CallSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/CallSettingsFragment.kt @@ -57,31 +57,39 @@ class CallSettingsFragment : GenericFragment() { binding.setBackClickListener { goBack() } - viewModel.systemWideOverlayEnabledEvent.observe(viewLifecycleOwner, { - it.consume { - if (!Compatibility.canDrawOverlay(requireContext())) { - val intent = Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:${requireContext().packageName}")) - startActivityForResult(intent, 0) + viewModel.systemWideOverlayEnabledEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (!Compatibility.canDrawOverlay(requireContext())) { + val intent = Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:${requireContext().packageName}")) + startActivityForResult(intent, 0) + } } } - }) + ) - viewModel.goToAndroidNotificationSettingsEvent.observe(viewLifecycleOwner, { it.consume { - if (Build.VERSION.SDK_INT >= Version.API26_O_80) { - val i = Intent() - i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS - i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) - i.putExtra( - Settings.EXTRA_CHANNEL_ID, - getString(R.string.notification_channel_service_id) - ) - i.addCategory(Intent.CATEGORY_DEFAULT) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) - i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) - startActivity(i) + viewModel.goToAndroidNotificationSettingsEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (Build.VERSION.SDK_INT >= Version.API26_O_80) { + val i = Intent() + i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS + i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) + i.putExtra( + Settings.EXTRA_CHANNEL_ID, + getString(R.string.notification_channel_service_id) + ) + i.addCategory(Intent.CATEGORY_DEFAULT) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) + i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) + startActivity(i) + } + } } - } }) + ) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/ChatSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/ChatSettingsFragment.kt index 61ecc7ab1..a44b3c546 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/ChatSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/ChatSettingsFragment.kt @@ -56,32 +56,40 @@ class ChatSettingsFragment : GenericFragment() { binding.setBackClickListener { goBack() } - viewModel.launcherShortcutsEvent.observe(viewLifecycleOwner, { - it.consume { newValue -> - if (newValue) { - Compatibility.createShortcutsToChatRooms(requireContext()) - } else { - Compatibility.removeShortcuts(requireContext()) + viewModel.launcherShortcutsEvent.observe( + viewLifecycleOwner, + { + it.consume { newValue -> + if (newValue) { + Compatibility.createShortcutsToChatRooms(requireContext()) + } else { + Compatibility.removeShortcuts(requireContext()) + } } } - }) + ) - viewModel.goToAndroidNotificationSettingsEvent.observe(viewLifecycleOwner, { it.consume { - if (Build.VERSION.SDK_INT >= Version.API26_O_80) { - val i = Intent() - i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS - i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) - i.putExtra( - Settings.EXTRA_CHANNEL_ID, - getString(R.string.notification_channel_chat_id) - ) - i.addCategory(Intent.CATEGORY_DEFAULT) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) - i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) - startActivity(i) + viewModel.goToAndroidNotificationSettingsEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (Build.VERSION.SDK_INT >= Version.API26_O_80) { + val i = Intent() + i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS + i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) + i.putExtra( + Settings.EXTRA_CHANNEL_ID, + getString(R.string.notification_channel_chat_id) + ) + i.addCategory(Intent.CATEGORY_DEFAULT) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) + i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) + startActivity(i) + } + } } - } }) + ) } override fun goBack() { diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/ContactsSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/ContactsSettingsFragment.kt index 8d154f2cf..6a71024aa 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/ContactsSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/ContactsSettingsFragment.kt @@ -57,25 +57,31 @@ class ContactsSettingsFragment : GenericFragment - if (newValue) { - Compatibility.createShortcutsToContacts(requireContext()) - } else { - Compatibility.removeShortcuts(requireContext()) - if (corePreferences.chatRoomShortcuts) { - Compatibility.createShortcutsToChatRooms(requireContext()) + viewModel.launcherShortcutsEvent.observe( + viewLifecycleOwner, + { + it.consume { newValue -> + if (newValue) { + Compatibility.createShortcutsToContacts(requireContext()) + } else { + Compatibility.removeShortcuts(requireContext()) + if (corePreferences.chatRoomShortcuts) { + Compatibility.createShortcutsToChatRooms(requireContext()) + } } } } - }) + ) - viewModel.askWriteContactsPermissionForPresenceStorageEvent.observe(viewLifecycleOwner, { - it.consume { - Log.i("[Contacts Settings] Asking for WRITE_CONTACTS permission to be able to store presence") - requestPermissions(arrayOf(android.Manifest.permission.WRITE_CONTACTS), 1) + viewModel.askWriteContactsPermissionForPresenceStorageEvent.observe( + viewLifecycleOwner, + { + it.consume { + Log.i("[Contacts Settings] Asking for WRITE_CONTACTS permission to be able to store presence") + requestPermissions(arrayOf(android.Manifest.permission.WRITE_CONTACTS), 1) + } } - }) + ) if (!PermissionHelper.required(requireContext()).hasReadContactsPermission()) { Log.i("[Contacts Settings] Asking for READ_CONTACTS permission") diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/SettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/SettingsFragment.kt index 3b9d71296..c1ede7d17 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/SettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/SettingsFragment.kt @@ -57,25 +57,31 @@ class SettingsFragment : SecureFragment() { view.doOnPreDraw { sharedViewModel.canSlidingPaneBeClosed.value = binding.slidingPane.isSlideable } - sharedViewModel.closeSlidingPaneEvent.observe(viewLifecycleOwner, { - it.consume { - if (!binding.slidingPane.closePane()) { - goBack() - } - } - }) - sharedViewModel.layoutChangedEvent.observe(viewLifecycleOwner, { - it.consume { - sharedViewModel.canSlidingPaneBeClosed.value = binding.slidingPane.isSlideable - if (binding.slidingPane.isSlideable) { - val navHostFragment = childFragmentManager.findFragmentById(R.id.settings_nav_container) as NavHostFragment - if (navHostFragment.navController.currentDestination?.id == R.id.emptySettingsFragment) { - Log.i("[Settings] Foldable device has been folded, closing side pane with empty fragment") - binding.slidingPane.closePane() + sharedViewModel.closeSlidingPaneEvent.observe( + viewLifecycleOwner, + { + it.consume { + if (!binding.slidingPane.closePane()) { + goBack() } } } - }) + ) + sharedViewModel.layoutChangedEvent.observe( + viewLifecycleOwner, + { + it.consume { + sharedViewModel.canSlidingPaneBeClosed.value = binding.slidingPane.isSlideable + if (binding.slidingPane.isSlideable) { + val navHostFragment = childFragmentManager.findFragmentById(R.id.settings_nav_container) as NavHostFragment + if (navHostFragment.navController.currentDestination?.id == R.id.emptySettingsFragment) { + Log.i("[Settings] Foldable device has been folded, closing side pane with empty fragment") + binding.slidingPane.closePane() + } + } + } + } + ) binding.slidingPane.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED /* End of shared view model & sliding pane related */ @@ -85,10 +91,13 @@ class SettingsFragment : SecureFragment() { binding.setBackClickListener { goBack() } - sharedViewModel.accountRemoved.observe(viewLifecycleOwner, { - Log.i("[Settings] Account removed, update accounts list") - viewModel.updateAccountsList() - }) + sharedViewModel.accountRemoved.observe( + viewLifecycleOwner, + { + Log.i("[Settings] Account removed, update accounts list") + viewModel.updateAccountsList() + } + ) val identity = arguments?.getString("Identity") if (identity != null) { diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/VideoSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/VideoSettingsFragment.kt index c79f49483..7dee3d217 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/VideoSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/VideoSettingsFragment.kt @@ -93,15 +93,18 @@ class VideoSettingsFragment : GenericFragment() { binding.setVariable(BR.text_subtitle, "") binding.setVariable(BR.defaultValue, payload.recvFmtp) binding.setVariable(BR.checked, payload.enabled()) - binding.setVariable(BR.listener, object : SettingListenerStub() { - override fun onBoolValueChanged(newValue: Boolean) { - payload.enable(newValue) - } + binding.setVariable( + BR.listener, + object : SettingListenerStub() { + override fun onBoolValueChanged(newValue: Boolean) { + payload.enable(newValue) + } - override fun onTextValueChanged(newValue: String) { - payload.recvFmtp = newValue + override fun onTextValueChanged(newValue: String) { + payload.recvFmtp = newValue + } } - }) + ) binding.lifecycleOwner = this list.add(binding) } diff --git a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/CallSettingsViewModel.kt b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/CallSettingsViewModel.kt index a8b973910..cc027a672 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/CallSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/CallSettingsViewModel.kt @@ -64,8 +64,8 @@ class CallSettingsViewModel : GenericSettingsViewModel() { val fullScreenListener = object : SettingListenerStub() { override fun onBoolValueChanged(newValue: Boolean) { - prefs.fullScreenCallUI = newValue - } + prefs.fullScreenCallUI = newValue + } } val fullScreen = MutableLiveData() diff --git a/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt b/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt index 687c6c948..d0668e343 100644 --- a/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt @@ -67,10 +67,13 @@ class SideMenuFragment : GenericFragment() { ViewModelProvider(this).get(SharedMainViewModel::class.java) } - sharedViewModel.accountRemoved.observe(viewLifecycleOwner, { - Log.i("[Side Menu] Account removed, update accounts list") - viewModel.updateAccountsList() - }) + sharedViewModel.accountRemoved.observe( + viewLifecycleOwner, + { + Log.i("[Side Menu] Account removed, update accounts list") + viewModel.updateAccountsList() + } + ) viewModel.accountsSettingsListener = object : SettingListenerStub() { override fun onAccountClicked(identity: String) { diff --git a/app/src/main/java/org/linphone/activities/main/viewmodels/CallOverlayViewModel.kt b/app/src/main/java/org/linphone/activities/main/viewmodels/CallOverlayViewModel.kt index dbe6d05a3..88807c6fa 100644 --- a/app/src/main/java/org/linphone/activities/main/viewmodels/CallOverlayViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/viewmodels/CallOverlayViewModel.kt @@ -49,8 +49,8 @@ class CallOverlayViewModel : ViewModel() { init { displayCallOverlay.value = corePreferences.showCallOverlay && - !corePreferences.systemWideCallOverlay && - coreContext.core.callsNb > 0 + !corePreferences.systemWideCallOverlay && + coreContext.core.callsNb > 0 coreContext.core.addListener(listener) } diff --git a/app/src/main/java/org/linphone/contact/ContactsManager.kt b/app/src/main/java/org/linphone/contact/ContactsManager.kt index 715564d3e..e5c28ef6e 100644 --- a/app/src/main/java/org/linphone/contact/ContactsManager.kt +++ b/app/src/main/java/org/linphone/contact/ContactsManager.kt @@ -315,7 +315,8 @@ class ContactsManager(private val context: Context) { val accounts = accountManager.getAccountsByType(context.getString(R.string.sync_account_type)) if (accounts.isEmpty()) { val newAccount = Account( - context.getString(R.string.sync_account_name), context.getString( + context.getString(R.string.sync_account_name), + context.getString( R.string.sync_account_type ) ) diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index de732fb68..4aa06320b 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -178,10 +178,13 @@ class CoreContext(val context: Context, coreConfig: Config) { } else { Log.i("[Context] Scheduling auto answering in $autoAnswerDelay milliseconds") val mainThreadHandler = Handler(Looper.getMainLooper()) - mainThreadHandler.postDelayed({ - Log.w("[Context] Auto answering call") - answerCall(call) - }, autoAnswerDelay.toLong()) + mainThreadHandler.postDelayed( + { + Log.w("[Context] Auto answering call") + answerCall(call) + }, + autoAnswerDelay.toLong() + ) } } } else if (state == Call.State.OutgoingInit) { @@ -214,7 +217,8 @@ class CoreContext(val context: Context, coreConfig: Config) { // Do not turn speaker on when video is enabled if headset or bluetooth is used if (!AudioRouteUtils.isHeadsetAudioRouteAvailable() && !AudioRouteUtils.isBluetoothAudioRouteCurrentlyUsed( call - )) { + ) + ) { Log.i("[Context] Video enabled and no wired headset not bluetooth in use, routing audio to speaker") AudioRouteUtils.routeAudioToSpeaker(call) } @@ -237,8 +241,9 @@ class CoreContext(val context: Context, coreConfig: Config) { } callErrorMessageResourceId.value = Event(message) } else if (state == Call.State.End && - call.dir == Call.Dir.Outgoing && - call.errorInfo.reason == Reason.Declined) { + call.dir == Call.Dir.Outgoing && + call.errorInfo.reason == Reason.Declined + ) { Log.i("[Context] Call has been declined") val message = context.getString(R.string.call_error_declined) callErrorMessageResourceId.value = Event(message) @@ -597,7 +602,8 @@ class CoreContext(val context: Context, coreConfig: Config) { } MotionEvent.ACTION_UP -> { if (abs(overlayX - params.x) < CorePreferences.OVERLAY_CLICK_SENSITIVITY && - abs(overlayY - params.y) < CorePreferences.OVERLAY_CLICK_SENSITIVITY) { + abs(overlayY - params.y) < CorePreferences.OVERLAY_CLICK_SENSITIVITY + ) { view.performClick() } overlayX = params.x.toFloat() diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 91a7b06fc..4164dcd7d 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -151,8 +151,9 @@ class NotificationsManager(private val context: Context) { } if (message.contents.find { content -> - content.isFile or content.isFileTransfer or content.isText - } == null) { + content.isFile or content.isFileTransfer or content.isText + } == null + ) { Log.w("[Notifications Manager] Received message with neither text or attachment, do not notify") return } @@ -291,7 +292,7 @@ class NotificationsManager(private val context: Context) { currentForegroundServiceNotificationId = notificationId service?.startForeground(currentForegroundServiceNotificationId, callNotification) } - } + } private fun stopForegroundNotification() { if (service != null) { @@ -462,7 +463,8 @@ class NotificationsManager(private val context: Context) { .createPendingIntent() val builder = NotificationCompat.Builder( - context, context.getString(R.string.notification_channel_missed_call_id)) + context, context.getString(R.string.notification_channel_missed_call_id) + ) .setContentTitle(context.getString(R.string.missed_call_notification_title)) .setContentText(body) .setSmallIcon(R.drawable.topbar_missed_call_notification) @@ -546,7 +548,8 @@ class NotificationsManager(private val context: Context) { val pendingIntent = PendingIntent.getActivity(context, 0, callNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) val builder = NotificationCompat.Builder( - context, channelToUse) + context, channelToUse + ) .setContentTitle(contact?.fullName ?: displayName) .setContentText(context.getString(stringResourceId)) .setSmallIcon(iconResourceId) diff --git a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt index 8ab500bf1..e2c313a4c 100644 --- a/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt +++ b/app/src/main/java/org/linphone/utils/AudioRouteUtils.kt @@ -106,7 +106,8 @@ class AudioRouteUtils { fun isBluetoothAudioRouteAvailable(): Boolean { for (audioDevice in coreContext.core.audioDevices) { if (audioDevice.type == AudioDevice.Type.Bluetooth && - audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) { + audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay) + ) { Log.i("[Audio Route Helper] Found bluetooth audio device [${audioDevice.deviceName}]") return true } @@ -117,7 +118,8 @@ class AudioRouteUtils { fun isHeadsetAudioRouteAvailable(): Boolean { for (audioDevice in coreContext.core.audioDevices) { if ((audioDevice.type == AudioDevice.Type.Headset || audioDevice.type == AudioDevice.Type.Headphones) && - audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) { + audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay) + ) { Log.i("[Audio Route Helper] Found headset/headphones audio device [${audioDevice.deviceName}]") return true } diff --git a/app/src/main/java/org/linphone/utils/FileUtils.kt b/app/src/main/java/org/linphone/utils/FileUtils.kt index dbdfafe68..96a7ed511 100644 --- a/app/src/main/java/org/linphone/utils/FileUtils.kt +++ b/app/src/main/java/org/linphone/utils/FileUtils.kt @@ -265,9 +265,9 @@ class FileUtils { context.contentResolver.openInputStream(uri) Log.i( "[File Utils] Trying to copy file from " + - uri.toString() + - " to local file " + - localFile.absolutePath + uri.toString() + + " to local file " + + localFile.absolutePath ) coroutineScope { val deferred = async { copyToFile(remoteFile, localFile) } @@ -417,7 +417,8 @@ class FileUtils { } catch (e: Exception) { Log.e( "[Chat Message] Couldn't get URI for file $file using file provider ${context.getString( - R.string.file_provider)}" + R.string.file_provider + )}" ) Uri.parse(path) } diff --git a/app/src/main/java/org/linphone/utils/LinphoneUtils.kt b/app/src/main/java/org/linphone/utils/LinphoneUtils.kt index a7d9bd209..ea528705a 100644 --- a/app/src/main/java/org/linphone/utils/LinphoneUtils.kt +++ b/app/src/main/java/org/linphone/utils/LinphoneUtils.kt @@ -67,8 +67,8 @@ class LinphoneUtils { fun isLimeAvailable(): Boolean { val core = coreContext.core return core.limeX3DhAvailable() && core.limeX3DhEnabled() && - core.limeX3DhServerUrl != null && - core.defaultAccount?.params?.conferenceFactoryUri != null + core.limeX3DhServerUrl != null && + core.defaultAccount?.params?.conferenceFactoryUri != null } fun isGroupChatAvailable(): Boolean { @@ -143,10 +143,14 @@ class LinphoneUtils { } fun isCallLogMissed(callLog: CallLog): Boolean { - return (callLog.dir == Call.Dir.Incoming && - (callLog.status == Call.Status.Missed || - callLog.status == Call.Status.Aborted || - callLog.status == Call.Status.EarlyAborted)) + return ( + callLog.dir == Call.Dir.Incoming && + ( + callLog.status == Call.Status.Missed || + callLog.status == Call.Status.Aborted || + callLog.status == Call.Status.EarlyAborted + ) + ) } fun getChatRoomId(localAddress: String, remoteAddress: String): String { diff --git a/app/src/main/java/org/linphone/utils/TimestampUtils.kt b/app/src/main/java/org/linphone/utils/TimestampUtils.kt index 359a360af..20e269448 100644 --- a/app/src/main/java/org/linphone/utils/TimestampUtils.kt +++ b/app/src/main/java/org/linphone/utils/TimestampUtils.kt @@ -93,8 +93,8 @@ class TimestampUtils { cal2: Calendar ): Boolean { return cal1[Calendar.ERA] == cal2[Calendar.ERA] && - cal1[Calendar.YEAR] == cal2[Calendar.YEAR] && - cal1[Calendar.DAY_OF_YEAR] == cal2[Calendar.DAY_OF_YEAR] + cal1[Calendar.YEAR] == cal2[Calendar.YEAR] && + cal1[Calendar.DAY_OF_YEAR] == cal2[Calendar.DAY_OF_YEAR] } private fun isSameYear( @@ -102,7 +102,7 @@ class TimestampUtils { cal2: Calendar ): Boolean { return cal1[Calendar.ERA] == cal2[Calendar.ERA] && - cal1[Calendar.YEAR] == cal2[Calendar.YEAR] + cal1[Calendar.YEAR] == cal2[Calendar.YEAR] } } } diff --git a/app/src/main/java/org/linphone/views/VoiceRecordProgressBar.kt b/app/src/main/java/org/linphone/views/VoiceRecordProgressBar.kt index 099c4461a..3d918af4c 100644 --- a/app/src/main/java/org/linphone/views/VoiceRecordProgressBar.kt +++ b/app/src/main/java/org/linphone/views/VoiceRecordProgressBar.kt @@ -63,7 +63,8 @@ class VoiceRecordProgressBar : View { context.theme.obtainStyledAttributes( attrs, R.styleable.VoiceRecordProgressBar, - 0, 0).apply { + 0, 0 + ).apply { try { val drawable = getDrawable(R.styleable.VoiceRecordProgressBar_progressDrawable)