Simplify code; change notification actions to Yes/No/Later

pull/332/merge
Alinson S. Xavier 8 years ago
parent 7f1a35ebe5
commit 9d48b4bcdb

@ -54,11 +54,11 @@ class PendingIntentFactory
}, },
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun cancelNotification(habit: Habit): PendingIntent = fun removeRepetition(habit: Habit): PendingIntent =
PendingIntent.getBroadcast( PendingIntent.getBroadcast(
context, 3, context, 3,
Intent(context, WidgetReceiver::class.java).apply { Intent(context, WidgetReceiver::class.java).apply {
action = WidgetReceiver.ACTION_CANCEL_REPETITION action = WidgetReceiver.ACTION_REMOVE_REPETITION
data = Uri.parse(habit.uriString) data = Uri.parse(habit.uriString)
}, },
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)

@ -66,9 +66,9 @@ class AndroidNotificationTray
@NonNull timestamp: Timestamp) : Notification @NonNull timestamp: Timestamp) : Notification
{ {
val checkAction = Action( val addRepetitionAction = Action(
R.drawable.ic_action_check, R.drawable.ic_action_check,
context.getString(R.string.check), context.getString(R.string.yes),
pendingIntents.addCheckmark(habit, timestamp)) pendingIntents.addCheckmark(habit, timestamp))
val snoozeAction = Action( val snoozeAction = Action(
@ -76,10 +76,10 @@ class AndroidNotificationTray
context.getString(R.string.snooze), context.getString(R.string.snooze),
pendingIntents.snoozeNotification(habit)) pendingIntents.snoozeNotification(habit))
val cancelAction = Action( val removeRepetitionAction = Action(
R.drawable.ic_action_cancel, R.drawable.ic_action_cancel,
context.getString(android.R.string.no), context.getString(R.string.no),
pendingIntents.cancelNotification(habit) pendingIntents.removeRepetition(habit)
) )
val wearableBg = decodeResource(context.resources, R.drawable.stripe) val wearableBg = decodeResource(context.resources, R.drawable.stripe)
@ -89,9 +89,9 @@ class AndroidNotificationTray
// WearableExtender. // WearableExtender.
val wearableExtender = WearableExtender() val wearableExtender = WearableExtender()
.setBackground(wearableBg) .setBackground(wearableBg)
.addAction(checkAction) .addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
.addAction(snoozeAction) .addAction(snoozeAction)
.addAction(cancelAction)
val builder = NotificationCompat.Builder(context) val builder = NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
@ -99,9 +99,9 @@ class AndroidNotificationTray
.setContentText(habit.description) .setContentText(habit.description)
.setContentIntent(pendingIntents.showHabit(habit)) .setContentIntent(pendingIntents.showHabit(habit))
.setDeleteIntent(pendingIntents.dismissNotification(habit)) .setDeleteIntent(pendingIntents.dismissNotification(habit))
.addAction(checkAction) .addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
.addAction(snoozeAction) .addAction(snoozeAction)
.addAction(cancelAction)
.setSound(ringtoneManager.getURI()) .setSound(ringtoneManager.getURI())
.extend(wearableExtender) .extend(wearableExtender)
.setWhen(reminderTime) .setWhen(reminderTime)

@ -46,9 +46,6 @@ public class WidgetReceiver extends BroadcastReceiver
public static final String ACTION_REMOVE_REPETITION = public static final String ACTION_REMOVE_REPETITION =
"org.isoron.uhabits.ACTION_REMOVE_REPETITION"; "org.isoron.uhabits.ACTION_REMOVE_REPETITION";
public static final String ACTION_CANCEL_REPETITION =
"org.isoron.uhabits.ACTION_CANCEL_REPETITION";
public static final String ACTION_TOGGLE_REPETITION = public static final String ACTION_TOGGLE_REPETITION =
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION"; "org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
@ -91,11 +88,6 @@ public class WidgetReceiver extends BroadcastReceiver
controller.onRemoveRepetition(data.getHabit(), controller.onRemoveRepetition(data.getHabit(),
data.getTimestamp()); data.getTimestamp());
break; break;
case ACTION_CANCEL_REPETITION:
controller.onCancelRepetition(data.getHabit(),
data.getTimestamp());
break;
} }
} }
catch (RuntimeException e) catch (RuntimeException e)

@ -217,4 +217,6 @@
<string name="example_question_boolean">e.g. Did you exercise today?</string> <string name="example_question_boolean">e.g. Did you exercise today?</string>
<string name="question">Question</string> <string name="question">Question</string>
<string name="target">Target</string> <string name="target">Target</string>
<string name="yes">Yes</string>
<string name="no">No</string>
</resources> </resources>

@ -48,25 +48,20 @@ public class WidgetBehavior
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp) public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
{ {
notificationTray.cancel(habit);
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp); Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
if (rep != null) return; if (rep != null) return;
performToggle(habit, timestamp); performToggle(habit, timestamp);
notificationTray.cancel(habit);
} }
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp) public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
{ {
notificationTray.cancel(habit);
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp); Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
if (rep == null) return; if (rep == null) return;
performToggle(habit, timestamp); performToggle(habit, timestamp);
} }
public void onCancelRepetition(@NonNull Habit habit, Timestamp timestamp)
{
onRemoveRepetition(habit, timestamp);
notificationTray.cancel(habit);
}
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp) public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
{ {
performToggle(habit, timestamp); performToggle(habit, timestamp);

Loading…
Cancel
Save