AndroidAPS/wear/src/main/java/info/nightscout/androidaps/Aaps.kt

47 lines
1.9 KiB
Kotlin
Raw Normal View History

2021-12-10 15:27:09 +01:00
package info.nightscout.androidaps
import android.content.Intent
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import info.nightscout.androidaps.comm.DataHandlerWear
import info.nightscout.androidaps.comm.DataLayerListenerServiceWear
import info.nightscout.androidaps.comm.ExceptionHandlerWear
2022-02-09 11:13:38 +01:00
import info.nightscout.androidaps.di.DaggerWearComponent
import info.nightscout.androidaps.events.EventWearPreferenceChange
import info.nightscout.androidaps.plugins.bus.RxBus
2022-04-11 14:25:00 +02:00
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import javax.inject.Inject
2021-12-10 15:27:09 +01:00
class Aaps : DaggerApplication(), OnSharedPreferenceChangeListener {
2022-04-11 14:25:00 +02:00
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBus
@Inject lateinit var dataHandlerWear: DataHandlerWear // instantiate only
@Inject lateinit var exceptionHandlerWear: ExceptionHandlerWear
2022-04-11 14:25:00 +02:00
2021-12-10 15:27:09 +01:00
override fun onCreate() {
super.onCreate()
exceptionHandlerWear.register()
2022-04-11 14:25:00 +02:00
aapsLogger.debug(LTag.WEAR, "onCreate")
2021-12-10 15:27:09 +01:00
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this)
startService(Intent(this, DataLayerListenerServiceWear::class.java))
2021-12-10 15:27:09 +01:00
}
override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
2022-02-09 11:13:38 +01:00
DaggerWearComponent
2021-12-10 15:27:09 +01:00
.builder()
.application(this)
.build()
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
2022-07-13 14:51:56 +02:00
// We trigger update on Complications
LocalBroadcastManager.getInstance(this).sendBroadcast(Intent(DataLayerListenerServiceWear.INTENT_NEW_DATA))
rxBus.send(EventWearPreferenceChange(key))
2021-12-10 15:27:09 +01:00
}
2022-07-13 14:51:56 +02:00
}