fix #948, allow customizing notification behaviour per event type
This commit is contained in:
parent
0326e52fb1
commit
578c7ed30f
|
@ -194,9 +194,11 @@ fun Context.notifyEvent(originalEvent: Event) {
|
||||||
val timeRange = if (event.getIsAllDay()) getString(R.string.all_day) else getFormattedEventTime(startTime, endTime)
|
val timeRange = if (event.getIsAllDay()) getString(R.string.all_day) else getFormattedEventTime(startTime, endTime)
|
||||||
val descriptionOrLocation = if (config.replaceDescription) event.location else event.description
|
val descriptionOrLocation = if (config.replaceDescription) event.location else event.description
|
||||||
val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
|
val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
|
||||||
val notification = getNotification(pendingIntent, event, content)
|
ensureBackgroundThread {
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notification = getNotification(pendingIntent, event, content)
|
||||||
notificationManager.notify(event.id!!.toInt(), notification)
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
notificationManager.notify(event.id!!.toInt(), notification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
|
@ -213,7 +215,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
|
||||||
if (soundUri != config.lastSoundUri || config.lastVibrateOnReminder != config.vibrateOnReminder) {
|
if (soundUri != config.lastSoundUri || config.lastVibrateOnReminder != config.vibrateOnReminder) {
|
||||||
if (!publicVersion) {
|
if (!publicVersion) {
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}"
|
val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
|
||||||
notificationManager.deleteNotificationChannel(oldChannelId)
|
notificationManager.deleteNotificationChannel(oldChannelId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +225,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
|
||||||
config.lastSoundUri = soundUri
|
config.lastSoundUri = soundUri
|
||||||
}
|
}
|
||||||
|
|
||||||
val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}"
|
val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
val audioAttributes = AudioAttributes.Builder()
|
val audioAttributes = AudioAttributes.Builder()
|
||||||
.setUsage(AudioAttributes.USAGE_ALARM)
|
.setUsage(AudioAttributes.USAGE_ALARM)
|
||||||
|
@ -231,7 +233,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
|
||||||
.setLegacyStreamType(config.reminderAudioStream)
|
.setLegacyStreamType(config.reminderAudioStream)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val name = resources.getString(R.string.event_reminders)
|
val name = eventTypesDB.getEventTypeWithId(event.eventType)?.getDisplayTitle()
|
||||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||||
NotificationChannel(channelId, name, importance).apply {
|
NotificationChannel(channelId, name, importance).apply {
|
||||||
setBypassDnd(true)
|
setBypassDnd(true)
|
||||||
|
|
Loading…
Reference in New Issue