Link priority setting to message channel setting on Oreo+

When using notification channels, us setting priority actually has
no effect. So instead of having a non-functional setting, we've
routed the notification priority setting to go to the system
notification channel settings page for our Messages channel.
This commit is contained in:
Greyson Parrelli 2018-08-15 12:11:10 -07:00
parent 10a790df88
commit a6473bc922
6 changed files with 47 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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