Merge branch 'train-maps' into integration

This commit is contained in:
Tizian 「ティツィアーン」 2026-11-03 23:13:32 +01:00
commit 10744bcd56
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
2 changed files with 1588 additions and 360 deletions

View file

@ -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