fix #109, show a notification if the device is turned on during an event

This commit is contained in:
tibbi 2017-04-02 20:21:22 +02:00
parent 4b82b5e5f3
commit 4709322eae
3 changed files with 16 additions and 0 deletions

View File

@ -152,6 +152,12 @@ fun Context.getFilteredEvents(events: List<Event>): List<Event> {
return events.filter { displayEventTypes.contains(it.eventType.toString()) }
}
fun Context.notifyRunningEvents() {
dbHelper.getRunningEvents {
it.forEach { notifyEvent(it) }
}
}
fun Context.notifyEvent(event: Event) {
val pendingIntent = getPendingIntent(this, event)
val startTime = Formatter.getTimeFromTS(this, event.startTS)

View File

@ -390,6 +390,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return newEvents
}
fun getRunningEvents(callback: (events: ArrayList<Event>) -> Unit) {
val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ?"
val ts = (System.currentTimeMillis() / 1000).toString()
val selectionArgs = arrayOf(ts, ts)
val cursor = getEventsCursor(selection, selectionArgs)
callback(fillEvents(cursor) as ArrayList)
}
private fun getEvents(selection: String): List<Event> {
val events = ArrayList<Event>()
var cursor: Cursor? = null

View File

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.notifyRunningEvents
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
class BootCompletedReceiver : BroadcastReceiver() {
@ -13,5 +14,6 @@ class BootCompletedReceiver : BroadcastReceiver() {
for (event in events) {
context.scheduleNextEventReminder(event)
}
context.notifyRunningEvents()
}
}