Force use of system settings to configure notifications on SDK30+.

fork-5.53.8
Cody Henthorne 2022-05-10 14:47:59 -04:00 zatwierdzone przez Alex Hart
rodzic 68ba3433a3
commit 06a49b5d5a
7 zmienionych plików z 116 dodań i 79 usunięć

Wyświetl plik

@ -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,6 +98,17 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
} }
) )
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,
onClick = {
NotificationChannels.openChannelSettings(requireContext(), NotificationChannels.getMessagesChannel(requireContext()), null)
}
)
} else {
clickPref( clickPref(
title = DSLSettingsText.from(R.string.preferences__sound), title = DSLSettingsText.from(R.string.preferences__sound),
summary = DSLSettingsText.from(getRingtoneSummary(state.messageNotificationsState.sound)), summary = DSLSettingsText.from(getRingtoneSummary(state.messageNotificationsState.sound)),
@ -141,6 +153,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
} }
) )
} }
}
switchPref( switchPref(
title = DSLSettingsText.from(R.string.preferences_notifications__in_chat_sounds), title = DSLSettingsText.from(R.string.preferences_notifications__in_chat_sounds),
@ -171,6 +184,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
} }
) )
if (Build.VERSION.SDK_INT < 30) {
if (NotificationChannels.supported()) { if (NotificationChannels.supported()) {
clickPref( clickPref(
title = DSLSettingsText.from(R.string.preferences_notifications__priority), title = DSLSettingsText.from(R.string.preferences_notifications__priority),
@ -190,6 +204,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
} }
) )
} }
}
dividerPref() dividerPref()

Wyświetl plik

@ -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,6 +86,14 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
) )
} }
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,
onClick = { NotificationChannels.openChannelSettings(requireContext(), state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
)
} else {
clickPref( clickPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__notification_sound), title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__notification_sound),
summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.messageSound, Settings.System.DEFAULT_NOTIFICATION_URI)), summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.messageSound, Settings.System.DEFAULT_NOTIFICATION_URI)),
@ -109,6 +119,7 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
} }
) )
} }
}
if (state.showCallingOptions) { if (state.showCallingOptions) {
dividerPref() dividerPref()

Wyświetl plik

@ -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,

Wyświetl plik

@ -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,

Wyświetl plik

@ -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() {

Wyświetl plik

@ -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);

Wyświetl plik

@ -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>