From a05caf6f0e2a0060fd7c0f4ad4ce9e844ce83a7c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sat, 29 Feb 2020 09:49:21 +0100 Subject: [PATCH] Update the 2 notification settings screens by moving some pref to the root notification screen --- .idea/dictionaries/bmarty.xml | 1 + ...sAdvancedNotificationPreferenceFragment.kt | 77 ----------------- ...rSettingsNotificationPreferenceFragment.kt | 85 +++++++++++++++++++ vector/src/main/res/values/strings_riotX.xml | 2 + ...ings_notification_advanced_preferences.xml | 33 ------- .../res/xml/vector_settings_notifications.xml | 34 +++++++- 6 files changed, 121 insertions(+), 111 deletions(-) diff --git a/.idea/dictionaries/bmarty.xml b/.idea/dictionaries/bmarty.xml index f351ec8bfd..7e9a9e1b03 100644 --- a/.idea/dictionaries/bmarty.xml +++ b/.idea/dictionaries/bmarty.xml @@ -19,6 +19,7 @@ msisdn pbkdf pkcs + riotx signin signout signup diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt index 5fa822ea92..b7c1a0490b 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -15,11 +15,6 @@ */ package im.vector.riotx.features.settings -import android.app.Activity -import android.content.Intent -import android.media.RingtoneManager -import android.net.Uri -import android.os.Parcelable import androidx.preference.Preference import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.pushrules.rest.PushRule @@ -28,7 +23,6 @@ import im.vector.riotx.R import im.vector.riotx.core.preference.PushRulePreference import im.vector.riotx.core.preference.VectorPreference import im.vector.riotx.core.utils.toast -import im.vector.riotx.features.notifications.NotificationUtils import javax.inject.Inject class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor( @@ -40,56 +34,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor( override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences override fun bindPref() { - val callNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY)!! - if (NotificationUtils.supportNotificationChannels()) { - callNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { - NotificationUtils.openSystemSettingsForCallCategory(this) - false - } - } else { - callNotificationsSystemOptions.isVisible = false - } - - val noisyNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY)!! - if (NotificationUtils.supportNotificationChannels()) { - noisyNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { - NotificationUtils.openSystemSettingsForNoisyCategory(this) - false - } - } else { - noisyNotificationsSystemOptions.isVisible = false - } - - val silentNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY)!! - if (NotificationUtils.supportNotificationChannels()) { - silentNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { - NotificationUtils.openSystemSettingsForSilentCategory(this) - false - } - } else { - silentNotificationsSystemOptions.isVisible = false - } - - // Ringtone - val ringtonePreference = findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!! - - if (NotificationUtils.supportNotificationChannels()) { - ringtonePreference.isVisible = false - } else { - ringtonePreference.summary = vectorPreferences.getNotificationRingToneName() - ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { - val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) - - if (null != vectorPreferences.getNotificationRingTone()) { - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, vectorPreferences.getNotificationRingTone()) - } - - startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE) - false - } - } - for (preferenceKey in prefKeyToPushRuleId.keys) { val preference = findPreference(preferenceKey) if (preference is PushRulePreference) { @@ -142,32 +86,11 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor( listView?.adapter?.notifyDataSetChanged() } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (resultCode == Activity.RESULT_OK) { - when (requestCode) { - REQUEST_NOTIFICATION_RINGTONE -> { - vectorPreferences.setNotificationRingTone(data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) - - // test if the selected ring tone can be played - val notificationRingToneName = vectorPreferences.getNotificationRingToneName() - if (null != notificationRingToneName) { - vectorPreferences.setNotificationRingTone(vectorPreferences.getNotificationRingTone()) - findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!! - .summary = notificationRingToneName - } - } - } - } - } - /* ========================================================================================== * Companion * ========================================================================================== */ companion object { - private const val REQUEST_NOTIFICATION_RINGTONE = 888 - // preference name <-> rule Id private val prefKeyToPushRuleId = mapOf( "SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to PushRule.RULE_ID_CONTAIN_DISPLAY_NAME, diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt index 4e4e9ddb7a..0ee42b7653 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationPreferenceFragment.kt @@ -16,6 +16,11 @@ package im.vector.riotx.features.settings +import android.app.Activity +import android.content.Intent +import android.media.RingtoneManager +import android.net.Uri +import android.os.Parcelable import android.widget.Toast import androidx.preference.Preference import androidx.preference.SwitchPreference @@ -24,8 +29,10 @@ import im.vector.matrix.android.api.pushrules.RuleIds import im.vector.matrix.android.api.pushrules.RuleKind import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder +import im.vector.riotx.core.preference.VectorPreference import im.vector.riotx.core.preference.VectorSwitchPreference import im.vector.riotx.core.pushers.PushersManager +import im.vector.riotx.features.notifications.NotificationUtils import im.vector.riotx.push.fcm.FcmHelper import javax.inject.Inject @@ -54,8 +61,82 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( val areNotifEnabledAtAccountLevel = !mRuleMaster.enabled (pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevel } + + handleSystemPreference() } + private fun handleSystemPreference() { + val callNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY)!! + if (NotificationUtils.supportNotificationChannels()) { + callNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { + NotificationUtils.openSystemSettingsForCallCategory(this) + false + } + } else { + callNotificationsSystemOptions.isVisible = false + } + + val noisyNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY)!! + if (NotificationUtils.supportNotificationChannels()) { + noisyNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { + NotificationUtils.openSystemSettingsForNoisyCategory(this) + false + } + } else { + noisyNotificationsSystemOptions.isVisible = false + } + + val silentNotificationsSystemOptions = findPreference(VectorPreferences.SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY)!! + if (NotificationUtils.supportNotificationChannels()) { + silentNotificationsSystemOptions.onPreferenceClickListener = Preference.OnPreferenceClickListener { + NotificationUtils.openSystemSettingsForSilentCategory(this) + false + } + } else { + silentNotificationsSystemOptions.isVisible = false + } + + // Ringtone + val ringtonePreference = findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!! + + if (NotificationUtils.supportNotificationChannels()) { + ringtonePreference.isVisible = false + } else { + ringtonePreference.summary = vectorPreferences.getNotificationRingToneName() + ringtonePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { + val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) + + if (null != vectorPreferences.getNotificationRingTone()) { + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, vectorPreferences.getNotificationRingTone()) + } + + startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE) + false + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + when (requestCode) { + REQUEST_NOTIFICATION_RINGTONE -> { + vectorPreferences.setNotificationRingTone(data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) + + // test if the selected ring tone can be played + val notificationRingToneName = vectorPreferences.getNotificationRingToneName() + if (null != notificationRingToneName) { + vectorPreferences.setNotificationRingTone(vectorPreferences.getNotificationRingTone()) + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!! + .summary = notificationRingToneName + } + } + } + } + } + + override fun onResume() { super.onResume() activeSessionHolder.getSafeActiveSession()?.refreshPushers() @@ -129,4 +210,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( }) } } + + companion object { + private const val REQUEST_NOTIFICATION_RINGTONE = 888 + } } diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index d627ac0dd7..620b2d866b 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -17,6 +17,8 @@ Encrypted messages in group chats When rooms are upgraded Troubleshoot + Set notification importance by event + diff --git a/vector/src/main/res/xml/vector_settings_notification_advanced_preferences.xml b/vector/src/main/res/xml/vector_settings_notification_advanced_preferences.xml index a58a2d8f19..6e0fb71671 100644 --- a/vector/src/main/res/xml/vector_settings_notification_advanced_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_notification_advanced_preferences.xml @@ -64,37 +64,4 @@ - - - - - - - - - - - - - - diff --git a/vector/src/main/res/xml/vector_settings_notifications.xml b/vector/src/main/res/xml/vector_settings_notifications.xml index fb660ba8b9..5ecf693b44 100644 --- a/vector/src/main/res/xml/vector_settings_notifications.xml +++ b/vector/src/main/res/xml/vector_settings_notifications.xml @@ -24,12 +24,44 @@ android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY" android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY" android:persistent="false" - android:summary="@string/settings_notification_advanced_summary" + android:summary="@string/settings_notification_advanced_summary_riotx" android:title="@string/settings_notification_advanced" app:fragment="im.vector.riotx.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment" /> + + + + + + + + + + + + + +