Remove format changes in Replace Yes/No buttons by "Enter" for numerical habits

pull/627/head
Nam Nguyen 5 years ago
parent 603dca97ac
commit af1ede8715

@ -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 =
getBroadcast( PendingIntent.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 =
getBroadcast( PendingIntent.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 =
getBroadcast( PendingIntent.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,8 +71,10 @@ class PendingIntentFactory
context, habit)) context, habit))
.getPendingIntent(0, FLAG_UPDATE_CURRENT)!! .getPendingIntent(0, FLAG_UPDATE_CURRENT)!!
fun showReminder(habit: Habit, reminderTime: Long?, timestamp: Long): PendingIntent = fun showReminder(habit: Habit,
getBroadcast( reminderTime: Long?,
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 {
@ -84,7 +86,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun snoozeNotification(habit: Habit): PendingIntent = fun snoozeNotification(habit: Habit): PendingIntent =
getBroadcast( PendingIntent.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)
@ -93,7 +95,7 @@ class PendingIntentFactory
FLAG_UPDATE_CURRENT) FLAG_UPDATE_CURRENT)
fun toggleCheckmark(habit: Habit, timestamp: Long?): PendingIntent = fun toggleCheckmark(habit: Habit, timestamp: Long?): PendingIntent =
getBroadcast( PendingIntent.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)

@ -69,11 +69,11 @@ class AndroidNotificationTray
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
// Some Xiaomi phones produce a RuntimeException if custom notification sounds are used. // Some Xiaomi phones produce a RuntimeException if custom notification sounds are used.
Log.i("AndroidNotificationTray", Log.i("AndroidNotificationTray",
"Failed to show notification. Retrying without sound.") "Failed to show notification. Retrying without sound.")
val n = buildNotification(habit, val n = buildNotification(habit,
reminderTime, reminderTime,
timestamp, timestamp,
disableSound = true) disableSound = true)
notificationManager.notify(notificationId, n) notificationManager.notify(notificationId, n)
} }
@ -95,7 +95,8 @@ 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, val enterAction = Action(
R.drawable.ic_action_check,
context.getString(R.string.enter), context.getString(R.string.enter),
pendingIntents.setNumericalValue(context, habit, 0, null)) pendingIntents.setNumericalValue(context, habit, 0, null))
@ -110,7 +111,7 @@ class AndroidNotificationTray
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))
.setSound(null) .setSound(null)
@ -137,8 +138,8 @@ class AndroidNotificationTray
builder.setLights(Color.RED, 1000, 1000) builder.setLights(Color.RED, 1000, 1000)
val snoozeAction = Action(R.drawable.ic_action_snooze, val snoozeAction = Action(R.drawable.ic_action_snooze,
context.getString(R.string.snooze), context.getString(R.string.snooze),
pendingIntents.snoozeNotification(habit)) pendingIntents.snoozeNotification(habit))
wearableExtender.addAction(snoozeAction) wearableExtender.addAction(snoozeAction)
builder.addAction(snoozeAction) builder.addAction(snoozeAction)
@ -153,8 +154,8 @@ class AndroidNotificationTray
as NotificationManager as NotificationManager
if (SDK_INT >= Build.VERSION_CODES.O) { if (SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(REMINDERS_CHANNEL_ID, val channel = NotificationChannel(REMINDERS_CHANNEL_ID,
context.resources.getString(R.string.reminder), context.resources.getString(R.string.reminder),
NotificationManager.IMPORTANCE_DEFAULT) NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel) notificationManager.createNotificationChannel(channel)
} }
} }

Loading…
Cancel
Save