From 51510cccd9844c52cfb27bed1bfe13e56a24c156 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 6 Dec 2022 19:27:06 +0600 Subject: [PATCH] 5742-r-Add_no_snooze_option issue: https://gitlab.e.foundation/e/backlog/-/issues/5742 - Add support to disable event notification snoozing - Handle corner case for notifications which are created BEFORE setting snooze=disable, but fires up AFTER the setting update. For these cases, snooze with default snooze value (5 mins) --- res/values/arrays.xml | 1 + res/values/strings.xml | 1 + src/com/android/calendar/alerts/AlertReceiver.java | 10 ++++++++++ .../android/calendar/alerts/SnoozeAlarmsService.java | 5 +++++ .../android/calendar/alerts/SnoozeDelayActivity.java | 6 ++++++ src/com/android/calendar/event/EventViewUtils.java | 6 ++++++ .../android/calendar/settings/GeneralPreferences.kt | 8 ++++++++ 7 files changed, 37 insertions(+) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 8307a7e1b..ffc165328 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -154,6 +154,7 @@ + "-1" "5" "10" "15" diff --git a/res/values/strings.xml b/res/values/strings.xml index afac62488..b2c2e583c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -38,6 +38,7 @@ (No title) + None 1 minute diff --git a/src/com/android/calendar/alerts/AlertReceiver.java b/src/com/android/calendar/alerts/AlertReceiver.java index 125709784..271214458 100644 --- a/src/com/android/calendar/alerts/AlertReceiver.java +++ b/src/com/android/calendar/alerts/AlertReceiver.java @@ -48,6 +48,8 @@ import android.text.style.URLSpan; import android.util.Log; import android.widget.Toast; +import androidx.annotation.Nullable; + import com.android.calendar.DynamicTheme; import com.android.calendar.Utils; import com.android.calendar.alerts.AlertService.NotificationWrapper; @@ -185,8 +187,16 @@ public class AlertReceiver extends BroadcastReceiver { return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } + // if default snooze minute < 0, means the snooze option is disable + // in this case return null as intent + @Nullable private static PendingIntent createSnoozeIntent(Context context, long eventId, long startMillis, long endMillis, int notificationId) { + + if (Utils.getDefaultSnoozeDelayMs(context) < 0L) { + return null; + } + Intent intent = new Intent(); intent.putExtra(AlertUtils.EVENT_ID_KEY, eventId); intent.putExtra(AlertUtils.EVENT_START_KEY, startMillis); diff --git a/src/com/android/calendar/alerts/SnoozeAlarmsService.java b/src/com/android/calendar/alerts/SnoozeAlarmsService.java index f0a7ff556..70351e933 100644 --- a/src/com/android/calendar/alerts/SnoozeAlarmsService.java +++ b/src/com/android/calendar/alerts/SnoozeAlarmsService.java @@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat; import android.util.Log; import com.android.calendar.Utils; +import com.android.calendar.settings.GeneralPreferences; /** * Service for asynchronously marking a fired alarm as dismissed and scheduling @@ -92,6 +93,10 @@ public class SnoozeAlarmsService extends IntentService { resolver.update(uri, dismissValues, selection, null); // Add a new alarm + if (snoozeDelay < 0) { + snoozeDelay = GeneralPreferences.SNOOZE_DELAY_DEFAULT_TIME * 60L * 1000L; + } + long alarmTime = System.currentTimeMillis() + snoozeDelay; ContentValues values = AlertUtils.makeContentValues(eventId, eventStart, eventEnd, alarmTime, 0); diff --git a/src/com/android/calendar/alerts/SnoozeDelayActivity.java b/src/com/android/calendar/alerts/SnoozeDelayActivity.java index 41e9d2c32..dd228c4e7 100644 --- a/src/com/android/calendar/alerts/SnoozeDelayActivity.java +++ b/src/com/android/calendar/alerts/SnoozeDelayActivity.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.widget.TimePicker; import com.android.calendar.Utils; +import com.android.calendar.settings.GeneralPreferences; import ws.xsoh.etar.R; @@ -55,6 +56,11 @@ public class SnoozeDelayActivity extends Activity implements if (id == DIALOG_DELAY) { TimePickerDialog tpd = (TimePickerDialog) d; int delayMinutes = (int) (Utils.getDefaultSnoozeDelayMs(this) / (60L * 1000L)); + + if (delayMinutes < 0) { + delayMinutes = GeneralPreferences.SNOOZE_DELAY_DEFAULT_TIME; + } + int hours = delayMinutes / 60; int minutes = delayMinutes % 60; diff --git a/src/com/android/calendar/event/EventViewUtils.java b/src/com/android/calendar/event/EventViewUtils.java index 8a63f3b0a..8d580593b 100644 --- a/src/com/android/calendar/event/EventViewUtils.java +++ b/src/com/android/calendar/event/EventViewUtils.java @@ -45,8 +45,14 @@ public class EventViewUtils { // if the given minutes is 63, then this returns the string "63 minutes". // As another example, if the given minutes is 120, then this returns // "2 hours". + // if minute is < 0, returns `None` public static String constructReminderLabel(Context context, int minutes, boolean abbrev) { Resources resources = context.getResources(); + + if (minutes < 0) { + return resources.getString(R.string.no_snooze_label); + } + int value, resId; if (minutes % 60 != 0) { diff --git a/src/com/android/calendar/settings/GeneralPreferences.kt b/src/com/android/calendar/settings/GeneralPreferences.kt index e7090c452..9eb2b75ea 100644 --- a/src/com/android/calendar/settings/GeneralPreferences.kt +++ b/src/com/android/calendar/settings/GeneralPreferences.kt @@ -62,6 +62,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), private lateinit var homeTzPref: Preference private lateinit var popupPref: SwitchPreference private lateinit var snoozeDelayPref: ListPreference + private lateinit var useDefaultCustomSnoozeDelayPref: Preference private lateinit var defaultReminderPref: ListPreference private lateinit var copyDbPref: Preference private lateinit var skipRemindersPref: ListPreference @@ -105,6 +106,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), homeTzPref = preferenceScreen.findPreference(KEY_HOME_TZ)!! popupPref = preferenceScreen.findPreference(KEY_ALERTS_POPUP)!! snoozeDelayPref = preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY)!! + useDefaultCustomSnoozeDelayPref = preferenceScreen.findPreference(KEY_USE_CUSTOM_SNOOZE_DELAY)!! defaultReminderPref = preferenceScreen.findPreference(KEY_DEFAULT_REMINDER)!! copyDbPref = preferenceScreen.findPreference(KEY_OTHER_COPY_DB)!! skipRemindersPref = preferenceScreen.findPreference(KEY_OTHER_REMINDERS_RESPONDED)!! @@ -136,6 +138,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), } buildSnoozeDelayEntries() + handleUseCustomSnoozeDelayVisibility() defaultEventDurationPref.summary = defaultEventDurationPref.entry themePref.summary = themePref.entry weekStartPref.summary = weekStartPref.entry @@ -191,6 +194,10 @@ class GeneralPreferences : PreferenceFragmentCompat(), } } + private fun handleUseCustomSnoozeDelayVisibility() { + useDefaultCustomSnoozeDelayPref.isEnabled = Integer.parseInt(snoozeDelayPref.value) >= 0 + } + private fun showColorPickerDialog() { val colorPickerDialog = ColorPickerDialogX() val selectedColorName = Utils.getSharedPreference(activity, KEY_COLOR_PREF, "teal") @@ -353,6 +360,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), snoozeDelayPref -> { snoozeDelayPref.value = newValue as String snoozeDelayPref.summary = snoozeDelayPref.entry + handleUseCustomSnoozeDelayVisibility() } defaultStartPref -> { val i = defaultStartPref.findIndexOfValue(newValue as String) -- GitLab