Revert "DevicePoseProvider: be picky about locations (#1344)"
This reverts commit 4bb092d98b.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package de.mm20.launcher2.ktx
|
||||
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
import kotlin.time.Duration.Companion.nanoseconds
|
||||
|
||||
import android.location.Location as AndroidLocation
|
||||
|
||||
/* https://github.com/streetcomplete/StreetComplete/blob/master/app/src/main/java/de/westnordost/streetcomplete/util/location/LocationUtils.kt
|
||||
* GPL-3.0-or-later
|
||||
*/
|
||||
fun AndroidLocation.isBetterThan(previous: AndroidLocation?): Boolean {
|
||||
if (longitude.isNaN() || latitude.isNaN()) return false
|
||||
if (previous == null) return true
|
||||
|
||||
val locationTimeDiff = elapsedRealtimeNanos.nanoseconds - previous.elapsedRealtimeNanos.nanoseconds
|
||||
val isMuchNewer = locationTimeDiff > 2.minutes
|
||||
val isMuchOlder = locationTimeDiff < (-2).minutes
|
||||
val isNewer = locationTimeDiff.isPositive()
|
||||
|
||||
val accuracyDelta = accuracy - previous.accuracy
|
||||
val isLessAccurate = accuracyDelta > 0f
|
||||
val isMoreAccurate = accuracyDelta < 0f
|
||||
val isMuchLessAccurate = accuracyDelta > 200f
|
||||
|
||||
val isFromSameProvider = provider == previous.provider
|
||||
|
||||
return when {
|
||||
// the user has likely moved
|
||||
isMuchNewer -> true
|
||||
// If the new location is more than two minutes older, it must be worse
|
||||
isMuchOlder -> false
|
||||
isMoreAccurate -> true
|
||||
isNewer && !isLessAccurate -> true
|
||||
isNewer && !isMuchLessAccurate && isFromSameProvider -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,5 @@
|
||||
package de.mm20.launcher2.ktx
|
||||
|
||||
fun Boolean.toInt(): Int {
|
||||
inline fun Boolean.toInt(): Int {
|
||||
return if (this) 1 else 0
|
||||
}
|
||||
|
||||
fun <T> Boolean.fold(
|
||||
whenTrue: () -> T,
|
||||
otherwise: () -> T
|
||||
): T = if (this) whenTrue() else otherwise()
|
||||
|
||||
fun <T> Boolean.foldOrNull(
|
||||
whenTrue: () -> T
|
||||
): T? = fold(whenTrue) { null }
|
||||
}
|
||||
Reference in New Issue
Block a user