fix #109, show a notification if the device is turned on during an event
This commit is contained in:
parent
4b82b5e5f3
commit
4709322eae
|
@ -152,6 +152,12 @@ fun Context.getFilteredEvents(events: List<Event>): List<Event> {
|
||||||
return events.filter { displayEventTypes.contains(it.eventType.toString()) }
|
return events.filter { displayEventTypes.contains(it.eventType.toString()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.notifyRunningEvents() {
|
||||||
|
dbHelper.getRunningEvents {
|
||||||
|
it.forEach { notifyEvent(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.notifyEvent(event: Event) {
|
fun Context.notifyEvent(event: Event) {
|
||||||
val pendingIntent = getPendingIntent(this, event)
|
val pendingIntent = getPendingIntent(this, event)
|
||||||
val startTime = Formatter.getTimeFromTS(this, event.startTS)
|
val startTime = Formatter.getTimeFromTS(this, event.startTS)
|
||||||
|
|
|
@ -390,6 +390,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
return newEvents
|
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> {
|
private fun getEvents(selection: String): List<Event> {
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
|
import com.simplemobiletools.calendar.extensions.notifyRunningEvents
|
||||||
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
|
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
|
||||||
|
|
||||||
class BootCompletedReceiver : BroadcastReceiver() {
|
class BootCompletedReceiver : BroadcastReceiver() {
|
||||||
|
@ -13,5 +14,6 @@ class BootCompletedReceiver : BroadcastReceiver() {
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
context.scheduleNextEventReminder(event)
|
context.scheduleNextEventReminder(event)
|
||||||
}
|
}
|
||||||
|
context.notifyRunningEvents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue