From 41b99fd079766e87ae7266825cf349bae0603179 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Apr 2026 03:34:43 +0000 Subject: [PATCH] fix(auto): fix ConnectionState data object usage and add list item limits Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Android/sessions/d1af27de-bc74-4b77-bdb8-7ae8167ab336 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> --- .../meshtastic/app/auto/MeshtasticCarScreen.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/org/meshtastic/app/auto/MeshtasticCarScreen.kt b/app/src/main/kotlin/org/meshtastic/app/auto/MeshtasticCarScreen.kt index eb172c674..7096cd0c2 100644 --- a/app/src/main/kotlin/org/meshtastic/app/auto/MeshtasticCarScreen.kt +++ b/app/src/main/kotlin/org/meshtastic/app/auto/MeshtasticCarScreen.kt @@ -67,7 +67,7 @@ class MeshtasticCarScreen(carContext: CarContext) : private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob()) private var observeJob: Job? = null - private var connectionState: ConnectionState = ConnectionState.Disconnected() + private var connectionState: ConnectionState = ConnectionState.Disconnected private var favoriteNodes: List = emptyList() private var channels: List = emptyList() private var unreadCounts: Map = emptyMap() @@ -195,10 +195,10 @@ class MeshtasticCarScreen(carContext: CarContext) : private fun buildFavoritesSection(): ItemList { val builder = ItemList.Builder() - for (node in favoriteNodes) { + for (node in favoriteNodes.take(MAX_LIST_ITEMS)) { val contactKey = "0${node.user.id}" val unread = unreadCounts[contactKey] ?: 0 - val name = node.user.long_name.ifEmpty { node.user.short_name } + val name = node.user.long_name.ifEmpty { node.user.short_name }.ifEmpty { "Unknown" } val subtitle = buildString { append(node.user.short_name) if (node.hopsAway >= 0) append(" ยท ${node.hopsAway} hops") @@ -220,7 +220,7 @@ class MeshtasticCarScreen(carContext: CarContext) : private fun buildChannelsSection(): ItemList { val builder = ItemList.Builder() - for ((index, channelSettings) in channels.withIndex()) { + for ((index, channelSettings) in channels.take(MAX_LIST_ITEMS).withIndex()) { val contactKey = "${index}${DataPacket.ID_BROADCAST}" val unread = unreadCounts[contactKey] ?: 0 val channelName = channelSettings.name.ifEmpty { "Primary Channel" } @@ -237,4 +237,13 @@ class MeshtasticCarScreen(carContext: CarContext) : return builder.build() } + + companion object { + /** + * Android Auto enforces a maximum item count per [ListTemplate] section. + * Car API level 1 supports up to 6 items per section. + */ + private const val MAX_LIST_ITEMS = 6 + } } +