Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add up to the allowed limit of list items to android auto #3687

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down