Skip to content

Commit

Permalink
Add_no_snooze_option
Browse files Browse the repository at this point in the history
  • Loading branch information
Fahim Salam Chowdhury authored and Gitsaibot committed Apr 3, 2024
1 parent e26f792 commit 4983629
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/android/calendar/alerts/AlertReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
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;
Expand Down Expand Up @@ -197,8 +199,16 @@ private static PendingIntent createDismissAlarmsIntent(Context context, long eve
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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
Expand Down Expand Up @@ -93,6 +94,10 @@ public void onHandleIntent(Intent intent) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.widget.TimePicker;

import com.android.calendar.Utils;
import com.android.calendar.settings.GeneralPreferences;

import ws.xsoh.etar.R;

Expand Down Expand Up @@ -55,6 +56,11 @@ protected void onPrepareDialog(int id, Dialog d) {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ private 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 == Integer.MIN_VALUE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
Expand Down Expand Up @@ -119,6 +120,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)!!
Expand Down Expand Up @@ -156,6 +158,7 @@ class GeneralPreferences : PreferenceFragmentCompat(),

buildSnoozeDelayEntries()
buildDefaultReminderPrefEntries()
handleUseCustomSnoozeDelayVisibility()
defaultEventDurationPref.summary = defaultEventDurationPref.entry
themePref.summary = themePref.entry
weekStartPref.summary = weekStartPref.entry
Expand Down Expand Up @@ -188,6 +191,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")
Expand Down Expand Up @@ -355,6 +362,7 @@ class GeneralPreferences : PreferenceFragmentCompat(),
snoozeDelayPref -> {
snoozeDelayPref.value = newValue as String
snoozeDelayPref.summary = snoozeDelayPref.entry
handleUseCustomSnoozeDelayVisibility()
}
defaultStartPref -> {
val i = defaultStartPref.findIndexOfValue(newValue as String)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
</string-array>

<string-array name="preferences_default_snooze_delay_values" translatable="false">
<item>"-1"</item>
<item>"5"</item>
<item>"10"</item>
<item>"15"</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

<!-- Reminder format strings -->
<string name="no_reminder_label">None</string>
<string name="no_snooze_label">None</string>
<plurals name="Nminutes">
<!-- This is the label for a 1-minute reminder. -->
<item quantity="one">1 minute</item>
Expand Down

0 comments on commit 4983629

Please sign in to comment.