@@ -7,6 +7,7 @@ import android.location.LocationManager
7
7
import android.os.Handler
8
8
import android.os.Looper
9
9
import androidx.core.content.getSystemService
10
+ import androidx.core.location.LocationCompat
10
11
import com.kylecorry.andromeda.core.sensors.AbstractSensor
11
12
import com.kylecorry.andromeda.core.sensors.Quality
12
13
import com.kylecorry.andromeda.core.tryOrDefault
@@ -111,12 +112,12 @@ class GPS(
111
112
112
113
// Can only get NMEA with fine location permission
113
114
if (Permissions .canGetFineLocation(context)) {
114
- if (android.os. Build . VERSION . SDK_INT >= android.os. Build . VERSION_CODES . N ) {
115
- nmeaListener?. let {
116
- locationManager?.addNmeaListener(it, Handler ( Looper .getMainLooper()))
117
- }
118
- } else {
119
- tryOrNothing {
115
+ tryOrNothing {
116
+ if (android.os. Build . VERSION . SDK_INT >= android.os. Build . VERSION_CODES . N ) {
117
+ nmeaListener?. let {
118
+ locationManager?.addNmeaListener(it, Handler ( Looper .getMainLooper()))
119
+ }
120
+ } else {
120
121
@Suppress(" DEPRECATION" )
121
122
locationManager?.addNmeaListener(legacyNmeaListener)
122
123
}
@@ -150,7 +151,8 @@ class GPS(
150
151
_location = Coordinate (location.latitude, location.longitude)
151
152
_time = Instant .ofEpochMilli(location.time)
152
153
_satellites =
153
- if (location.extras?.containsKey(" satellites" ) == true ) (location.extras?.getInt(" satellites" ) ? : 0 ) else 0
154
+ if (location.extras?.containsKey(" satellites" ) == true ) (location.extras?.getInt(" satellites" )
155
+ ? : 0 ) else 0
154
156
_altitude = if (location.hasAltitude()) location.altitude.toFloat() else 0f
155
157
val accuracy = if (location.hasAccuracy()) location.accuracy else null
156
158
_quality = when {
@@ -160,20 +162,17 @@ class GPS(
160
162
else -> Quality .Unknown
161
163
}
162
164
_horizontalAccuracy = accuracy ? : 0f
163
- _verticalAccuracy =
164
- if (android.os.Build .VERSION .SDK_INT >= android.os.Build .VERSION_CODES .O && location.hasVerticalAccuracy()) {
165
- location.verticalAccuracyMeters
166
- } else {
167
- null
168
- }
165
+ _verticalAccuracy = if (LocationCompat .hasVerticalAccuracy(location)) {
166
+ LocationCompat .getVerticalAccuracyMeters(location)
167
+ } else {
168
+ null
169
+ }
169
170
// TODO: Add speed accuracy to IGPS
170
171
_speed = if (location.hasSpeed()) {
171
- if (android.os.Build .VERSION .SDK_INT >= android.os.Build .VERSION_CODES .O && location.hasSpeedAccuracy()) {
172
- if (location.speed < location.speedAccuracyMetersPerSecond * 0.68 ) {
173
- 0f
174
- } else {
175
- location.speed
176
- }
172
+ if (LocationCompat .hasSpeedAccuracy(location) &&
173
+ location.speed < LocationCompat .getSpeedAccuracyMetersPerSecond(location) * 0.68
174
+ ) {
175
+ 0f
177
176
} else {
178
177
location.speed
179
178
}
0 commit comments