kopia lustrzana https://github.com/ryukoposting/Signal-Android
Force use of system settings to configure notifications on SDK30+.
rodzic
68ba3433a3
commit
06a49b5d5a
|
@ -9,6 +9,7 @@ import android.graphics.PorterDuffColorFilter
|
|||
import android.media.Ringtone
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
|
@ -97,49 +98,61 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
|
|||
}
|
||||
)
|
||||
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__sound),
|
||||
summary = DSLSettingsText.from(getRingtoneSummary(state.messageNotificationsState.sound)),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
launchMessageSoundSelectionIntent()
|
||||
}
|
||||
)
|
||||
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__vibrate),
|
||||
isChecked = state.messageNotificationsState.vibrateEnabled,
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
viewModel.setMessageNotificationVibration(!state.messageNotificationsState.vibrateEnabled)
|
||||
}
|
||||
)
|
||||
|
||||
customPref(
|
||||
LedColorPreference(
|
||||
colorValues = ledColorValues,
|
||||
radioListPreference = RadioListPreference(
|
||||
title = DSLSettingsText.from(R.string.preferences__led_color),
|
||||
listItems = ledColorLabels,
|
||||
selected = ledColorValues.indexOf(state.messageNotificationsState.ledColor),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationLedColor(ledColorValues[it])
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if (!NotificationChannels.supported()) {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__pref_led_blink_title),
|
||||
listItems = ledBlinkLabels,
|
||||
selected = ledBlinkValues.indexOf(state.messageNotificationsState.ledBlink),
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__customize),
|
||||
summary = DSLSettingsText.from(R.string.preferences__change_sound_and_vibration),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationLedBlink(ledBlinkValues[it])
|
||||
onClick = {
|
||||
NotificationChannels.openChannelSettings(requireContext(), NotificationChannels.getMessagesChannel(requireContext()), null)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__sound),
|
||||
summary = DSLSettingsText.from(getRingtoneSummary(state.messageNotificationsState.sound)),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
launchMessageSoundSelectionIntent()
|
||||
}
|
||||
)
|
||||
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__vibrate),
|
||||
isChecked = state.messageNotificationsState.vibrateEnabled,
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
viewModel.setMessageNotificationVibration(!state.messageNotificationsState.vibrateEnabled)
|
||||
}
|
||||
)
|
||||
|
||||
customPref(
|
||||
LedColorPreference(
|
||||
colorValues = ledColorValues,
|
||||
radioListPreference = RadioListPreference(
|
||||
title = DSLSettingsText.from(R.string.preferences__led_color),
|
||||
listItems = ledColorLabels,
|
||||
selected = ledColorValues.indexOf(state.messageNotificationsState.ledColor),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationLedColor(ledColorValues[it])
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if (!NotificationChannels.supported()) {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.preferences__pref_led_blink_title),
|
||||
listItems = ledBlinkLabels,
|
||||
selected = ledBlinkValues.indexOf(state.messageNotificationsState.ledBlink),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationLedBlink(ledBlinkValues[it])
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
switchPref(
|
||||
|
@ -171,24 +184,26 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
|
|||
}
|
||||
)
|
||||
|
||||
if (NotificationChannels.supported()) {
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.preferences_notifications__priority),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
launchNotificationPriorityIntent()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.preferences_notifications__priority),
|
||||
listItems = notificationPriorityLabels,
|
||||
selected = notificationPriorityValues.indexOf(state.messageNotificationsState.priority.toString()),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationPriority(notificationPriorityValues[it].toInt())
|
||||
}
|
||||
)
|
||||
if (Build.VERSION.SDK_INT < 30) {
|
||||
if (NotificationChannels.supported()) {
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.preferences_notifications__priority),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
launchNotificationPriorityIntent()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.preferences_notifications__priority),
|
||||
listItems = notificationPriorityLabels,
|
||||
selected = notificationPriorityValues.indexOf(state.messageNotificationsState.priority.toString()),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onSelected = {
|
||||
viewModel.setMessageNotificationPriority(notificationPriorityValues[it].toInt())
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
dividerPref()
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
|
@ -19,6 +20,7 @@ import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
|||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels
|
||||
import org.thoughtcrime.securesms.util.ConversationUtil
|
||||
import org.thoughtcrime.securesms.util.RingtoneUtil
|
||||
|
||||
private val TAG = Log.tag(CustomNotificationsSettingsFragment::class.java)
|
||||
|
@ -84,30 +86,39 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
|
|||
)
|
||||
}
|
||||
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__notification_sound),
|
||||
summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.messageSound, Settings.System.DEFAULT_NOTIFICATION_URI)),
|
||||
isEnabled = state.controlsEnabled,
|
||||
onClick = { requestSound(state.messageSound, false) }
|
||||
)
|
||||
|
||||
if (NotificationChannels.supported()) {
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__customize),
|
||||
summary = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__change_sound_and_vibration),
|
||||
isEnabled = state.controlsEnabled,
|
||||
isChecked = state.messageVibrateEnabled,
|
||||
onClick = { viewModel.setMessageVibrate(RecipientDatabase.VibrateState.fromBoolean(!state.messageVibrateEnabled)) }
|
||||
onClick = { NotificationChannels.openChannelSettings(requireContext(), state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
|
||||
)
|
||||
} else {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
|
||||
clickPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__notification_sound),
|
||||
summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.messageSound, Settings.System.DEFAULT_NOTIFICATION_URI)),
|
||||
isEnabled = state.controlsEnabled,
|
||||
listItems = vibrateLabels,
|
||||
selected = state.messageVibrateState.id,
|
||||
onSelected = {
|
||||
viewModel.setMessageVibrate(RecipientDatabase.VibrateState.fromId(it))
|
||||
}
|
||||
onClick = { requestSound(state.messageSound, false) }
|
||||
)
|
||||
|
||||
if (NotificationChannels.supported()) {
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
|
||||
isEnabled = state.controlsEnabled,
|
||||
isChecked = state.messageVibrateEnabled,
|
||||
onClick = { viewModel.setMessageVibrate(RecipientDatabase.VibrateState.fromBoolean(!state.messageVibrateEnabled)) }
|
||||
)
|
||||
} else {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
|
||||
isEnabled = state.controlsEnabled,
|
||||
listItems = vibrateLabels,
|
||||
selected = state.messageVibrateState.id,
|
||||
onSelected = {
|
||||
viewModel.setMessageVibrate(RecipientDatabase.VibrateState.fromId(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (state.showCallingOptions) {
|
||||
|
|
|
@ -2,9 +2,11 @@ package org.thoughtcrime.securesms.components.settings.conversation.sounds.custo
|
|||
|
||||
import android.net.Uri
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
||||
data class CustomNotificationsSettingsState(
|
||||
val isInitialLoadComplete: Boolean = false,
|
||||
val recipient: Recipient? = null,
|
||||
val hasCustomNotifications: Boolean = false,
|
||||
val controlsEnabled: Boolean = false,
|
||||
val messageVibrateState: RecipientDatabase.VibrateState = RecipientDatabase.VibrateState.DEFAULT,
|
||||
|
|
|
@ -25,6 +25,7 @@ class CustomNotificationsSettingsViewModel(
|
|||
store.update(Recipient.live(recipientId).liveData) { recipient, state ->
|
||||
val recipientHasCustomNotifications = NotificationChannels.supported() && recipient.notificationChannel != null
|
||||
state.copy(
|
||||
recipient = recipient,
|
||||
hasCustomNotifications = recipientHasCustomNotifications,
|
||||
controlsEnabled = (!NotificationChannels.supported() || recipientHasCustomNotifications) && state.isInitialLoadComplete,
|
||||
messageSound = recipient.messageRingtone,
|
||||
|
|
|
@ -184,7 +184,7 @@ public final class EnableCallNotificationSettingsDialog extends DialogFragment {
|
|||
}
|
||||
|
||||
private void showNotificationChannelSettings() {
|
||||
NotificationChannels.openChannelSettings(requireContext(), NotificationChannels.CALLS);
|
||||
NotificationChannels.openChannelSettings(requireContext(), NotificationChannels.CALLS, null);
|
||||
}
|
||||
|
||||
private void showAppSettings() {
|
||||
|
|
|
@ -233,7 +233,7 @@ public class NotificationChannels {
|
|||
/**
|
||||
* Navigates the user to the system settings for the desired notification channel.
|
||||
*/
|
||||
public static void openChannelSettings(@NonNull Context context, @NonNull String channelId) {
|
||||
public static void openChannelSettings(@NonNull Context context, @NonNull String channelId, @Nullable String conversationId) {
|
||||
if (!supported()) {
|
||||
return;
|
||||
}
|
||||
|
@ -242,6 +242,9 @@ public class NotificationChannels {
|
|||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||
if (conversationId != null && Build.VERSION.SDK_INT >= CONVERSATION_SUPPORT_VERSION) {
|
||||
intent.putExtra(Settings.EXTRA_CONVERSATION_ID, conversationId);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Channel settings activity not found", e);
|
||||
|
|
|
@ -845,6 +845,9 @@
|
|||
<string name="CustomNotificationsDialogFragment__use_custom_notifications">Use custom notifications</string>
|
||||
<string name="CustomNotificationsDialogFragment__notification_sound">Notification sound</string>
|
||||
<string name="CustomNotificationsDialogFragment__vibrate">Vibrate</string>
|
||||
<!-- Button text for customizing notification options -->
|
||||
<string name="CustomNotificationsDialogFragment__customize">Customize</string>
|
||||
<string name="CustomNotificationsDialogFragment__change_sound_and_vibration">Change sound and vibration</string>
|
||||
<string name="CustomNotificationsDialogFragment__call_settings">Call settings</string>
|
||||
<string name="CustomNotificationsDialogFragment__ringtone">Ringtone</string>
|
||||
<string name="CustomNotificationsDialogFragment__enabled">Enabled</string>
|
||||
|
@ -2478,6 +2481,8 @@
|
|||
<string name="preferences__led_color">LED color</string>
|
||||
<string name="preferences__led_color_unknown">Unknown</string>
|
||||
<string name="preferences__pref_led_blink_title">LED blink pattern</string>
|
||||
<string name="preferences__customize">Customize</string>
|
||||
<string name="preferences__change_sound_and_vibration">Change sound and vibration</string>
|
||||
<string name="preferences__sound">Sound</string>
|
||||
<string name="preferences__silent">Silent</string>
|
||||
<string name="preferences__default">Default</string>
|
||||
|
|
Ładowanie…
Reference in New Issue