diff --git a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java index 6b585ac07a..a913661dc2 100644 --- a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java @@ -30,8 +30,11 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu setContentTitle(context.getString(R.string.app_name)); setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0)); setCategory(NotificationCompat.CATEGORY_MESSAGE); - setPriority(TextSecurePreferences.getNotificationPriority(context)); setGroupSummary(true); + + if (!NotificationChannels.supported()) { + setPriority(TextSecurePreferences.getNotificationPriority(context)); + } } public void setMessageCount(int messageCount, int threadCount) { diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java index 31600d8876..0cd8e593b3 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java @@ -26,7 +26,7 @@ public class NotificationChannels { * ignored for API < 26. */ public static void create(@NonNull Context context) { - if (Build.VERSION.SDK_INT < 26) { + if (!supported()) { return; } @@ -47,4 +47,8 @@ public class NotificationChannels { notificationManager.deleteNotificationChannel(APP_UPDATES); } } + + public static boolean supported() { + return Build.VERSION.SDK_INT >= 26; + } } diff --git a/src/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java index 9784cc6ba1..2cd058898e 100644 --- a/src/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java @@ -21,7 +21,6 @@ public class PendingMessageNotificationBuilder extends AbstractNotificationBuild setSmallIcon(R.drawable.icon_notification); setColor(context.getResources().getColor(R.color.textsecure_primary)); - setPriority(TextSecurePreferences.getNotificationPriority(context)); setCategory(NotificationCompat.CATEGORY_MESSAGE); setContentTitle(context.getString(R.string.MessageNotifier_pending_signal_messages)); @@ -31,5 +30,9 @@ public class PendingMessageNotificationBuilder extends AbstractNotificationBuild setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)); setAutoCancel(true); setAlarms(null, RecipientDatabase.VibrateState.DEFAULT); + + if (!NotificationChannels.supported()) { + setPriority(TextSecurePreferences.getNotificationPriority(context)); + } } } diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index d0b39a1c06..5394e13cdd 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -52,8 +52,11 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil setSmallIcon(R.drawable.icon_notification); setColor(context.getResources().getColor(R.color.textsecure_primary)); - setPriority(TextSecurePreferences.getNotificationPriority(context)); setCategory(NotificationCompat.CATEGORY_MESSAGE); + + if (!NotificationChannels.supported()) { + setPriority(TextSecurePreferences.getNotificationPriority(context)); + } } public void setThread(@NonNull Recipient recipient) { diff --git a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index 4d29b6f0cb..ae49264fa1 100644 --- a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -18,6 +18,8 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.components.SwitchPreferenceCompat; import org.thoughtcrime.securesms.notifications.MessageNotifier; +import org.thoughtcrime.securesms.notifications.NotificationChannels; +import org.thoughtcrime.securesms.preferences.widgets.SignalListPreference; import org.thoughtcrime.securesms.preferences.widgets.SignalPreference; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.w3c.dom.Text; @@ -84,7 +86,21 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF)); initializeListSummary((ListPreference) findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF)); initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF)); - initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF)); + + if (NotificationChannels.supported()) { + ((SignalListPreference) this.findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF)).disableDialog(); + + this.findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF) + .setOnPreferenceClickListener(preference -> { + Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); + intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationChannels.MESSAGES); + intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName()); + startActivity(intent); + return true; + }); + } else { + initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF)); + } initializeRingtoneSummary(findPreference(TextSecurePreferences.RINGTONE_PREF)); initializeCallRingtoneSummary(findPreference(TextSecurePreferences.CALL_RINGTONE_PREF)); diff --git a/src/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java b/src/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java index d7dc6d913d..643e70bd2e 100644 --- a/src/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java +++ b/src/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java @@ -16,8 +16,9 @@ import org.thoughtcrime.securesms.util.ViewUtil; public class SignalListPreference extends ListPreference { - private TextView rightSummary; + private TextView rightSummary; private CharSequence summary; + private boolean dialogDisabled; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public SignalListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { @@ -63,4 +64,15 @@ public class SignalListPreference extends ListPreference { this.rightSummary.setText(summary); } } + + public void disableDialog() { + dialogDisabled = true; + } + + @Override + protected void onClick() { + if (!dialogDisabled) { + super.onClick(); + } + } }