Replace Yes/No buttons by "Enter" for numerical habits

pull/627/head
Nam Nguyen 5 years ago
parent 84523869e8
commit e1368777ab

@ -36,7 +36,7 @@ class PendingIntentFactory
private val intentFactory: IntentFactory) { private val intentFactory: IntentFactory) {
fun addCheckmark(habit: Habit, timestamp: Timestamp?): PendingIntent = fun addCheckmark(habit: Habit, timestamp: Timestamp?): PendingIntent =
PendingIntent.getBroadcast( getBroadcast(
context, 1, context, 1,
Intent(context, WidgetReceiver::class.java).apply { Intent(context, WidgetReceiver::class.java).apply {
data = Uri.parse(habit.uriString) data = Uri.parse(habit.uriString)
@ -46,7 +46,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun dismissNotification(habit: Habit): PendingIntent = fun dismissNotification(habit: Habit): PendingIntent =
PendingIntent.getBroadcast( getBroadcast(
context, 0, context, 0,
Intent(context, ReminderReceiver::class.java).apply { Intent(context, ReminderReceiver::class.java).apply {
action = WidgetReceiver.ACTION_DISMISS_REMINDER action = WidgetReceiver.ACTION_DISMISS_REMINDER
@ -55,7 +55,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun removeRepetition(habit: Habit): PendingIntent = fun removeRepetition(habit: Habit): PendingIntent =
PendingIntent.getBroadcast( getBroadcast(
context, 3, context, 3,
Intent(context, WidgetReceiver::class.java).apply { Intent(context, WidgetReceiver::class.java).apply {
action = WidgetReceiver.ACTION_REMOVE_REPETITION action = WidgetReceiver.ACTION_REMOVE_REPETITION
@ -71,10 +71,8 @@ class PendingIntentFactory
context, habit)) context, habit))
.getPendingIntent(0, FLAG_UPDATE_CURRENT)!! .getPendingIntent(0, FLAG_UPDATE_CURRENT)!!
fun showReminder(habit: Habit, fun showReminder(habit: Habit, reminderTime: Long?, timestamp: Long): PendingIntent =
reminderTime: Long?, getBroadcast(
timestamp: Long): PendingIntent =
PendingIntent.getBroadcast(
context, context,
(habit.getId()!! % Integer.MAX_VALUE).toInt() + 1, (habit.getId()!! % Integer.MAX_VALUE).toInt() + 1,
Intent(context, ReminderReceiver::class.java).apply { Intent(context, ReminderReceiver::class.java).apply {
@ -86,7 +84,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun snoozeNotification(habit: Habit): PendingIntent = fun snoozeNotification(habit: Habit): PendingIntent =
PendingIntent.getBroadcast( getBroadcast(
context, 0, context, 0,
Intent(context, ReminderReceiver::class.java).apply { Intent(context, ReminderReceiver::class.java).apply {
data = Uri.parse(habit.uriString) data = Uri.parse(habit.uriString)
@ -95,7 +93,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun toggleCheckmark(habit: Habit, timestamp: Long?): PendingIntent = fun toggleCheckmark(habit: Habit, timestamp: Long?): PendingIntent =
PendingIntent.getBroadcast( getBroadcast(
context, 2, context, 2,
Intent(context, WidgetReceiver::class.java).apply { Intent(context, WidgetReceiver::class.java).apply {
data = Uri.parse(habit.uriString) data = Uri.parse(habit.uriString)

@ -95,30 +95,41 @@ class AndroidNotificationTray
context.getString(R.string.no), context.getString(R.string.no),
pendingIntents.removeRepetition(habit)) pendingIntents.removeRepetition(habit))
val enterAction = Action(R.drawable.ic_action_check,
context.getString(R.string.enter),
pendingIntents.setNumericalValue(context, habit, 0, null))
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
// on the watch, Pebble requires us to add them to the // on the watch, Pebble requires us to add them to the
// WearableExtender. // WearableExtender.
val wearableExtender = WearableExtender() val wearableExtender = WearableExtender().setBackground(wearableBg)
.setBackground(wearableBg)
.addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
val defaultText = context.getString(R.string.default_reminder_question) val defaultText = context.getString(R.string.default_reminder_question)
val builder = Builder(context, REMINDERS_CHANNEL_ID) val builder = Builder(context, REMINDERS_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setContentTitle(habit.name) .setContentTitle(habit.name)
.setContentText(if(habit.question.isBlank()) defaultText else habit.question) .setContentText(if (habit.question.isBlank()) defaultText else habit.question)
.setContentIntent(pendingIntents.showHabit(habit)) .setContentIntent(pendingIntents.showHabit(habit))
.setDeleteIntent(pendingIntents.dismissNotification(habit)) .setDeleteIntent(pendingIntents.dismissNotification(habit))
.addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
.setSound(null) .setSound(null)
.setWhen(reminderTime) .setWhen(reminderTime)
.setShowWhen(true) .setShowWhen(true)
.setOngoing(preferences.shouldMakeNotificationsSticky()) .setOngoing(preferences.shouldMakeNotificationsSticky())
if (habit.isNumerical) {
wearableExtender.addAction(enterAction)
builder.addAction(enterAction)
} else {
wearableExtender
.addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
builder
.addAction(addRepetitionAction)
.addAction(removeRepetitionAction)
}
if (!disableSound) if (!disableSound)
builder.setSound(ringtoneManager.getURI()) builder.setSound(ringtoneManager.getURI())

@ -194,4 +194,5 @@
<string name="every_month">Every month</string> <string name="every_month">Every month</string>
<string name="validation_cannot_be_blank">Cannot be blank</string> <string name="validation_cannot_be_blank">Cannot be blank</string>
<string name="today">Today</string> <string name="today">Today</string>
<string name="enter">Enter</string>
</resources> </resources>
Loading…
Cancel
Save