1. UpdateCalendarService will fetch all events from now to the next fetch time + Preferences.showUntil, so that EventRepository holds all events need to be shown before the next fetch; 2. Every event is updated 1 minute after the corresponding time span, to make the actual time difference consistent with the displayed getRelativeTimeSpanString; 3. Update events only when necessary, eliminate redundant alarms; cancel all update alarms when showEvents is turned off.
29 lines
959 B
Kotlin
29 lines
959 B
Kotlin
package com.tommasoberlose.anotherwidget.receivers
|
|
|
|
import android.content.BroadcastReceiver
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.util.Log
|
|
import com.tommasoberlose.anotherwidget.db.EventRepository
|
|
import com.tommasoberlose.anotherwidget.global.Actions
|
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
|
|
|
class NewCalendarEventReceiver : BroadcastReceiver() {
|
|
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
val eventRepository = EventRepository(context)
|
|
when (intent.action) {
|
|
Intent.ACTION_PROVIDER_CHANGED -> {
|
|
CalendarHelper.updateEventList(context)
|
|
}
|
|
Actions.ACTION_GO_TO_NEXT_EVENT -> {
|
|
eventRepository.goToNextEvent()
|
|
}
|
|
Actions.ACTION_GO_TO_PREVIOUS_EVENT -> {
|
|
eventRepository.goToPreviousEvent()
|
|
}
|
|
}
|
|
eventRepository.close()
|
|
}
|
|
}
|