fix #403, tweak some things around notifications

This commit is contained in:
tibbi 2018-03-23 23:09:07 +01:00
parent 1aae2a6fc6
commit 1d54ea7788
1 changed files with 7 additions and 9 deletions

View File

@ -159,17 +159,15 @@ fun Context.notifyEvent(event: Event) {
val startTime = Formatter.getTimeFromTS(applicationContext, event.startTS) val startTime = Formatter.getTimeFromTS(applicationContext, event.startTS)
val endTime = Formatter.getTimeFromTS(applicationContext, event.endTS) val endTime = Formatter.getTimeFromTS(applicationContext, event.endTS)
val startDate = Formatter.getDateFromTS(event.startTS) val startDate = Formatter.getDateFromTS(event.startTS)
val displayedStartDate: String val displayedStartDate = when (startDate) {
if (startDate == LocalDate.now()) { LocalDate.now() -> ""
displayedStartDate = "" LocalDate.now().plusDays(1) -> getString(R.string.tomorrow)
} else if (startDate == LocalDate.now().plusDays(1)) { else -> Formatter.getDayAndMonth(startDate)
displayedStartDate = getString(R.string.tomorrow)
} else /* At least 2 days in the future */ {
displayedStartDate = Formatter.getDayAndMonth(startDate)
} }
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 = arrayOf(displayedStartDate, timeRange, descriptionOrLocation).joinToString(" ") val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
val notification = getNotification(applicationContext, pendingIntent, event, content) val notification = getNotification(applicationContext, pendingIntent, event, content)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id, notification) notificationManager.notify(event.id, notification)
@ -221,7 +219,7 @@ private fun getNotification(context: Context, pendingIntent: PendingIntent, even
return builder.build() return builder.build()
} }
private fun getFormattedEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime\u2013$endTime" private fun getFormattedEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime \u2013 $endTime"
private fun getPendingIntent(context: Context, event: Event): PendingIntent { private fun getPendingIntent(context: Context, event: Event): PendingIntent {
val intent = Intent(context, EventActivity::class.java) val intent = Intent(context, EventActivity::class.java)