Adjust if-block for clarity.

This commit is contained in:
Phillip Hsu 2017-03-01 13:30:20 -08:00
parent 997cf25276
commit 05d96ca48e

View File

@ -59,45 +59,43 @@ public class UpcomingAlarmReceiver extends BroadcastReceiver {
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
nm.cancel(TAG, (int) id);
} else if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
new AlarmController(context, null).cancelAlarm(alarm, false, true);
} else {
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
new AlarmController(context, null).cancelAlarm(alarm, false, true);
// Prepare notification
// 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 {
// Prepare notification
// 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 {
// 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;
}
// 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);
}
}
}