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

36 lines
1.4 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
2020-03-18 00:22:21 +01:00
import dagger.android.DaggerBroadcastReceiver
2020-03-16 21:40:29 +01:00
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
2020-03-18 00:22:21 +01:00
class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
2020-03-16 21:40:29 +01:00
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePluginProvider
override fun onReceive(context: Context, intent: Intent) {
2020-03-18 00:22:21 +01:00
super.onReceive(context, intent)
2020-03-16 21:40:29 +01:00
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)
}
}