mirror of
https://github.com/home-assistant/android
synced 2024-07-23 03:14:14 +00:00
Only add up to the allowed limit of list items to android auto (#3687)
This commit is contained in:
parent
f4eb29cee3
commit
c02025e0f8
|
@ -5,6 +5,7 @@ import android.util.Log
|
|||
import androidx.annotation.RequiresApi
|
||||
import androidx.car.app.CarContext
|
||||
import androidx.car.app.Screen
|
||||
import androidx.car.app.constraints.ConstraintManager
|
||||
import androidx.car.app.model.Action
|
||||
import androidx.car.app.model.CarColor
|
||||
import androidx.car.app.model.CarIcon
|
||||
|
@ -58,8 +59,15 @@ class EntityGridVehicleScreen(
|
|||
}
|
||||
|
||||
override fun onGetTemplate(): Template {
|
||||
val manager = carContext.getCarService(ConstraintManager::class.java)
|
||||
val gridLimit = manager.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_GRID)
|
||||
|
||||
val listBuilder = ItemList.Builder()
|
||||
entities.forEach { entity ->
|
||||
entities.forEachIndexed { index, entity ->
|
||||
if (index >= gridLimit) {
|
||||
Log.i(TAG, "Grid limit ($gridLimit) reached, not adding more entities (${entities.size}) for $title ")
|
||||
return@forEachIndexed
|
||||
}
|
||||
val icon = entity.getIcon(carContext) ?: CommunityMaterial.Icon.cmd_cloud_question
|
||||
val gridItem =
|
||||
GridItem.Builder()
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.util.Log
|
|||
import androidx.annotation.RequiresApi
|
||||
import androidx.car.app.CarContext
|
||||
import androidx.car.app.Screen
|
||||
import androidx.car.app.constraints.ConstraintManager
|
||||
import androidx.car.app.model.Action
|
||||
import androidx.car.app.model.CarColor
|
||||
import androidx.car.app.model.CarIcon
|
||||
|
@ -73,6 +74,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()
|
||||
entities
|
||||
.map { // Null checks handled during collection
|
||||
|
@ -82,11 +85,15 @@ class MapVehicleScreen(
|
|||
Pair(it, listOf(lat, lon))
|
||||
}
|
||||
.sortedBy { it.first.friendlyName }
|
||||
.forEach { (entity, location) ->
|
||||
val icon = entity.getIcon(carContext) ?: CommunityMaterial.Icon.cmd_account
|
||||
.forEachIndexed { index, pair ->
|
||||
if (index >= listLimit) {
|
||||
Log.i(TAG, "List limit ($listLimit) 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()
|
||||
.setTitle(entity.friendlyName)
|
||||
.setTitle(pair.first.friendlyName)
|
||||
.setImage(
|
||||
CarIcon.Builder(
|
||||
IconicsDrawable(carContext, icon)
|
||||
|
@ -98,10 +105,10 @@ class MapVehicleScreen(
|
|||
.build()
|
||||
)
|
||||
.setOnClickListener {
|
||||
Log.i(TAG, "${entity.entityId} clicked")
|
||||
Log.i(TAG, "${pair.first.entityId} clicked")
|
||||
val intent = Intent(
|
||||
CarContext.ACTION_NAVIGATE,
|
||||
Uri.parse("geo:${location[0]},${location[1]}")
|
||||
Uri.parse("geo:${pair.second[0]},${pair.second[1]}")
|
||||
)
|
||||
carContext.startCarApp(intent)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue