Adjust if-block for clarity.
This commit is contained in:
parent
997cf25276
commit
05d96ca48e
@ -59,45 +59,43 @@ public class UpcomingAlarmReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
||||||
nm.cancel(TAG, (int) id);
|
nm.cancel(TAG, (int) id);
|
||||||
|
} else if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
||||||
|
new AlarmController(context, null).cancelAlarm(alarm, false, true);
|
||||||
} else {
|
} else {
|
||||||
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
// Prepare notification
|
||||||
new AlarmController(context, null).cancelAlarm(alarm, false, true);
|
// http://stackoverflow.com/a/15803726/5055032
|
||||||
|
// Notifications aren't updated on the UI thread, so we could have
|
||||||
|
// done this in the background. However, no lengthy operations are
|
||||||
|
// done here, so doing so is a premature optimization.
|
||||||
|
String title;
|
||||||
|
String text;
|
||||||
|
if (ACTION_SHOW_SNOOZING.equals(intent.getAction())) {
|
||||||
|
if (!alarm.isSnoozed())
|
||||||
|
throw new IllegalStateException("Can't show snoozing notif. if alarm not snoozed!");
|
||||||
|
title = alarm.label().isEmpty() ? context.getString(R.string.alarm) : alarm.label();
|
||||||
|
text = context.getString(R.string.title_snoozing_until,
|
||||||
|
formatTime(context, alarm.snoozingUntil()));
|
||||||
} else {
|
} else {
|
||||||
// Prepare notification
|
// No intent action required for default behavior
|
||||||
// http://stackoverflow.com/a/15803726/5055032
|
title = context.getString(R.string.upcoming_alarm);
|
||||||
// Notifications aren't updated on the UI thread, so we could have
|
text = formatTime(context, alarm.ringsAt());
|
||||||
// done this in the background. However, no lengthy operations are
|
if (!alarm.label().isEmpty()) {
|
||||||
// done here, so doing so is a premature optimization.
|
text = alarm.label() + ", " + text;
|
||||||
String title;
|
|
||||||
String text;
|
|
||||||
if (ACTION_SHOW_SNOOZING.equals(intent.getAction())) {
|
|
||||||
if (!alarm.isSnoozed())
|
|
||||||
throw new IllegalStateException("Can't show snoozing notif. if alarm not snoozed!");
|
|
||||||
title = alarm.label().isEmpty() ? context.getString(R.string.alarm) : alarm.label();
|
|
||||||
text = context.getString(R.string.title_snoozing_until,
|
|
||||||
formatTime(context, alarm.snoozingUntil()));
|
|
||||||
} else {
|
|
||||||
// No intent action required for default behavior
|
|
||||||
title = context.getString(R.string.upcoming_alarm);
|
|
||||||
text = formatTime(context, alarm.ringsAt());
|
|
||||||
if (!alarm.label().isEmpty()) {
|
|
||||||
text = alarm.label() + ", " + text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent dismissIntent = new Intent(context, UpcomingAlarmReceiver.class)
|
|
||||||
.setAction(ACTION_DISMISS_NOW)
|
|
||||||
.putExtra(EXTRA_ALARM, ParcelableUtil.marshall(alarm));
|
|
||||||
PendingIntent piDismiss = PendingIntent.getBroadcast(context, (int) id, dismissIntent, FLAG_ONE_SHOT);
|
|
||||||
Notification note = new NotificationCompat.Builder(context)
|
|
||||||
.setSmallIcon(R.drawable.ic_alarm_24dp)
|
|
||||||
.setContentTitle(title)
|
|
||||||
.setContentText(text)
|
|
||||||
.setContentIntent(ContentIntentUtils.create(context, MainActivity.PAGE_ALARMS, id))
|
|
||||||
.addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), piDismiss)
|
|
||||||
.build();
|
|
||||||
nm.notify(TAG, (int) id, note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intent dismissIntent = new Intent(context, UpcomingAlarmReceiver.class)
|
||||||
|
.setAction(ACTION_DISMISS_NOW)
|
||||||
|
.putExtra(EXTRA_ALARM, ParcelableUtil.marshall(alarm));
|
||||||
|
PendingIntent piDismiss = PendingIntent.getBroadcast(context, (int) id, dismissIntent, FLAG_ONE_SHOT);
|
||||||
|
Notification note = new NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.ic_alarm_24dp)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(text)
|
||||||
|
.setContentIntent(ContentIntentUtils.create(context, MainActivity.PAGE_ALARMS, id))
|
||||||
|
.addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), piDismiss)
|
||||||
|
.build();
|
||||||
|
nm.notify(TAG, (int) id, note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user