From 8e2fc8b6cd50849b1aa5f3df8b85ee6a03ddda1a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 26 Apr 2024 15:23:31 +0200 Subject: [PATCH] Improved account profile if push notifications aren't available on the device (or not configured in app) --- .../main/settings/viewmodel/AccountProfileViewModel.kt | 9 +++++++-- app/src/main/res/layout/account_profile_fragment.xml | 6 ++++-- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt index ce8f93438..736eceda4 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt @@ -50,6 +50,8 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { val selectedDialPlan = MutableLiveData() + val pushNotificationsAvailable = MutableLiveData() + val pushNotificationsEnabled = MutableLiveData() val registerEnabled = MutableLiveData() @@ -78,7 +80,8 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { expandDetails.value = true expandDevices.value = false // TODO: set to true when feature will be available - coreContext.postOnCoreThread { + coreContext.postOnCoreThread { core -> + pushNotificationsAvailable.postValue(core.isPushNotificationAvailable) hideAccountSettings.postValue(corePreferences.hideAccountSettings) dialPlansLabelList.add("") // To allow removing selected dial plan @@ -113,7 +116,9 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { accountModel.postValue(AccountModel(account)) isCurrentlySelectedModeSecure.postValue(account.isEndToEndEncryptionMandatory()) registerEnabled.postValue(account.params.isRegisterEnabled) - pushNotificationsEnabled.postValue(account.params.pushNotificationAllowed) + pushNotificationsEnabled.postValue( + core.isPushNotificationAvailable && account.params.pushNotificationAllowed + ) sipAddress.postValue(account.params.identityAddress?.asStringUriOnly()) displayName.postValue(account.params.identityAddress?.displayName) diff --git a/app/src/main/res/layout/account_profile_fragment.xml b/app/src/main/res/layout/account_profile_fragment.xml index 453cf6104..813455e87 100644 --- a/app/src/main/res/layout/account_profile_fragment.xml +++ b/app/src/main/res/layout/account_profile_fragment.xml @@ -321,6 +321,7 @@ android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" + android:enabled="@{viewModel.pushNotificationsAvailable}" android:checked="@={viewModel.pushNotificationsEnabled}" app:layout_constraintEnd_toEndOf="@id/details_background" app:layout_constraintTop_toBottomOf="@id/prefix"/> @@ -330,12 +331,13 @@ android:id="@+id/push_notifications_title" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginTop="16dp" android:layout_marginStart="16dp" android:layout_marginEnd="10dp" - android:text="@string/account_settings_push_notification_title" + android:text="@{viewModel.pushNotificationsAvailable ? @string/account_settings_push_notification_title : @string/account_settings_push_notification_not_available_title, default=@string/account_settings_push_notification_title}" android:maxLines="2" android:ellipsize="end" - app:layout_constraintTop_toTopOf="@id/push_notifications_switch" + app:layout_constraintTop_toBottomOf="@id/prefix" app:layout_constraintBottom_toBottomOf="@id/push_notifications_switch" app:layout_constraintStart_toStartOf="@id/details_background" app:layout_constraintEnd_toStartOf="@id/push_notifications_switch"/> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index a4554ec52..ba38de826 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -297,6 +297,7 @@ Paramètres de compte Autoriser les notifications poussées + Les notifications poussées ne sont pas disponibles ! URL du serveur mandataire Serveur mandataire sortant URL du serveur STUN diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c19e8042f..8c2049bfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -332,6 +332,7 @@ Account settings Allow push notifications + Push notifications aren\'t available! SIP proxy server URL Outbound proxy STUN server URL