fix #948, allow customizing notification behaviour per event type

This commit is contained in:
tibbi 2019-08-27 15:44:55 +02:00
parent 0326e52fb1
commit 578c7ed30f
1 changed files with 8 additions and 6 deletions

View File

@ -194,10 +194,12 @@ fun Context.notifyEvent(originalEvent: Event) {
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 content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
ensureBackgroundThread {
val notification = getNotification(pendingIntent, event, content)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id!!.toInt(), notification)
}
}
@SuppressLint("NewApi")
fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: String, publicVersion: Boolean = false): Notification {
@ -213,7 +215,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
if (soundUri != config.lastSoundUri || config.lastVibrateOnReminder != config.vibrateOnReminder) {
if (!publicVersion) {
if (isOreoPlus()) {
val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}"
val oldChannelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
notificationManager.deleteNotificationChannel(oldChannelId)
}
}
@ -223,7 +225,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
config.lastSoundUri = soundUri
}
val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}"
val channelId = "simple_calendar_${config.lastReminderChannel}_${config.reminderAudioStream}_${event.eventType}"
if (isOreoPlus()) {
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
@ -231,7 +233,7 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
.setLegacyStreamType(config.reminderAudioStream)
.build()
val name = resources.getString(R.string.event_reminders)
val name = eventTypesDB.getEventTypeWithId(event.eventType)?.getDisplayTitle()
val importance = NotificationManager.IMPORTANCE_HIGH
NotificationChannel(channelId, name, importance).apply {
setBypassDnd(true)