AndroidAPS/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.kt

34 lines
1.3 KiB
Kotlin
Raw Normal View History

2020-03-16 21:40:29 +01:00
package info.nightscout.androidaps.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.PumpInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import javax.inject.Inject
class TimeDateOrTZChangeReceiver : BroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePluginProvider
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
val activePump: PumpInterface = activePlugin.getActivePump()
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
if (action != null) {
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
activePump.timeDateOrTimeZoneChanged()
}
}
fun registerBroadcasts(context: Context) {
val filter = IntentFilter()
filter.addAction(Intent.ACTION_TIME_CHANGED)
filter.addAction(Intent.ACTION_DATE_CHANGED)
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED)
context.registerReceiver(this, filter)
}
}