|
|
@ -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,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())
|
|
|
|
|
|
|
|
|
|
|
@ -126,8 +137,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)
|
|
|
|
|
|
|
|
|
|
|
@ -142,8 +153,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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|