diff --git a/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/ManageAndroidAutoViewModel.kt b/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/ManageAndroidAutoViewModel.kt index e29be695397..30e80de6927 100755 --- a/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/ManageAndroidAutoViewModel.kt +++ b/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/ManageAndroidAutoViewModel.kt @@ -45,7 +45,14 @@ class ManageAndroidAutoViewModel @Inject constructor( async { entities[it.id] = try { serverManager.integrationRepository(it.id).getEntities().orEmpty() - .filter { it.domain in MainVehicleScreen.SUPPORTED_DOMAINS } + .filter { + it.domain in MainVehicleScreen.SUPPORTED_DOMAINS || + ( + it.domain in MainVehicleScreen.MAP_DOMAINS && + ((it.attributes as? Map<*, *>)?.get("latitude") as? Double != null) && + ((it.attributes as? Map<*, *>)?.get("longitude") as? Double != null) + ) + } } catch (e: Exception) { Log.e(TAG, "Couldn't load entities for server", e) emptyList() diff --git a/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/views/AndroidAutoFavoritesView.kt b/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/views/AndroidAutoFavoritesView.kt index aa917609f68..a2b430d434e 100755 --- a/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/views/AndroidAutoFavoritesView.kt +++ b/app/src/main/java/io/homeassistant/companion/android/settings/vehicle/views/AndroidAutoFavoritesView.kt @@ -55,7 +55,14 @@ fun AndroidAutoFavoritesSettings( androidAutoViewModel.sortedEntities .filter { !favoriteEntities.contains("$selectedServer-${it.entityId}") && - (it.domain in MainVehicleScreen.SUPPORTED_DOMAINS) + ( + it.domain in MainVehicleScreen.SUPPORTED_DOMAINS || + ( + it.domain in MainVehicleScreen.MAP_DOMAINS && + ((it.attributes as? Map<*, *>)?.get("latitude") as? Double != null) && + ((it.attributes as? Map<*, *>)?.get("longitude") as? Double != null) + ) + ) } .toList() } diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt index 2aef7ce83f8..0cd8da088de 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt @@ -1,5 +1,7 @@ package io.homeassistant.companion.android.vehicle +import android.content.Intent +import android.net.Uri import android.os.Build import android.util.Log import androidx.annotation.RequiresApi @@ -23,6 +25,7 @@ import com.mikepenz.iconics.utils.toAndroidIconCompat import io.homeassistant.companion.android.common.R import io.homeassistant.companion.android.common.data.integration.Entity import io.homeassistant.companion.android.common.data.integration.IntegrationRepository +import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName import io.homeassistant.companion.android.common.data.integration.friendlyState import io.homeassistant.companion.android.common.data.integration.getIcon @@ -160,8 +163,23 @@ class EntityGridVehicleScreen( gridItem .setOnClickListener { Log.i(TAG, "${entity.entityId} clicked") - lifecycleScope.launch { - entity.onPressed(integrationRepository) + if (entity.domain in MainVehicleScreen.MAP_DOMAINS) { + val attrs = entity.attributes as? Map<*, *> + if (attrs != null) { + val lat = attrs["latitude"] as? Double + val lon = attrs["longitude"] as? Double + if (lat != null && lon != null) { + val intent = Intent( + CarContext.ACTION_NAVIGATE, + Uri.parse("geo:$lat,$lon") + ) + carContext.startCarApp(intent) + } + } + } else { + lifecycleScope.launch { + entity.onPressed(integrationRepository) + } } } .setImage( diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt index 83bc3ce80cf..7b0a0731fd9 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt @@ -11,9 +11,9 @@ import androidx.car.app.constraints.ConstraintManager import androidx.car.app.model.Action import androidx.car.app.model.CarColor import androidx.car.app.model.CarIcon +import androidx.car.app.model.GridItem +import androidx.car.app.model.GridTemplate import androidx.car.app.model.ItemList -import androidx.car.app.model.ListTemplate -import androidx.car.app.model.Row import androidx.car.app.model.Template import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -27,6 +27,7 @@ import io.homeassistant.companion.android.common.data.integration.Entity import io.homeassistant.companion.android.common.data.integration.IntegrationRepository import io.homeassistant.companion.android.common.data.integration.domain import io.homeassistant.companion.android.common.data.integration.friendlyName +import io.homeassistant.companion.android.common.data.integration.friendlyState import io.homeassistant.companion.android.common.data.integration.getIcon import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch @@ -36,14 +37,14 @@ import io.homeassistant.companion.android.common.R as commonR class MapVehicleScreen( carContext: CarContext, val integrationRepository: IntegrationRepository, - val entitiesFlow: Flow>> + private val entitiesFlow: Flow>> ) : Screen(carContext) { companion object { private const val TAG = "MapVehicleScreen" } - var loading = true + private var loading = true var entities: Set> = setOf() init { @@ -75,8 +76,8 @@ class MapVehicleScreen( override fun onGetTemplate(): Template { val manager = carContext.getCarService(ConstraintManager::class.java) - val listLimit = manager.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_LIST) - val listBuilder = ItemList.Builder() + val gridLimit = manager.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_GRID) + val gridBuilder = ItemList.Builder() entities .map { // Null checks handled during collection val attrs = it.attributes as Map<*, *> @@ -86,19 +87,20 @@ class MapVehicleScreen( } .sortedBy { it.first.friendlyName } .forEachIndexed { index, pair -> - if (index >= listLimit) { - Log.i(TAG, "List limit ($listLimit) reached, not adding any more navigation entities (${entities.size})") + if (index >= gridLimit) { + Log.i(TAG, "Grid limit ($gridLimit) reached, not adding any more navigation entities (${entities.size})") return@forEachIndexed } val icon = pair.first.getIcon(carContext) ?: CommunityMaterial.Icon.cmd_account - listBuilder.addItem( - Row.Builder() + gridBuilder.addItem( + GridItem.Builder() .setTitle(pair.first.friendlyName) + .setText(pair.first.friendlyState(carContext)) .setImage( CarIcon.Builder( IconicsDrawable(carContext, icon) .apply { - sizeDp = 48 + sizeDp = 64 }.toAndroidIconCompat() ) .setTint(CarColor.DEFAULT) @@ -116,15 +118,15 @@ class MapVehicleScreen( ) } - return ListTemplate.Builder().apply { + return GridTemplate.Builder().apply { setTitle(carContext.getString(R.string.aa_navigation)) setHeaderAction(Action.BACK) if (loading) { setLoading(true) } else { setLoading(false) - listBuilder.setNoItemsMessage(carContext.getString(commonR.string.aa_no_entities_with_locations)) - setSingleList(listBuilder.build()) + gridBuilder.setNoItemsMessage(carContext.getString(commonR.string.aa_no_entities_with_locations)) + setSingleList(gridBuilder.build()) } }.build() }