Merge branch 'train-maps' into integration
This commit is contained in:
commit
10744bcd56
2 changed files with 1588 additions and 360 deletions
|
|
@ -110,6 +110,7 @@ class MainActivity : FlutterActivity() {
|
|||
"show" -> result.success(RecorderService.show(call.arguments as String).let { null })
|
||||
"isRecording" -> result.success(RecorderService.isRecording())
|
||||
"position" -> position(result)
|
||||
"lastPosition" -> result.success(lastPosition())
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
|
@ -280,6 +281,22 @@ class MainActivity : FlutterActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
/** Where the phone was last known to be by any provider, the newest; none without the
|
||||
* location permission, which this never asks for (ADR 0030, D63: a new route's map opens
|
||||
* there at once). */
|
||||
private fun lastPosition(): Map<String, Double>? {
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
|
||||
checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val manager = getSystemService(LocationManager::class.java)
|
||||
val newest = manager.getProviders(true)
|
||||
.mapNotNull { manager.getLastKnownLocation(it) }
|
||||
.maxByOrNull { it.time }
|
||||
return newest?.let { mapOf("lat" to it.latitude, "lon" to it.longitude) }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val RECORDER_REQUEST = 1
|
||||
const val FRESH_MS = 120_000L
|
||||
|
|
|
|||
Loading…
Reference in a new issue