mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Simplify code; change notification actions to Yes/No/Later
This commit is contained in:
@@ -54,11 +54,11 @@ class PendingIntentFactory
|
||||
},
|
||||
FLAG_UPDATE_CURRENT)
|
||||
|
||||
fun cancelNotification(habit: Habit): PendingIntent =
|
||||
fun removeRepetition(habit: Habit): PendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
context, 3,
|
||||
Intent(context, WidgetReceiver::class.java).apply {
|
||||
action = WidgetReceiver.ACTION_CANCEL_REPETITION
|
||||
action = WidgetReceiver.ACTION_REMOVE_REPETITION
|
||||
data = Uri.parse(habit.uriString)
|
||||
},
|
||||
FLAG_UPDATE_CURRENT)
|
||||
|
||||
@@ -66,9 +66,9 @@ class AndroidNotificationTray
|
||||
@NonNull timestamp: Timestamp) : Notification
|
||||
{
|
||||
|
||||
val checkAction = Action(
|
||||
val addRepetitionAction = Action(
|
||||
R.drawable.ic_action_check,
|
||||
context.getString(R.string.check),
|
||||
context.getString(R.string.yes),
|
||||
pendingIntents.addCheckmark(habit, timestamp))
|
||||
|
||||
val snoozeAction = Action(
|
||||
@@ -76,10 +76,10 @@ class AndroidNotificationTray
|
||||
context.getString(R.string.snooze),
|
||||
pendingIntents.snoozeNotification(habit))
|
||||
|
||||
val cancelAction = Action(
|
||||
val removeRepetitionAction = Action(
|
||||
R.drawable.ic_action_cancel,
|
||||
context.getString(android.R.string.no),
|
||||
pendingIntents.cancelNotification(habit)
|
||||
context.getString(R.string.no),
|
||||
pendingIntents.removeRepetition(habit)
|
||||
)
|
||||
|
||||
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
||||
@@ -89,9 +89,9 @@ class AndroidNotificationTray
|
||||
// WearableExtender.
|
||||
val wearableExtender = WearableExtender()
|
||||
.setBackground(wearableBg)
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
.addAction(cancelAction)
|
||||
|
||||
val builder = NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
@@ -99,9 +99,9 @@ class AndroidNotificationTray
|
||||
.setContentText(habit.description)
|
||||
.setContentIntent(pendingIntents.showHabit(habit))
|
||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
.addAction(cancelAction)
|
||||
.setSound(ringtoneManager.getURI())
|
||||
.extend(wearableExtender)
|
||||
.setWhen(reminderTime)
|
||||
|
||||
@@ -46,9 +46,6 @@ 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";
|
||||
|
||||
@@ -91,11 +88,6 @@ 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)
|
||||
|
||||
@@ -217,4 +217,6 @@
|
||||
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||
<string name="question">Question</string>
|
||||
<string name="target">Target</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
@@ -48,25 +48,20 @@ public class WidgetBehavior
|
||||
|
||||
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
notificationTray.cancel(habit);
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep != null) return;
|
||||
performToggle(habit, timestamp);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
notificationTray.cancel(habit);
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep == null) return;
|
||||
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