Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b9e80f3 authored by Daria Evdokimova's avatar Daria Evdokimova
Browse files

Allowing multiple alarms to be set for the same time through Intents.

Right now setting multiple alarms for the same time through Intents
is not allowed even though it is allowed through the UI.
This CL changes that. Tests for this feature are in the following CL.

Change-Id: I1383300e86e9d62042704edf45d146303f81c0a7
parent 55ff960b
Loading
Loading
Loading
Loading
+2 −19
Original line number Diff line number Diff line
@@ -89,31 +89,13 @@ public class HandleApiCalls extends Activity {
            return;
        }

        final boolean skipUi = intent.getBooleanExtra(AlarmClock.EXTRA_SKIP_UI, false);
        Events.sendAlarmEvent(R.string.action_create, R.string.label_intent);
        final boolean skipUi = intent.getBooleanExtra(AlarmClock.EXTRA_SKIP_UI, false);

        final StringBuilder selection = new StringBuilder();
        final List<String> args = new ArrayList<>();
        setSelectionFromIntent(intent, hour, minutes, selection, args);

        // Check if the alarm already exists and handle it
        final ContentResolver cr = getContentResolver();
        final List<Alarm> alarms = Alarm.getAlarms(cr,
                selection.toString(),
                args.toArray(new String[args.size()]));
        if (!alarms.isEmpty()) {
            Alarm alarm = alarms.get(0);
            alarm.enabled = true;
            Alarm.updateAlarm(cr, alarm);

            // Delete all old instances and create a new one with updated values
            AlarmStateManager.deleteAllInstances(this, alarm.id);
            setupInstance(alarm.createInstanceAfter(Calendar.getInstance()), skipUi);
            LogUtils.i("HandleApiCalls deleted old, created new alarm: %s", alarm);
            return;
        }

        // Otherwise insert it and handle it
        final String message = getMessageFromIntent(intent);
        final DaysOfWeek daysOfWeek = getDaysFromIntent(intent);
        final boolean vibrate = intent.getBooleanExtra(AlarmClock.EXTRA_VIBRATE, false);
@@ -134,6 +116,7 @@ public class HandleApiCalls extends Activity {
        }
        alarm.deleteAfterUse = !daysOfWeek.isRepeating() && skipUi;

        final ContentResolver cr = getContentResolver();
        alarm = Alarm.addAlarm(cr, alarm);
        setupInstance(alarm.createInstanceAfter(Calendar.getInstance()), skipUi);
        LogUtils.i("HandleApiCalls set up alarm: %s", alarm);