mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'dev' of git://github.com/rsri/uhabits into pull/cancel_notification
This commit is contained in:
@@ -54,6 +54,15 @@ class PendingIntentFactory
|
||||
},
|
||||
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 =
|
||||
android.support.v4.app.TaskStackBuilder
|
||||
.create(context)
|
||||
|
||||
@@ -76,6 +76,12 @@ class AndroidNotificationTray
|
||||
context.getString(R.string.snooze),
|
||||
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)
|
||||
|
||||
// Even though the set of actions is the same on the phone and
|
||||
@@ -85,6 +91,7 @@ class AndroidNotificationTray
|
||||
.setBackground(wearableBg)
|
||||
.addAction(checkAction)
|
||||
.addAction(snoozeAction)
|
||||
.addAction(cancelAction)
|
||||
|
||||
val builder = NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
@@ -94,6 +101,7 @@ class AndroidNotificationTray
|
||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||
.addAction(checkAction)
|
||||
.addAction(snoozeAction)
|
||||
.addAction(cancelAction)
|
||||
.setSound(ringtoneManager.getURI())
|
||||
.extend(wearableExtender)
|
||||
.setWhen(reminderTime)
|
||||
|
||||
@@ -46,6 +46,9 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
public static final String 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 =
|
||||
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
|
||||
|
||||
@@ -88,6 +91,11 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
controller.onRemoveRepetition(data.getHabit(),
|
||||
data.getTimestamp());
|
||||
break;
|
||||
|
||||
case ACTION_CANCEL_REPETITION:
|
||||
controller.onCancelRepetition(data.getHabit(),
|
||||
data.getTimestamp());
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
|
||||
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 266 B |
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 B |
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
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);
|
||||
}
|
||||
|
||||
public void onCancelRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
onRemoveRepetition(habit, timestamp);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
performToggle(habit, timestamp);
|
||||
|
||||
Reference in New Issue
Block a user