summaryrefslogtreecommitdiff
path: root/mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt
diff options
context:
space:
mode:
Diffstat (limited to 'mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt')
-rw-r--r--mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt37
1 files changed, 37 insertions, 0 deletions
diff --git a/mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt b/mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt
new file mode 100644
index 0000000000..8b56fff3f6
--- /dev/null
+++ b/mapbox/src/main/java/com/example/mapbox/livedata/MapViewSensors.kt
@@ -0,0 +1,37 @@
+package com.soy.android.maps.livedata
+
+import android.location.Location
+import androidx.lifecycle.Observer
+import com.example.mapbox.livedata.HeadingSensorLiveData
+import com.example.mapbox.livedata.LocationWithHeadingLiveData
+import javax.inject.Inject
+
+class MapViewSensors
+@Inject constructor(
+ val locationLiveData: LocationWithHeadingLiveData,
+ val headingLiveData: HeadingSensorLiveData
+) {
+ fun requestUpdates(
+ locationObserver: Observer<Location>? = null,
+ headingObserver: Observer<Float>? = null
+ ) {
+ locationObserver?.let {
+ locationLiveData.observeForever(it)
+ }
+ headingObserver?.let {
+ headingLiveData.observeForever(it)
+ }
+ }
+
+ fun removeUpdates(
+ locationObserver: Observer<Location>? = null,
+ headingObserver: Observer<Float>? = null
+ ) {
+ locationObserver?.let {
+ locationLiveData.removeObserver(it)
+ }
+ headingObserver?.let {
+ headingLiveData.removeObserver(it)
+ }
+ }
+}