From 335b3ff33d4e905f8db8339ed76f26d17f073b6c Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 6 Dec 2022 19:27:06 +0600 Subject: [PATCH] 5742-s-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) --- .../com/android/calendar/alerts/AlertReceiver.java | 10 ++++++++++ .../android/calendar/alerts/SnoozeAlarmsService.java | 5 +++++ .../android/calendar/alerts/SnoozeDelayActivity.java | 6 ++++++ .../com/android/calendar/event/EventViewUtils.java | 6 ++++++ .../android/calendar/settings/GeneralPreferences.kt | 8 ++++++++ app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 37 insertions(+) diff --git a/app/src/main/java/com/android/calendar/alerts/AlertReceiver.java b/app/src/main/java/com/android/calendar/alerts/AlertReceiver.java index 29dcd41b7..26006d5a7 100644 --- a/app/src/main/java/com/android/calendar/alerts/AlertReceiver.java +++ b/app/src/main/java/com/android/calendar/alerts/AlertReceiver.java @@ -49,6 +49,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; @@ -188,8 +190,16 @@ public class AlertReceiver extends BroadcastReceiver { return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | Utils.PI_FLAG_IMMUTABLE); } + // 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/app/src/main/java/com/android/calendar/alerts/SnoozeAlarmsService.java b/app/src/main/java/com/android/calendar/alerts/SnoozeAlarmsService.java index 876768760..a72291f95 100644 --- a/app/src/main/java/com/android/calendar/alerts/SnoozeAlarmsService.java +++ b/app/src/main/java/com/android/calendar/alerts/SnoozeAlarmsService.java @@ -33,6 +33,7 @@ import android.util.Log; import androidx.core.content.ContextCompat; import com.android.calendar.Utils; +import com.android.calendar.settings.GeneralPreferences; /** * Service for asynchronously marking a fired alarm as dismissed and scheduling @@ -93,6 +94,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/app/src/main/java/com/android/calendar/alerts/SnoozeDelayActivity.java b/app/src/main/java/com/android/calendar/alerts/SnoozeDelayActivity.java index 41e9d2c32..dd228c4e7 100644 --- a/app/src/main/java/com/android/calendar/alerts/SnoozeDelayActivity.java +++ b/app/src/main/java/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/app/src/main/java/com/android/calendar/event/EventViewUtils.java b/app/src/main/java/com/android/calendar/event/EventViewUtils.java index 52642bc09..fca5edea3 100644 --- a/app/src/main/java/com/android/calendar/event/EventViewUtils.java +++ b/app/src/main/java/com/android/calendar/event/EventViewUtils.java @@ -46,8 +46,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 || minutes == 0) { diff --git a/app/src/main/java/com/android/calendar/settings/GeneralPreferences.kt b/app/src/main/java/com/android/calendar/settings/GeneralPreferences.kt index c5d9b03d9..47222f4b3 100644 --- a/app/src/main/java/com/android/calendar/settings/GeneralPreferences.kt +++ b/app/src/main/java/com/android/calendar/settings/GeneralPreferences.kt @@ -73,6 +73,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 @@ -117,6 +118,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)!! @@ -154,6 +156,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), buildSnoozeDelayEntries() buildDefaultReminderPrefEntries() + handleUseCustomSnoozeDelayVisibility() defaultEventDurationPref.summary = defaultEventDurationPref.entry themePref.summary = themePref.entry weekStartPref.summary = weekStartPref.entry @@ -186,6 +189,10 @@ class GeneralPreferences : PreferenceFragmentCompat(), initializeColorMap() } + 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") @@ -351,6 +358,7 @@ class GeneralPreferences : PreferenceFragmentCompat(), snoozeDelayPref -> { snoozeDelayPref.value = newValue as String snoozeDelayPref.summary = snoozeDelayPref.entry + handleUseCustomSnoozeDelayVisibility() } defaultStartPref -> { val i = defaultStartPref.findIndexOfValue(newValue as String) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index c754fa3e4..1eb8866e2 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -110,6 +110,7 @@ + "-1" "5" "10" "15" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cdef1aed5..a978701ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,6 +39,7 @@ None + None 1 minute -- GitLab