Android Auto location fixes

This commit is contained in:
Johan von Forstner
2022-09-27 23:04:43 +02:00
parent c1ec46917e
commit 49c2fb3494
2 changed files with 21 additions and 14 deletions

View File

@@ -108,8 +108,6 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
}
override fun onGetTemplate(): Template {
session.requestLocationUpdates()
session.mapScreen = this
return PlaceListMapTemplate.Builder().apply {
setTitle(
@@ -123,17 +121,23 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
}
)
)
searchLocation?.let {
setAnchor(Place.Builder(CarLocation.create(it.latitude, it.longitude)).apply {
if (prefs.placeSearchResultAndroidAutoName != null) {
setMarker(
PlaceMarker.Builder()
.setColor(CarColor.PRIMARY)
.build()
)
}
}.build())
} ?: setLoading(true)
if (prefs.placeSearchResultAndroidAutoName != null) {
searchLocation?.let {
setAnchor(Place.Builder(CarLocation.create(it.latitude, it.longitude)).apply {
if (prefs.placeSearchResultAndroidAutoName != null) {
setMarker(
PlaceMarker.Builder()
.setColor(CarColor.PRIMARY)
.build()
)
}
}.build())
} ?: setLoading(true)
} else {
location?.let {
setAnchor(Place.Builder(CarLocation.create(it.latitude, it.longitude)).build())
} ?: setLoading(true)
}
chargers?.take(maxRows)?.let { chargerList ->
val builder = ItemList.Builder()
// only show the city if not all chargers are in the same city
@@ -421,6 +425,7 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
override fun onStart(owner: LifecycleOwner) {
setupListeners()
session.requestLocationUpdates()
// Reloading chargers in onStart does not seem to count towards content limit.
// So let's do this so the user gets fresh chargers when re-entering the app.

View File

@@ -26,7 +26,9 @@ abstract class LocationEngine(protected val context: Context) {
*/
@RequiresPermission(anyOf = [Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION])
fun requestLocationUpdates(priority: Priority, intervalMs: Long, listener: LocationListener) {
requests.add(LocationRequest(priority, intervalMs, listener))
if (!requests.any { it.listener == listener }) {
requests.add(LocationRequest(priority, intervalMs, listener))
}
enable()
}