Moved push notif account toggle from profile to settings

This commit is contained in:
Sylvain Berfini 2024-05-17 14:57:11 +02:00
parent 01d721d477
commit f8d60c1284
4 changed files with 42 additions and 41 deletions

View file

@ -52,10 +52,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
val selectedDialPlan = MutableLiveData<Int>()
val pushNotificationsAvailable = MutableLiveData<Boolean>()
val pushNotificationsEnabled = MutableLiveData<Boolean>()
val registerEnabled = MutableLiveData<Boolean>()
val showModeSelection = MutableLiveData<Boolean>()
@ -83,7 +79,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
expandDevices.value = false // TODO: set to true when feature will be available
coreContext.postOnCoreThread { core ->
pushNotificationsAvailable.postValue(core.isPushNotificationAvailable)
hideAccountSettings.postValue(corePreferences.hideAccountSettings)
dialPlansLabelList.add("") // To allow removing selected dial plan
@ -118,9 +113,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
accountModel.postValue(AccountModel(account))
isCurrentlySelectedModeSecure.postValue(account.isEndToEndEncryptionMandatory())
registerEnabled.postValue(account.params.isRegisterEnabled)
pushNotificationsEnabled.postValue(
core.isPushNotificationAvailable && account.params.pushNotificationAllowed
)
sipAddress.postValue(account.params.identityAddress?.asStringUriOnly())
displayName.postValue(account.params.identityAddress?.displayName)
@ -217,7 +209,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
if (::account.isInitialized) {
val params = account.params
val copy = params.clone()
copy.pushNotificationAllowed = pushNotificationsEnabled.value == true
val address = params.identityAddress?.clone()
if (address != null) {

View file

@ -39,6 +39,10 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() {
val isAccountInSecureMode = MutableLiveData<Boolean>()
val pushNotificationsAvailable = MutableLiveData<Boolean>()
val pushNotificationsEnabled = MutableLiveData<Boolean>()
val availableTransports = arrayListOf<String>()
val selectedTransport = MutableLiveData<TransportType>()
@ -90,6 +94,11 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() {
val params = account.params
pushNotificationsAvailable.postValue(core.isPushNotificationAvailable)
pushNotificationsEnabled.postValue(
core.isPushNotificationAvailable && params.pushNotificationAllowed
)
val transportType = params.serverAddress?.transport ?: TransportType.Tls
selectedTransport.postValue(transportType)
@ -131,6 +140,7 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() {
if (::account.isInitialized) {
val newParams = account.params.clone()
newParams.pushNotificationAllowed = pushNotificationsEnabled.value == true
val server = sipProxyServer.value.orEmpty()
if (server.isNotEmpty()) {

View file

@ -83,7 +83,7 @@
<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="details_background, sip_address, sip_address_label, display_name, display_name_label, prefix, prefix_caret, prefix_label, prefix_label_tooltip, push_notifications_switch, push_notifications_title"
app:constraint_referenced_ids="details_background, sip_address, sip_address_label, display_name, display_name_label, prefix, prefix_caret, prefix_label, prefix_label_tooltip"
android:visibility="@{viewModel.expandDetails ? View.VISIBLE : View.GONE}" />
<androidx.constraintlayout.widget.Group
@ -191,7 +191,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/details"
app:layout_constraintBottom_toBottomOf="@id/push_notifications_switch"/>
app:layout_constraintBottom_toBottomOf="@id/prefix"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/header_style"
@ -315,34 +315,6 @@
app:layout_constraintBottom_toBottomOf="@id/prefix"
app:layout_constraintEnd_toEndOf="@id/prefix"/>
<com.google.android.material.materialswitch.MaterialSwitch
style="@style/material_switch_style"
android:id="@+id/push_notifications_switch"
android:layout_width="wrap_content"
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"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
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="@{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_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"/>
<ImageView
android:id="@+id/connection_background"
android:layout_width="0dp"

View file

@ -61,18 +61,46 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.materialswitch.MaterialSwitch
style="@style/material_switch_style"
android:id="@+id/push_notifications_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:enabled="@{viewModel.pushNotificationsAvailable}"
android:checked="@={viewModel.pushNotificationsEnabled}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:id="@+id/push_notifications_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="10dp"
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="parent"
app:layout_constraintBottom_toBottomOf="@id/push_notifications_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/push_notifications_switch"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:id="@+id/transport_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/assistant_sip_account_transport_protocol"
android:maxLines="2"
android:ellipsize="end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/push_notifications_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>