use common data container
This commit is contained in:
parent
044c509027
commit
e0c8f9dc26
|
@ -128,9 +128,9 @@ public class MainApp extends DaggerApplication {
|
|||
public static boolean devBranch;
|
||||
public static boolean engineeringMode;
|
||||
|
||||
private String CHANNEL_ID = "AndroidAPS-Ongoing";
|
||||
private int ONGOING_NOTIFICATION_ID = 4711;
|
||||
private Notification notification;
|
||||
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject ActivityMonitor activityMonitor;
|
||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.general.automation.events.EventTrigger
|
|||
import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerRemove
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.services.LastLocationDataContainer
|
||||
import info.nightscout.androidaps.services.LocationService
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -34,7 +35,7 @@ abstract class Trigger(val mainApp: MainApp) {
|
|||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var locationService: LocationService
|
||||
@Inject lateinit var locationDataContainer: LastLocationDataContainer
|
||||
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
|
|
@ -20,10 +20,9 @@ class TriggerLocation(mainApp: MainApp) : Trigger(mainApp) {
|
|||
|
||||
var lastMode = InputLocationMode.Mode.INSIDE
|
||||
private val buttonAction = Runnable {
|
||||
val location = locationService.lastLocation
|
||||
if (location != null) {
|
||||
latitude.value = location.latitude
|
||||
longitude.value = location.longitude
|
||||
locationDataContainer.lastLocation?.let {
|
||||
latitude.value = it.latitude
|
||||
longitude.value = it.longitude
|
||||
aapsLogger.debug(LTag.AUTOMATION, String.format("Grabbed location: %f %f", latitude.value, longitude.value))
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +38,7 @@ class TriggerLocation(mainApp: MainApp) : Trigger(mainApp) {
|
|||
}
|
||||
|
||||
@Synchronized override fun shouldRun(): Boolean {
|
||||
val location: Location = locationService.lastLocation ?: return false
|
||||
val location: Location = locationDataContainer.lastLocation ?: return false
|
||||
val a = Location("Trigger")
|
||||
a.latitude = latitude.value
|
||||
a.longitude = longitude.value
|
||||
|
@ -98,7 +97,7 @@ class TriggerLocation(mainApp: MainApp) : Trigger(mainApp) {
|
|||
.add(LabelWithElement(mainApp, resourceHelper.gs(R.string.longitude_short), "", longitude))
|
||||
.add(LabelWithElement(mainApp, resourceHelper.gs(R.string.distance_short), "", distance))
|
||||
.add(LabelWithElement(mainApp, resourceHelper.gs(R.string.location_mode), "", modeSelected))
|
||||
.add(InputButton(mainApp, resourceHelper.gs(R.string.currentlocation), buttonAction), locationService.lastLocation != null)
|
||||
.add(InputButton(mainApp, resourceHelper.gs(R.string.currentlocation), buttonAction), locationDataContainer.lastLocation != null)
|
||||
.build(root)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package info.nightscout.androidaps.services
|
||||
|
||||
import android.location.Location
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by adrian on 2020-01-06.
|
||||
*/
|
||||
|
||||
@Singleton
|
||||
class LastLocationDataContainer @Inject constructor() {
|
||||
var lastLocation: Location? = null
|
||||
}
|
|
@ -26,12 +26,14 @@ import io.reactivex.disposables.CompositeDisposable
|
|||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
class LocationService @Inject constructor(): DaggerService() {
|
||||
class LocationService : DaggerService() {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var mainApp: MainApp
|
||||
@Inject lateinit var lastLocationDataContainer: LastLocationDataContainer
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
private var locationManager: LocationManager? = null
|
||||
|
@ -40,8 +42,6 @@ class LocationService @Inject constructor(): DaggerService() {
|
|||
private val LOCATION_INTERVAL_ACTIVE = T.mins(5).msecs()
|
||||
private val LOCATION_INTERVAL_PASSIVE = T.mins(1).msecs() // this doesn't cost more power
|
||||
|
||||
var lastLocation: Location? = null
|
||||
|
||||
companion object {
|
||||
private const val LOCATION_DISTANCE = 10f
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class LocationService @Inject constructor(): DaggerService() {
|
|||
|
||||
override fun onLocationChanged(location: Location) {
|
||||
aapsLogger.debug(LTag.LOCATION, "onLocationChanged: $location")
|
||||
lastLocation = location
|
||||
lastLocationDataContainer.lastLocation = location
|
||||
rxBus.send(EventLocationChange(location))
|
||||
}
|
||||
|
||||
|
@ -73,17 +73,17 @@ class LocationService @Inject constructor(): DaggerService() {
|
|||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
startForeground(mainApp.notificationId(), mainApp.getNotification())
|
||||
startForeground(mainApp.notificationId(), mainApp.notification)
|
||||
return Service.START_STICKY
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startForeground(mainApp.notificationId(), mainApp.getNotification())
|
||||
startForeground(mainApp.notificationId(), mainApp.notification)
|
||||
|
||||
// Get last location once until we get regular update
|
||||
LocationServices.getFusedLocationProviderClient(this).lastLocation.addOnSuccessListener {
|
||||
lastLocation = it
|
||||
lastLocationDataContainer.lastLocation = it
|
||||
}
|
||||
|
||||
initializeLocationManager()
|
||||
|
|
Loading…
Reference in a new issue