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:
parent
a7ef12bcca
commit
6ca192ccc9
|
@ -37,6 +37,7 @@ import com.simplemobiletools.commons.helpers.isMarshmallowPlus
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.LocalDate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -157,9 +158,19 @@ fun Context.notifyEvent(event: Event) {
|
||||||
val pendingIntent = getPendingIntent(applicationContext, event)
|
val pendingIntent = getPendingIntent(applicationContext, 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 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 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 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
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
notificationManager.notify(event.id, notification)
|
notificationManager.notify(event.id, notification)
|
||||||
}
|
}
|
||||||
|
@ -210,7 +221,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 - $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)
|
||||||
|
|
|
@ -7,7 +7,9 @@ import com.simplemobiletools.calendar.extensions.getNowSeconds
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.LocalDate
|
||||||
import org.joda.time.format.DateTimeFormat
|
import org.joda.time.format.DateTimeFormat
|
||||||
|
import java.text.DateFormat
|
||||||
|
|
||||||
object Formatter {
|
object Formatter {
|
||||||
val DAYCODE_PATTERN = "YYYYMMdd"
|
val DAYCODE_PATTERN = "YYYYMMdd"
|
||||||
|
@ -76,6 +78,8 @@ object Formatter {
|
||||||
|
|
||||||
fun getDayCodeFromDateTime(dateTime: DateTime) = dateTime.toString(DAYCODE_PATTERN)
|
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 getDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.getDefault())
|
||||||
|
|
||||||
fun getUTCDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.UTC)
|
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 getShiftedImportTimestamp(ts: Int) = getUTCDateTimeFromTS(ts).withTime(13, 0, 0, 0).withZoneRetainFields(DateTimeZone.getDefault()).seconds()
|
||||||
|
|
||||||
|
fun getDayAndMonth(localDate: LocalDate) = localDate.toString("dd.MM.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
|
|
||||||
<!-- Event Reminders -->
|
<!-- Event Reminders -->
|
||||||
<string name="reminder">Erinnerung</string>
|
<string name="reminder">Erinnerung</string>
|
||||||
|
<string name="tomorrow">Morgen</string>
|
||||||
<string name="before">vorher</string>
|
<string name="before">vorher</string>
|
||||||
<string name="add_another_reminder">Füge eine weitere Erinnerung hinzu</string>
|
<string name="add_another_reminder">Füge eine weitere Erinnerung hinzu</string>
|
||||||
<string name="event_reminders">Ereignis Erinnerungen</string>
|
<string name="event_reminders">Ereignis Erinnerungen</string>
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
|
|
||||||
<!-- Event Reminders -->
|
<!-- Event Reminders -->
|
||||||
<string name="reminder">Reminder</string>
|
<string name="reminder">Reminder</string>
|
||||||
|
<string name="tomorrow">Tomorrow</string>
|
||||||
<string name="before">before</string>
|
<string name="before">before</string>
|
||||||
<string name="add_another_reminder">Add another reminder</string>
|
<string name="add_another_reminder">Add another reminder</string>
|
||||||
<string name="event_reminders">Event reminders</string>
|
<string name="event_reminders">Event reminders</string>
|
||||||
|
|
Loading…
Reference in New Issue