From 6e243b4ee79ca7da8042ddb0a841c0133b8c5257 Mon Sep 17 00:00:00 2001 From: Maximilian Goldschmidt Date: Thu, 18 Apr 2024 13:32:33 +0200 Subject: [PATCH] Tweaking responsiveness on reset and trip change --- automotive/build.gradle | 4 ++-- .../carStatsViewer/carApp/CarStatsViewerScreen.kt | 12 +++++++++--- .../carApp/TripDataSettingsScreen.kt | 1 + .../ixam97/carStatsViewer/carApp/TripDataTab.kt | 14 ++++++++++++-- .../carStatsViewer/dataProcessor/DataProcessor.kt | 1 + 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/automotive/build.gradle b/automotive/build.gradle index 85ac0279..2290598c 100644 --- a/automotive/build.gradle +++ b/automotive/build.gradle @@ -10,8 +10,8 @@ android { defaultConfig { minSdkVersion 29 targetSdkVersion 34 - versionCode 209 - versionName "0.27.0.0004" + versionCode 211 + versionName "0.27.0.0006" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } 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 889a1265..e9f83ce7 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsViewerScreen.kt @@ -1,6 +1,8 @@ package com.ixam97.carStatsViewer.carApp import android.content.Intent +import android.os.Handler +import android.os.Looper import androidx.car.app.CarContext import androidx.car.app.Screen import androidx.car.app.annotations.ExperimentalCarApi @@ -66,7 +68,9 @@ class CarStatsViewerScreen(carContext: CarContext) : Screen(carContext) { lifecycle.addObserver(object : DefaultLifecycleObserver { override fun onResume(owner: LifecycleOwner) { super.onResume(owner) - invalidate() + Handler(Looper.getMainLooper()).post { + invalidate() + } } }) setupListeners() @@ -80,8 +84,10 @@ class CarStatsViewerScreen(carContext: CarContext) : Screen(carContext) { private fun externalInvalidate() { CoroutineScope(Dispatchers.IO).launch { dataUpdate = true - delay(100) - invalidate() + delay(250) + Handler(Looper.getMainLooper()).post { + invalidate() + } } } diff --git a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataSettingsScreen.kt b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataSettingsScreen.kt index 88ce040d..1a6877e9 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataSettingsScreen.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataSettingsScreen.kt @@ -56,6 +56,7 @@ class TripDataSettingsScreen(carContext: CarContext) : Screen(carContext) { private fun changeSelectedTrip(index: Int) { CarStatsViewer.dataProcessor.changeSelectedTrip(index + 1) CarStatsViewer.appPreferences.mainViewTrip = index + invalidate() screenManager.popToRoot() } private fun tripTypeRow(tripType: Int) = Row.Builder().apply { 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 9133954e..08b530ac 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataTab.kt @@ -1,5 +1,7 @@ package com.ixam97.carStatsViewer.carApp +import android.os.Handler +import android.os.Looper import androidx.annotation.OptIn import androidx.car.app.CarToast import androidx.car.app.annotations.ExperimentalCarApi @@ -262,7 +264,11 @@ internal fun CarStatsViewerScreen.TripDataList() = ListTemplate.Builder().apply setIcon(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_car_app_tune)).build()) setBackgroundColor(CarColor.createCustom(backgroundColor, backgroundColor)) setOnClickListener { - screenManager.push(TripDataSettingsScreen(carContext)) + screenManager.pushForResult(TripDataSettingsScreen(carContext)) { + Handler(Looper.getMainLooper()).post { + invalidate() + } + } } }.build()) @@ -272,7 +278,11 @@ internal fun CarStatsViewerScreen.TripDataList() = ListTemplate.Builder().apply setIcon(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_car_app_reset)).build()) setBackgroundColor(CarColor.createCustom(backgroundColor, backgroundColor)) setOnClickListener { - screenManager.push(ConfirmResetScreen(carContext)) + screenManager.pushForResult(ConfirmResetScreen(carContext)) { + Handler(Looper.getMainLooper()).post { + invalidate() + } + } } }.build()) } diff --git a/automotive/src/main/java/com/ixam97/carStatsViewer/dataProcessor/DataProcessor.kt b/automotive/src/main/java/com/ixam97/carStatsViewer/dataProcessor/DataProcessor.kt index 0f10f64a..710e1b23 100644 --- a/automotive/src/main/java/com/ixam97/carStatsViewer/dataProcessor/DataProcessor.kt +++ b/automotive/src/main/java/com/ixam97/carStatsViewer/dataProcessor/DataProcessor.kt @@ -719,6 +719,7 @@ class DataProcessor { timerMap[tripType]?.reset() loadSessionsToMemory().join() if (drivingState == DrivingState.DRIVE) timerMap[tripType]?.start() + aaosExec?.execute(aaosRunnable) } private fun startChargingSession(): Job {