mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Update the 2 notification settings screens by moving some pref to the root notification screen
This commit is contained in:
parent
3462df405c
commit
a05caf6f0e
@ -19,6 +19,7 @@
|
|||||||
<w>msisdn</w>
|
<w>msisdn</w>
|
||||||
<w>pbkdf</w>
|
<w>pbkdf</w>
|
||||||
<w>pkcs</w>
|
<w>pkcs</w>
|
||||||
|
<w>riotx</w>
|
||||||
<w>signin</w>
|
<w>signin</w>
|
||||||
<w>signout</w>
|
<w>signout</w>
|
||||||
<w>signup</w>
|
<w>signup</w>
|
||||||
|
@ -15,11 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package im.vector.riotx.features.settings
|
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 androidx.preference.Preference
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
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.PushRulePreference
|
||||||
import im.vector.riotx.core.preference.VectorPreference
|
import im.vector.riotx.core.preference.VectorPreference
|
||||||
import im.vector.riotx.core.utils.toast
|
import im.vector.riotx.core.utils.toast
|
||||||
import im.vector.riotx.features.notifications.NotificationUtils
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor(
|
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor(
|
||||||
@ -40,56 +34,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor(
|
|||||||
override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences
|
override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences
|
||||||
|
|
||||||
override fun bindPref() {
|
override fun bindPref() {
|
||||||
val callNotificationsSystemOptions = findPreference<VectorPreference>(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<VectorPreference>(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<VectorPreference>(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<VectorPreference>(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) {
|
for (preferenceKey in prefKeyToPushRuleId.keys) {
|
||||||
val preference = findPreference<VectorPreference>(preferenceKey)
|
val preference = findPreference<VectorPreference>(preferenceKey)
|
||||||
if (preference is PushRulePreference) {
|
if (preference is PushRulePreference) {
|
||||||
@ -142,32 +86,11 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor(
|
|||||||
listView?.adapter?.notifyDataSetChanged()
|
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<Parcelable>(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<VectorPreference>(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!!
|
|
||||||
.summary = notificationRingToneName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Companion
|
* Companion
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val REQUEST_NOTIFICATION_RINGTONE = 888
|
|
||||||
|
|
||||||
// preference name <-> rule Id
|
// preference name <-> rule Id
|
||||||
private val prefKeyToPushRuleId = mapOf(
|
private val prefKeyToPushRuleId = mapOf(
|
||||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to PushRule.RULE_ID_CONTAIN_DISPLAY_NAME,
|
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to PushRule.RULE_ID_CONTAIN_DISPLAY_NAME,
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package im.vector.riotx.features.settings
|
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 android.widget.Toast
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.SwitchPreference
|
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.matrix.android.api.pushrules.RuleKind
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
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.preference.VectorSwitchPreference
|
||||||
import im.vector.riotx.core.pushers.PushersManager
|
import im.vector.riotx.core.pushers.PushersManager
|
||||||
|
import im.vector.riotx.features.notifications.NotificationUtils
|
||||||
import im.vector.riotx.push.fcm.FcmHelper
|
import im.vector.riotx.push.fcm.FcmHelper
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -54,8 +61,82 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||||||
val areNotifEnabledAtAccountLevel = !mRuleMaster.enabled
|
val areNotifEnabledAtAccountLevel = !mRuleMaster.enabled
|
||||||
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevel
|
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleSystemPreference()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleSystemPreference() {
|
||||||
|
val callNotificationsSystemOptions = findPreference<VectorPreference>(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<VectorPreference>(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<VectorPreference>(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<VectorPreference>(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<Parcelable>(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<VectorPreference>(VectorPreferences.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY)!!
|
||||||
|
.summary = notificationRingToneName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
activeSessionHolder.getSafeActiveSession()?.refreshPushers()
|
activeSessionHolder.getSafeActiveSession()?.refreshPushers()
|
||||||
@ -129,4 +210,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val REQUEST_NOTIFICATION_RINGTONE = 888
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
<string name="settings_messages_in_e2e_group_chat">Encrypted messages in group chats</string>
|
<string name="settings_messages_in_e2e_group_chat">Encrypted messages in group chats</string>
|
||||||
<string name="settings_when_rooms_are_upgraded">When rooms are upgraded</string>
|
<string name="settings_when_rooms_are_upgraded">When rooms are upgraded</string>
|
||||||
<string name="settings_troubleshoot_title">Troubleshoot</string>
|
<string name="settings_troubleshoot_title">Troubleshoot</string>
|
||||||
|
<string name="settings_notification_advanced_summary_riotx">Set notification importance by event</string>
|
||||||
|
|
||||||
<!-- END Strings added by Benoit -->
|
<!-- END Strings added by Benoit -->
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,37 +64,4 @@
|
|||||||
|
|
||||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||||
|
|
||||||
<im.vector.riotx.core.preference.VectorPreferenceCategory
|
|
||||||
android:key="SETTINGS_NOTIFICATION_CONFIGURATION"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/settings_notification_configuration">
|
|
||||||
|
|
||||||
<!-- For API < 26 -->
|
|
||||||
<im.vector.riotx.core.preference.VectorPreference
|
|
||||||
android:dialogTitle="@string/settings_notification_ringtone"
|
|
||||||
android:key="SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/settings_notification_ringtone" />
|
|
||||||
|
|
||||||
<!-- For API >= 26 -->
|
|
||||||
<im.vector.riotx.core.preference.VectorPreference
|
|
||||||
android:key="SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY"
|
|
||||||
android:persistent="false"
|
|
||||||
android:summary="@string/settings_system_preferences_summary"
|
|
||||||
android:title="@string/settings_noisy_notifications_preferences" />
|
|
||||||
|
|
||||||
<im.vector.riotx.core.preference.VectorPreference
|
|
||||||
android:key="SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY"
|
|
||||||
android:persistent="false"
|
|
||||||
android:summary="@string/settings_system_preferences_summary"
|
|
||||||
android:title="@string/settings_silent_notifications_preferences" />
|
|
||||||
|
|
||||||
<im.vector.riotx.core.preference.VectorPreference
|
|
||||||
android:key="SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY"
|
|
||||||
android:persistent="false"
|
|
||||||
android:summary="@string/settings_system_preferences_summary"
|
|
||||||
android:title="@string/settings_call_notifications_preferences" />
|
|
||||||
|
|
||||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
||||||
|
@ -24,12 +24,44 @@
|
|||||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||||
android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY"
|
android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:summary="@string/settings_notification_advanced_summary"
|
android:summary="@string/settings_notification_advanced_summary_riotx"
|
||||||
android:title="@string/settings_notification_advanced"
|
android:title="@string/settings_notification_advanced"
|
||||||
app:fragment="im.vector.riotx.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment" />
|
app:fragment="im.vector.riotx.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment" />
|
||||||
|
|
||||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||||
|
|
||||||
|
<im.vector.riotx.core.preference.VectorPreferenceCategory
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/settings_notification_configuration">
|
||||||
|
|
||||||
|
<!-- For API < 26 -->
|
||||||
|
<im.vector.riotx.core.preference.VectorPreference
|
||||||
|
android:dialogTitle="@string/settings_notification_ringtone"
|
||||||
|
android:key="SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/settings_notification_ringtone" />
|
||||||
|
|
||||||
|
<!-- For API >= 26 -->
|
||||||
|
<im.vector.riotx.core.preference.VectorPreference
|
||||||
|
android:key="SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY"
|
||||||
|
android:persistent="false"
|
||||||
|
android:summary="@string/settings_system_preferences_summary"
|
||||||
|
android:title="@string/settings_noisy_notifications_preferences" />
|
||||||
|
|
||||||
|
<im.vector.riotx.core.preference.VectorPreference
|
||||||
|
android:key="SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY"
|
||||||
|
android:persistent="false"
|
||||||
|
android:summary="@string/settings_system_preferences_summary"
|
||||||
|
android:title="@string/settings_silent_notifications_preferences" />
|
||||||
|
|
||||||
|
<im.vector.riotx.core.preference.VectorPreference
|
||||||
|
android:key="SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY"
|
||||||
|
android:persistent="false"
|
||||||
|
android:summary="@string/settings_system_preferences_summary"
|
||||||
|
android:title="@string/settings_call_notifications_preferences" />
|
||||||
|
|
||||||
|
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||||
|
|
||||||
<im.vector.riotx.core.preference.VectorPreferenceCategory android:title="@string/settings_troubleshoot_title">
|
<im.vector.riotx.core.preference.VectorPreferenceCategory android:title="@string/settings_troubleshoot_title">
|
||||||
|
|
||||||
<im.vector.riotx.core.preference.VectorPreference
|
<im.vector.riotx.core.preference.VectorPreference
|
||||||
|
Loading…
Reference in New Issue
Block a user