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.
This commit is contained in:
Florian Angermeier 2018-03-20 23:56:55 +01:00
parent a7ef12bcca
commit 6ca192ccc9
4 changed files with 21 additions and 2 deletions

View File

@ -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)

View File

@ -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.")
}

View File

@ -89,6 +89,7 @@
<!-- Event Reminders -->
<string name="reminder">Erinnerung</string>
<string name="tomorrow">Morgen</string>
<string name="before">vorher</string>
<string name="add_another_reminder">Füge eine weitere Erinnerung hinzu</string>
<string name="event_reminders">Ereignis Erinnerungen</string>

View File

@ -89,6 +89,7 @@
<!-- Event Reminders -->
<string name="reminder">Reminder</string>
<string name="tomorrow">Tomorrow</string>
<string name="before">before</string>
<string name="add_another_reminder">Add another reminder</string>
<string name="event_reminders">Event reminders</string>