Merge branch 'dev' of git://github.com/rsri/uhabits into pull/cancel_notification

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

@ -54,6 +54,15 @@ class PendingIntentFactory
}, },
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun cancelNotification(habit: Habit): PendingIntent =
PendingIntent.getBroadcast(
context, 3,
Intent(context, WidgetReceiver::class.java).apply {
action = WidgetReceiver.ACTION_CANCEL_REPETITION
data = Uri.parse(habit.uriString)
},
FLAG_UPDATE_CURRENT)
fun showHabit(habit: Habit): PendingIntent = fun showHabit(habit: Habit): PendingIntent =
android.support.v4.app.TaskStackBuilder android.support.v4.app.TaskStackBuilder
.create(context) .create(context)

@ -76,6 +76,12 @@ class AndroidNotificationTray
context.getString(R.string.snooze), context.getString(R.string.snooze),
pendingIntents.snoozeNotification(habit)) pendingIntents.snoozeNotification(habit))
val cancelAction = Action(
R.drawable.ic_action_cancel,
context.getString(android.R.string.no),
pendingIntents.cancelNotification(habit)
)
val wearableBg = decodeResource(context.resources, R.drawable.stripe) val wearableBg = decodeResource(context.resources, R.drawable.stripe)
// Even though the set of actions is the same on the phone and // Even though the set of actions is the same on the phone and
@ -85,6 +91,7 @@ class AndroidNotificationTray
.setBackground(wearableBg) .setBackground(wearableBg)
.addAction(checkAction) .addAction(checkAction)
.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)
@ -94,6 +101,7 @@ class AndroidNotificationTray
.setDeleteIntent(pendingIntents.dismissNotification(habit)) .setDeleteIntent(pendingIntents.dismissNotification(habit))
.addAction(checkAction) .addAction(checkAction)
.addAction(snoozeAction) .addAction(snoozeAction)
.addAction(cancelAction)
.setSound(ringtoneManager.getURI()) .setSound(ringtoneManager.getURI())
.extend(wearableExtender) .extend(wearableExtender)
.setWhen(reminderTime) .setWhen(reminderTime)

@ -46,6 +46,9 @@ 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";
@ -88,6 +91,11 @@ 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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

@ -61,6 +61,12 @@ public class WidgetBehavior
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