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 29dcd41b7754c6272c5b4ddd134d5ed6d0ec35a7..26006d5a71912f02114c1672c5f7d64af91ba8f8 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 876768760a8d72833f3db69e6c90d0945b4ceaea..a72291f953a6566839f2fbaf9e5db0d787fea3db 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 41e9d2c323d045af9eb98c56609070fffa2703e3..dd228c4e71f69494fdd6f9de492fced38e3a8d56 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 52642bc09fbbc0144997df8f262460f7dd4d8f33..fca5edea311d28e122d820a381a04b5cf01b49ba 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 c5d9b03d9d00284a0397a31edd02e42da6f70357..47222f4b34800c29b2accc0113656d19b35c2df2 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 c754fa3e4a6e35a4703678311fa0a591e831581a..1eb8866e224946733c5a4d0e08ce3659b0fda79e 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 cdef1aed54dab8b63f40c4e43f1816deb05e0333..a978701ba076598d4f3ba147be63f27ee676c315 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