Add 'Manage notifications' shortcut

pull/574/head
Alex Baker 7 years ago
parent fc5d02ac93
commit 0e69efee96

@ -5,10 +5,12 @@
*/
package com.todoroo.astrid.reminders;
import android.annotation.TargetApi;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
@ -22,6 +24,7 @@ import org.tasks.activities.TimePickerActivity;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.jobs.JobManager;
import org.tasks.notifications.NotificationManager;
import org.tasks.preferences.ActivityPermissionRequestor;
import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionChecker;
@ -77,10 +80,22 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
initializeTimePreference(getQuietStartPreference(), REQUEST_QUIET_START);
initializeTimePreference(getQuietEndPreference(), REQUEST_QUIET_END);
findPreference(R.string.notification_channel_settings).setOnPreferenceClickListener(this::openNotificationChannelSettings);
requires(device.supportsLocationServices(), R.string.geolocation_reminders);
requires(atLeastOreo(), R.string.notification_channel_settings);
requires(preOreo(), R.string.p_rmd_ringtone, R.string.p_rmd_vibrate, R.string.p_led_notification);
}
@TargetApi(Build.VERSION_CODES.O)
private boolean openNotificationChannelSettings(Preference ignored) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationManager.DEFAULT_NOTIFICATION_CHANNEL);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, ReminderPreferences.this.getPackageName());
startActivity(intent);
return true;
}
private void rescheduleNotificationsOnChange(int... resIds) {
for (int resId : resIds) {
findPreference(getString(resId)).setOnPreferenceChangeListener((preference, newValue) -> {

@ -16,7 +16,7 @@ public class NotificationManager {
private final android.app.NotificationManager notificationManager;
private final Preferences preferences;
public static final String DEFAULT_NOTIFICATION_CHANNEL = "my_channel_01";
public static final String DEFAULT_NOTIFICATION_CHANNEL = "notifications";
@Inject
public NotificationManager(@ForApplication Context context, Preferences preferences) {
@ -28,6 +28,9 @@ public class NotificationManager {
NotificationChannel notificationChannel = new NotificationChannel(DEFAULT_NOTIFICATION_CHANNEL, channelName, android.app.NotificationManager.IMPORTANCE_HIGH);
notificationChannel.enableLights(true);
notificationChannel.enableVibration(true);
notificationChannel.setBypassDnd(true);
notificationChannel.setShowBadge(true);
notificationChannel.setImportance(android.app.NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setLightColor(preferences.getLEDColor());
notificationChannel.setVibrationPattern(preferences.getVibrationPattern());
notificationManager.createNotificationChannel(notificationChannel);

@ -789,4 +789,5 @@ File %1$s contained %2$s.\n\n
<string name="start_of_week">Start of week</string>
<string name="use_locale_default">Use locale default</string>
<string name="use_native_datetime_pickers">Use native date and time pickers</string>
<string name="notification_channel_settings">Manage notifications</string>
</resources>

@ -12,6 +12,10 @@
android:defaultValue="true"
android:key="@string/p_rmd_enabled"
android:title="@string/enabled" />
<Preference
android:dependency="@string/p_rmd_enabled"
android:key="@string/notification_channel_settings"
android:title="@string/notification_channel_settings" />
<RingtonePreference
android:defaultValue="content://settings/system/notification_sound"
android:dependency="@string/p_rmd_enabled"

Loading…
Cancel
Save