From d9f775a617bd03818afde0a45c420b6c84e79c55 Mon Sep 17 00:00:00 2001 From: Maximilian Goldschmidt Date: Tue, 30 Apr 2024 13:47:09 +0200 Subject: [PATCH] Applied connection status changes to Car App --- .../carStatsViewer/carApp/CarStatsTab.kt | 17 +++++----- .../carApp/CarStatsViewerScreen.kt | 4 +-- .../carStatsViewer/carApp/TripDataTab.kt | 33 ++++++++++++------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsTab.kt b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsTab.kt index bf7ffcdc..04358543 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsTab.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsTab.kt @@ -9,6 +9,7 @@ import androidx.car.app.model.Row import androidx.car.app.model.SectionedItemList import androidx.core.graphics.drawable.IconCompat import com.ixam97.carStatsViewer.R +import com.ixam97.carStatsViewer.liveDataApi.ConnectionStatus @OptIn(ExperimentalCarApi::class) internal fun CarStatsViewerScreen.CarStatsList() = ListTemplate.Builder().apply { @@ -25,18 +26,18 @@ internal fun CarStatsViewerScreen.CarStatsList() = ListTemplate.Builder().apply ItemList.Builder().apply { apiState.forEach { (apiName, status) -> - val apiIconColor = when (status) { - 0 -> colorDisconnected - 1 -> colorConnected - 2 -> colorLimited + val apiIconColor = when (ConnectionStatus.fromInt(status)) { + ConnectionStatus.UNUSED -> colorDisconnected + ConnectionStatus.CONNECTED -> colorConnected + ConnectionStatus.LIMITED -> colorLimited else -> colorError } addItem(Row.Builder().apply { setTitle(apiName) - addText(when (status) { - 0 -> "Disabled" - 1 -> "Connected" - 2 -> "Limited" + addText(when (ConnectionStatus.fromInt(status)) { + ConnectionStatus.UNUSED -> "Disabled" + ConnectionStatus.CONNECTED -> "Connected" + ConnectionStatus.LIMITED -> "Limited" else -> "Error" }) setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_connected)).setTint(apiIconColor).build()) diff --git a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt index 28271c59..7e4614a4 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt @@ -104,12 +104,12 @@ class CarStatsViewerScreen( override fun onPause(owner: LifecycleOwner) { super.onPause(owner) - carDataSurfaceCallback.pause() + // carDataSurfaceCallback.pause() } override fun onResume(owner: LifecycleOwner) { super.onResume(owner) - carDataSurfaceCallback.resume() + // carDataSurfaceCallback.resume() } override fun onGetTemplate(): Template { diff --git a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt index 80100727..4353ba77 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt @@ -13,6 +13,8 @@ import com.ixam97.carStatsViewer.CarStatsViewer import com.ixam97.carStatsViewer.R import com.ixam97.carStatsViewer.database.tripData.DrivingSession import com.ixam97.carStatsViewer.database.tripData.TripType +import com.ixam97.carStatsViewer.liveDataApi.ConnectionStatus +import com.ixam97.carStatsViewer.liveDataApi.LiveDataApi import com.ixam97.carStatsViewer.utils.StringFormatters import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -54,28 +56,35 @@ internal fun CarStatsViewerScreen.TripDataList(session: DrivingSession?) = ListT )) var statusString = "" - var index = 0 var apiIconColor = colorDisconnected - apiState.forEach { (apiName, status) -> - statusString += "$apiName: $status " - if (index == CarStatsViewer.appPreferences.mainViewConnectionApi) { + CarStatsViewer.liveDataApis.forEachIndexed { apiIndex, liveDataApi -> + if (liveDataApi.connectionStatus.status == 0) return@forEachIndexed + val name = liveDataApi.apiIdentifier + val status = liveDataApi.connectionStatus + val statusName = when (status) { + ConnectionStatus.UNUSED -> "Disabled" + ConnectionStatus.CONNECTED -> "Connected" + ConnectionStatus.LIMITED -> "Limited" + else -> "Error" + } + if (statusString.isNotEmpty()) statusString += "\n" + statusString += "$name: $statusName" + if (apiIndex == CarStatsViewer.appPreferences.mainViewConnectionApi) { apiIconColor = when (status) { - 0 -> colorDisconnected - 1 -> colorConnected - 2 -> colorLimited + ConnectionStatus.UNUSED -> colorDisconnected + ConnectionStatus.CONNECTED -> colorConnected + ConnectionStatus.LIMITED -> colorLimited else -> colorError } } - - index++ } if (statusString.isEmpty() || statusString == "") statusString = "No API available" addItem(createDataRow( statusString, - "Api Status", + null, R.drawable.ic_connected, apiIconColor )) @@ -129,8 +138,8 @@ internal fun CarStatsViewerScreen.TripDataList(session: DrivingSession?) = ListT }.build() @OptIn(ExperimentalCarApi::class) private -fun CarStatsViewerScreen.createDataRow(value: String, name: String, iconResId: Int, iconColor: CarColor = CarColor.DEFAULT) = Row.Builder().apply { +fun CarStatsViewerScreen.createDataRow(value: String, name: String? = null, iconResId: Int, iconColor: CarColor = CarColor.DEFAULT) = Row.Builder().apply { setTitle(value) setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, iconResId)).setTint(iconColor).build()) - addText(name) + name?.let{addText(it)} }.build() \ No newline at end of file