From a7ef12bcca4c7c8b57521678cea7ede8558ec086 Mon Sep 17 00:00:00 2001 From: Florian Angermeier Date: Tue, 20 Mar 2018 19:06:50 +0100 Subject: [PATCH 1/2] Fix closing string tag Add missing "<" character. --- app/src/main/res/values-lt/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index dd3ff0f26..1c8404837 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -178,7 +178,7 @@ Kojų diena Susitikimas su Jonu Akmenų sode - Bibliotekoje/string> + Bibliotekoje Pietūs su Marija Dangoraižyje Kavos laikas From 6ca192ccc918498153c99765706d103eaf52cdef Mon Sep 17 00:00:00 2001 From: Florian Angermeier Date: Tue, 20 Mar 2018 23:56:55 +0100 Subject: [PATCH 2/2] Improve notification content by displaying date if useful The date will now be included in the notification content if it makes sense to do so. For the time range a en dash is now used instead of the minus symbol. --- .../calendar/extensions/Context.kt | 15 +++++++++++++-- .../calendar/helpers/Formatter.kt | 6 ++++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 4e9d8c175..2dc798663 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -37,6 +37,7 @@ import com.simplemobiletools.commons.helpers.isMarshmallowPlus import com.simplemobiletools.commons.helpers.isOreoPlus import org.joda.time.DateTime import org.joda.time.DateTimeZone +import org.joda.time.LocalDate import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -157,9 +158,19 @@ fun Context.notifyEvent(event: Event) { val pendingIntent = getPendingIntent(applicationContext, event) val startTime = Formatter.getTimeFromTS(applicationContext, event.startTS) val endTime = Formatter.getTimeFromTS(applicationContext, event.endTS) + val startDate = Formatter.getDateFromTS(event.startTS) + val displayedStartDate: String + if (startDate == LocalDate.now()) { + displayedStartDate = "" + } else if (startDate == LocalDate.now().plusDays(1)) { + 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 descriptionOrLocation = if (config.replaceDescription) event.location else event.description - val notification = getNotification(applicationContext, pendingIntent, event, "$timeRange $descriptionOrLocation") + val content = arrayOf(displayedStartDate, timeRange, descriptionOrLocation).joinToString(" ") + val notification = getNotification(applicationContext, pendingIntent, event, content) val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(event.id, notification) } @@ -210,7 +221,7 @@ private fun getNotification(context: Context, pendingIntent: PendingIntent, even return builder.build() } -private fun getFormattedEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime - $endTime" +private fun getFormattedEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime\u2013$endTime" private fun getPendingIntent(context: Context, event: Event): PendingIntent { val intent = Intent(context, EventActivity::class.java) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt index ef2389d3f..1605e164a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt @@ -7,7 +7,9 @@ import com.simplemobiletools.calendar.extensions.getNowSeconds import com.simplemobiletools.calendar.extensions.seconds import org.joda.time.DateTime import org.joda.time.DateTimeZone +import org.joda.time.LocalDate import org.joda.time.format.DateTimeFormat +import java.text.DateFormat object Formatter { val DAYCODE_PATTERN = "YYYYMMdd" @@ -76,6 +78,8 @@ object Formatter { fun getDayCodeFromDateTime(dateTime: DateTime) = dateTime.toString(DAYCODE_PATTERN) + fun getDateFromTS(ts: Int) = LocalDate(ts * 1000L, DateTimeZone.getDefault()) + fun getDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.getDefault()) fun getUTCDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.UTC) @@ -104,4 +108,6 @@ object Formatter { } fun getShiftedImportTimestamp(ts: Int) = getUTCDateTimeFromTS(ts).withTime(13, 0, 0, 0).withZoneRetainFields(DateTimeZone.getDefault()).seconds() + + fun getDayAndMonth(localDate: LocalDate) = localDate.toString("dd.MM.") } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2ee73b187..b91bf2309 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -89,6 +89,7 @@ Erinnerung + Morgen vorher Füge eine weitere Erinnerung hinzu Ereignis Erinnerungen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fad828cb1..6b8e8cd71 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -89,6 +89,7 @@ Reminder + Tomorrow before Add another reminder Event reminders