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