Skip to content

Commit

Permalink
fix: Re-work strategy for force screen update
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jul 14, 2024
1 parent 1b9106b commit 746b363
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import org.obd.graphs.sendBroadcastEvent

const val VIRTUAL_SCREEN_1_SETTINGS_CHANGED = "pref.aa.pids.profile_1.event.changed"
const val VIRTUAL_SCREEN_2_SETTINGS_CHANGED = "pref.aa.pids.profile_2.event.changed"
const val VIRTUAL_SCREEN_3_SETTINGS_CHANGED = "pref.aa.pids.profile_3.event.changed"
const val VIRTUAL_SCREEN_3_SETTINGS_CHANGED
= "pref.aa.pids.profile_3.event.changed"
const val VIRTUAL_SCREEN_4_SETTINGS_CHANGED = "pref.aa.pids.profile_4.event.changed"
const val LOG_KEY = "CarScreen"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ internal class NavTemplateCarScreen(
try {
renderingThread.start()
fps.start()
invalidate()
//force refresh screen
sendBroadcastEvent(AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT)
sendBroadcastEvent(AA_REFRESH_EVENT)
navigationManager().navigationStarted()
toast.show(carContext, R.string.main_activity_toast_connection_established)
invalidate()

}catch (e: Exception){
Log.w(LOG_KEY,"Failed when received DATA_LOGGER_ERROR_CONNECT_EVENT event",e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import androidx.car.app.model.CarColor
import androidx.car.app.model.Template
import androidx.car.app.navigation.model.NavigationTemplate
import androidx.lifecycle.LifecycleOwner
import org.obd.graphs.AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT
import org.obd.graphs.AA_REFRESH_EVENT
import org.obd.graphs.AA_VIRTUAL_SCREEN_REFRESH_EVENT
import org.obd.graphs.AA_VIRTUAL_SCREEN_RENDERER_CHANGED_EVENT
import org.obd.graphs.AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT
import org.obd.graphs.aa.*
import org.obd.graphs.aa.screen.*
import org.obd.graphs.aa.screen.CarScreen
import org.obd.graphs.bl.collector.MetricsCollector
import org.obd.graphs.bl.datalogger.dataLogger
import org.obd.graphs.bl.datalogger.dataLoggerPreferences
Expand Down Expand Up @@ -46,6 +46,20 @@ internal class SurfaceScreen(
AA_VIRTUAL_SCREEN_RENDERER_CHANGED_EVENT -> surfaceController.allocateSurfaceRender()
AA_VIRTUAL_SCREEN_REFRESH_EVENT -> renderFrame()

AA_REFRESH_EVENT -> {
Log.i(LOG_KEY,"Received forced refresh screen event")

when (settings.getCurrentVirtualScreen()) {
VIRTUAL_SCREEN_1 -> settings.applyVirtualScreen1()
VIRTUAL_SCREEN_2 -> settings.applyVirtualScreen2()
VIRTUAL_SCREEN_3 -> settings.applyVirtualScreen3()
VIRTUAL_SCREEN_4 -> settings.applyVirtualScreen4()
}

applyMetricsFilter()
renderFrame()
}

AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT -> {
applyMetricsFilter()
renderFrame()
Expand Down Expand Up @@ -153,6 +167,7 @@ internal class SurfaceScreen(
addAction(PROFILE_RESET_EVENT)
addAction(AA_VIRTUAL_SCREEN_REFRESH_EVENT)
addAction(AA_VIRTUAL_SCREEN_RENDERER_CHANGED_EVENT)
addAction(AA_REFRESH_EVENT)
})
}

Expand All @@ -162,12 +177,13 @@ internal class SurfaceScreen(

private fun applyMetricsFilter() {
if (dataLoggerPreferences.instance.individualQueryStrategyEnabled) {
Log.i(LOG_KEY, "User selection PIDs=${settings.getSelectedPIDs()}")

metricsCollector.applyFilter(enabled = settings.getSelectedPIDs(), order = settings.getPIDsSortOrder())

query.setStrategy(QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW)
query.update(metricsCollector.getMetrics().map { p -> p.source.command.pid.id }.toSet())
Log.i(LOG_KEY, "User selection PIDs=${settings.getSelectedPIDs()}")

dataLogger.updateQuery(query)
} else {
query.setStrategy(QueryStrategyType.SHARED_QUERY)
Expand All @@ -189,7 +205,7 @@ internal class SurfaceScreen(
if (settings.isVirtualScreenEnabled(1)) {
added = true

builder = builder.addAction(createAction(carContext,R.drawable.action_virtual_screen_1, actionStripColor(VIRTUAL_SCREEN_1)) {
builder = builder.addAction(createAction(carContext, R.drawable.action_virtual_screen_1, actionStripColor(VIRTUAL_SCREEN_1)) {
parent.invalidate()
settings.applyVirtualScreen1()
applyMetricsFilter()
Expand All @@ -200,7 +216,7 @@ internal class SurfaceScreen(
if (settings.isVirtualScreenEnabled(2)) {

added = true
builder = builder.addAction(createAction(carContext,R.drawable.action_virtual_screen_2, actionStripColor(VIRTUAL_SCREEN_2)) {
builder = builder.addAction(createAction(carContext, R.drawable.action_virtual_screen_2, actionStripColor(VIRTUAL_SCREEN_2)) {
parent.invalidate()
settings.applyVirtualScreen2()
applyMetricsFilter()
Expand All @@ -211,7 +227,7 @@ internal class SurfaceScreen(
if (settings.isVirtualScreenEnabled(3)) {

added = true
builder = builder.addAction(createAction(carContext,R.drawable.action_virtual_screen_3, actionStripColor(VIRTUAL_SCREEN_3)) {
builder = builder.addAction(createAction(carContext, R.drawable.action_virtual_screen_3, actionStripColor(VIRTUAL_SCREEN_3)) {
parent.invalidate()
settings.applyVirtualScreen3()
applyMetricsFilter()
Expand All @@ -222,7 +238,7 @@ internal class SurfaceScreen(
if (settings.isVirtualScreenEnabled(4)) {
added = true

builder = builder.addAction(createAction(carContext,R.drawable.action_virtual_screen_4, actionStripColor(VIRTUAL_SCREEN_4)) {
builder = builder.addAction(createAction(carContext, R.drawable.action_virtual_screen_4, actionStripColor(VIRTUAL_SCREEN_4)) {
parent.invalidate()
settings.applyVirtualScreen4()
applyMetricsFilter()
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/org/obd/graphs/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const val AA_VIRTUAL_SCREEN_VISIBILITY_CHANGED_EVENT = "pref.aa.virtual_screens.
const val AA_VIRTUAL_SCREEN_RENDERER_CHANGED_EVENT = "pref.aa.screen_renderer.changed"
const val AA_VIRTUAL_SCREEN_REFRESH_EVENT = "pref.aa.screen_refresh.event"
const val AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT = "pref.pids.generic.high.event.changed"
const val AA_REFRESH_EVENT = "pref.pids.refresh.event"

const val PREF_DYNAMIC_SELECTOR_ENABLED = "pref.aa.theme.dynamic-selector.enabled"
const val PREF_MODULE_LIST = "pref.pids.registry.list"
Expand Down

0 comments on commit 746b363

Please sign in to comment.