From 3a2459a537b4cb544e644cf64bab53d48f5d044d Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Sun, 15 Sep 2024 19:47:39 +0200 Subject: [PATCH] feat:TripInfo: Conditionall displaying PIDs on the dashboard --- app/build.gradle | 4 +- app/src/main/assets/alfa_2_0_gme.properties | 3 +- .../assets/alfa_2_0_gme_stn_usb.properties | 3 +- .../assets/alfa_2_0_gme_stn_wifi.properties | 3 +- .../org/obd/graphs/activity/MainActivity.kt | 2 - .../graphs/preferences/PreferencesFragment.kt | 17 ++++- .../preferences/pid/ModulesListPreferences.kt | 2 +- .../pid/PIDsListPreferenceDialogFragment.kt | 72 +++++++++++-------- .../preferences/pid/PIDsListPreferences.kt | 2 +- app/src/main/res/xml/preferences.xml | 18 +++++ .../main/assets/alfa_2_0_gme_aa.properties | 3 +- .../assets/alfa_2_0_gme_aa_gg_stn.properties | 3 +- .../assets/alfa_2_0_gme_aa_stn.properties | 3 +- .../assets/alfa_2_0_gme_aa_stn_gpf.properties | 3 +- .../aa/screen/nav/SurfaceRendererScreen.kt | 6 ++ .../src/main/java/org/obd/graphs/Constants.kt | 1 + .../org/obd/graphs/preferences/Preferences.kt | 4 +- .../collector/InMemoryCarMetricsCollector.kt | 8 ++- .../graphs/bl/collector/MetricsCollector.kt | 2 +- .../java/org/obd/graphs/bl/query/Query.kt | 1 + .../org/obd/graphs/bl/query/QueryStrategy.kt | 2 + .../bl/query/QueryStrategyOrchestrator.kt | 3 + .../graphs/bl/query/TripInfoQueryStrategy.kt | 51 +++++++------ .../assets/giulia_2_2_multijet.properties | 1 + ext/src/main/assets/qiulia_qv.properties | 1 + .../java/org/obd/graphs/profile/Profile.kt | 3 +- .../profile/ProfilePreferencesBackend.kt | 3 +- .../graphs/renderer/trip/TripInfoDrawer.kt | 59 +++++++++------ .../renderer/trip/TripInfoSurfaceRenderer.kt | 7 +- 29 files changed, 194 insertions(+), 96 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5feebe12..2c3a2eed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,7 +58,7 @@ android { dimension "version" resValue "string", "DEFAULT_PROFILE", "profile_8" applicationId "org.obd.graphs.my.giulia.aa" - versionCode 138 + versionCode 140 } giuliaPerformanceMonitor { @@ -72,7 +72,7 @@ android { dimension "version" resValue "string", "DEFAULT_PROFILE", "profile_3" applicationId "org.obd.graphs.my.giulia" - versionCode 59 + versionCode 60 } } diff --git a/app/src/main/assets/alfa_2_0_gme.properties b/app/src/main/assets/alfa_2_0_gme.properties index 0f6c95c6..f152b743 100644 --- a/app/src/main/assets/alfa_2_0_gme.properties +++ b/app/src/main/assets/alfa_2_0_gme.properties @@ -119,4 +119,5 @@ profile_3.pref.giulia.pids.selected.8=[7015, 7014, 7027] profile_3.pref.adapter.batch.size="3" profile_3.pref.adapter.batch_01.size="3" -profile_3.pref.profile.2_0_GME_extension.enabled=true \ No newline at end of file +profile_3.pref.profile.2_0_GME_extension.enabled=true +profile_3.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/app/src/main/assets/alfa_2_0_gme_stn_usb.properties b/app/src/main/assets/alfa_2_0_gme_stn_usb.properties index 606deac4..3d83134f 100644 --- a/app/src/main/assets/alfa_2_0_gme_stn_usb.properties +++ b/app/src/main/assets/alfa_2_0_gme_stn_usb.properties @@ -113,4 +113,5 @@ profile_6.pref.giulia.pids.selected.8=[7015, 7014, 7027] profile_6.pref.adapter.batch.size="10" profile_6.pref.adapter.batch_01.size="3" -profile_6.pref.profile.2_0_GME_extension.enabled=true \ No newline at end of file +profile_6.pref.profile.2_0_GME_extension.enabled=true +profile_6.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/app/src/main/assets/alfa_2_0_gme_stn_wifi.properties b/app/src/main/assets/alfa_2_0_gme_stn_wifi.properties index 4151902d..b8044156 100644 --- a/app/src/main/assets/alfa_2_0_gme_stn_wifi.properties +++ b/app/src/main/assets/alfa_2_0_gme_stn_wifi.properties @@ -124,4 +124,5 @@ profile_4.pref.adapter.batch.size="10" profile_4.pref.adapter.batch_01.size="3" -profile_4.pref.profile.2_0_GME_extension.enabled=true \ No newline at end of file +profile_4.pref.profile.2_0_GME_extension.enabled=true +profile_4.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/app/src/main/java/org/obd/graphs/activity/MainActivity.kt b/app/src/main/java/org/obd/graphs/activity/MainActivity.kt index b298fee2..ca8f06dd 100644 --- a/app/src/main/java/org/obd/graphs/activity/MainActivity.kt +++ b/app/src/main/java/org/obd/graphs/activity/MainActivity.kt @@ -45,7 +45,6 @@ import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.bl.drag.dragRacingMetricsProcessor import org.obd.graphs.bl.generator.MetricsGenerator import org.obd.graphs.bl.trip.tripManager -import org.obd.graphs.preferences.* import org.obd.graphs.profile.profile import pub.devrel.easypermissions.AppSettingsDialog import pub.devrel.easypermissions.EasyPermissions @@ -221,7 +220,6 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { versionName = BuildConfig.VERSION_NAME ) - Prefs.registerOnSharedPreferenceChangeListener(profile) profile.setupProfiles(forceOverrideRecommendation = false) } diff --git a/app/src/main/java/org/obd/graphs/preferences/PreferencesFragment.kt b/app/src/main/java/org/obd/graphs/preferences/PreferencesFragment.kt index f8c30bc7..d733da9a 100644 --- a/app/src/main/java/org/obd/graphs/preferences/PreferencesFragment.kt +++ b/app/src/main/java/org/obd/graphs/preferences/PreferencesFragment.kt @@ -47,6 +47,7 @@ const val PREFERENCE_SCREEN_KEY = "preferences.rootKey" const val PREFS_CONNECTION_TYPE_CHANGED_EVENT = "prefs.connection_type.changed.event" const val PREF_GAUGE_RECORDINGS = "pref.gauge.recordings" +const val PREF_TRIP_INFO_DISPLAYED_PARAMETERS_IDS = "pref.trip_info.displayed_parameter_ids" const val PREF_DASH_DISPLAYED_PARAMETERS_IDS = "pref.dash.displayed_parameter_ids" const val PREF_GAUGE_DISPLAYED_PARAMETERS_IDS = "pref.gauge.displayed_parameter_ids" const val PREF_GRAPH_DISPLAYED_PARAMETERS_IDS = "pref.graph.displayed_parameter_ids" @@ -64,14 +65,17 @@ class PreferencesFragment : PreferenceFragmentCompat() { override fun onDisplayPreferenceDialog(preference: Preference) { when (preference) { + is TripsListPreferences -> { TripsPreferenceDialogFragment().show(parentFragmentManager, null) } + is VehicleMetadataListPreferences -> { VehicleMetadataPreferenceDialogFragment().show(parentFragmentManager, null) } is PIDsListPreferences -> { + openPreferenceDialogFor(preference.source) when (preference.source) { "dash" -> { openPIDsDialog("pref.dash.pids.selected","dashboard") @@ -91,6 +95,12 @@ class PreferencesFragment : PreferenceFragmentCompat() { openPIDsDialog(gaugeVirtualScreen.getVirtualScreenPrefKey(), preference.source) { navigateToScreen(R.id.navigation_gauge) } } + + "trip_info" -> { + openPIDsDialog(preference.key, preference.source) + { navigateToPreferencesScreen("pref.aa") } + } + else -> { openPIDsDialog(preference.key, preference.source) } @@ -235,6 +245,11 @@ class PreferencesFragment : PreferenceFragmentCompat() { when (preferenceKey) { PREF_GAUGE_RECORDINGS -> TripsPreferenceDialogFragment().show(parentFragmentManager, null) + PREF_TRIP_INFO_DISPLAYED_PARAMETERS_IDS -> + openPIDsDialog("pref.aa.trip_info.pids.selected","trip_info") + { navigateToPreferencesScreen("pref.aa") } + + PREF_DASH_DISPLAYED_PARAMETERS_IDS -> openPIDsDialog("pref.dash.pids.selected","dashboard") { navigateToScreen(R.id.navigation_dashboard) } @@ -254,9 +269,7 @@ class PreferencesFragment : PreferenceFragmentCompat() { } private fun openPIDsDialog(key: String, source: String, onDialogCloseListener: (() -> Unit) = {}) { - val detailsViewVisible = source == "low" || source == "high" PIDsListPreferenceDialogFragment(key = key, source = source, - detailsViewEnabled = detailsViewVisible, onDialogCloseListener = onDialogCloseListener) .show(parentFragmentManager, null) } diff --git a/app/src/main/java/org/obd/graphs/preferences/pid/ModulesListPreferences.kt b/app/src/main/java/org/obd/graphs/preferences/pid/ModulesListPreferences.kt index 8a0cb51e..64765f28 100644 --- a/app/src/main/java/org/obd/graphs/preferences/pid/ModulesListPreferences.kt +++ b/app/src/main/java/org/obd/graphs/preferences/pid/ModulesListPreferences.kt @@ -32,7 +32,7 @@ import org.obd.graphs.modules import org.obd.graphs.preferences.Prefs import org.obd.graphs.sendBroadcastEvent -const val LOG_TAG = "ModulesListPreferences" +private const val LOG_TAG = "ModulesListPreferences" class ModulesListPreferences( context: Context, diff --git a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialogFragment.kt b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialogFragment.kt index e648d414..1b0d210a 100644 --- a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialogFragment.kt +++ b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialogFragment.kt @@ -37,6 +37,8 @@ import org.obd.graphs.ViewPreferencesSerializer import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.bl.datalogger.dataLoggerPreferences import org.obd.graphs.bl.datalogger.vehicleCapabilitiesManager +import org.obd.graphs.bl.query.Query +import org.obd.graphs.bl.query.QueryStrategyType import org.obd.graphs.preferences.CoreDialogFragment import org.obd.graphs.preferences.Prefs import org.obd.graphs.preferences.getStringSet @@ -53,18 +55,19 @@ private const val FILTER_BY_ECU_SUPPORTED_PIDS_PREF = "pref.pids.registry.filter private const val FILTER_BY_STABLE_PIDS_PREF = "pref.pids.registry.filter_pids_stable" private const val HIGH_PRIO_PID_PREF = "pref.pids.generic.high" private const val LOW_PRIO_PID_PREF = "pref.pids.generic.low" -private const val LOG_KEY = "PIDsDialog" +private const val LOG_TAG = "PIDsDialog" data class PidDefinitionDetails(val source: PidDefinition, var checked: Boolean = false, var supported: Boolean = true) -class PIDsListPreferenceDialogFragment( - private val key: String, private val detailsViewEnabled: Boolean = false, - private val source: String, private val onDialogCloseListener: (() -> Unit) = {} -) : - CoreDialogFragment() { +open class PIDsListPreferenceDialogFragment( + private val key: String, + private val source: String, + private val onDialogCloseListener: (() -> Unit) = {} +) : CoreDialogFragment() { private lateinit var root: View private lateinit var listOfItems: MutableList + private val detailsViewEnabled: Boolean = (source == "low" || source == "high") @SuppressLint("NotifyDataSetChanged") override fun onCreateView( @@ -77,7 +80,7 @@ class PIDsListPreferenceDialogFragment( root = inflater.inflate(R.layout.dialog_pids, container, false) - listOfItems = buildInitialList() + listOfItems = sourceList() val adapter = PIDsViewAdapter(root, context, listOfItems, detailsViewEnabled) val recyclerView: RecyclerView = getRecyclerView(root) @@ -120,18 +123,17 @@ class PIDsListPreferenceDialogFragment( searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { - if (Log.isLoggable(LOG_KEY, Log.DEBUG)) { - Log.d(LOG_KEY, "OnQueryTextSubmit newText=$query") + if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { + Log.d(LOG_TAG, "OnQueryTextSubmit newText=$query") } filterListOfItems(query) - return false } override fun onQueryTextChange(newValue: String): Boolean { - if (Log.isLoggable(LOG_KEY, Log.DEBUG)) { - Log.d(LOG_KEY, "OnQueryTextChange newValue=$newValue") + if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { + Log.d(LOG_TAG, "OnQueryTextChange newValue=$newValue") } filterListOfItems(newValue) @@ -184,15 +186,15 @@ class PIDsListPreferenceDialogFragment( val viewSerializer = viewPreferencesSerializer() val swappableAdapter: SwappableAdapter = object : SwappableAdapter { override fun swapItems(fromPosition: Int, toPosition: Int) { - if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) { - Log.v(LOG_KEY, "swappableAdapter fromPosition=$fromPosition toPosition=$toPosition") + if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { + Log.v(LOG_TAG, "swappableAdapter fromPosition=$fromPosition toPosition=$toPosition") } getAdapter().swapItems(fromPosition, toPosition) } override fun storePreferences(context: Context) { - if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) { - Log.v(LOG_KEY, "storePreferences for $key") + if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { + Log.v(LOG_TAG, "storePreferences for $key") } viewSerializer.store(getAdapter().data.map { it.source.id }) @@ -215,7 +217,7 @@ class PIDsListPreferenceDialogFragment( val newList = list.filter { it.checked } .map { it.source.id.toString() }.toList() - Log.i(LOG_KEY, "Key=$key, selected PIDs=$newList") + Log.i(LOG_TAG, "Key=$key, selected PIDs=$newList") if (Prefs.getStringSet(key).toSet() != newList.toSet()) { notifyListChanged() @@ -245,7 +247,7 @@ class PIDsListPreferenceDialogFragment( var text = newText if (newText.contains("m:")) { val spaceIndex = newText.indexOf(" ") - var module: String + val module: String val colon = newText.indexOf(":") + 1 if (spaceIndex > 0) { @@ -257,7 +259,7 @@ class PIDsListPreferenceDialogFragment( } filtered = filtered.filter { it.source.resourceFile.lowercase(Locale.getDefault()).contains(module) }.toMutableList() - Log.e(LOG_KEY, "Filtered module=$module and query=$text") + Log.e(LOG_TAG, "Filtered module=$module and query=$text") } if (text.isNotEmpty()) { @@ -274,11 +276,16 @@ class PIDsListPreferenceDialogFragment( private fun getAdapter() = (getRecyclerView(root).adapter as PIDsViewAdapter) - private fun buildInitialList(): MutableList { + private fun sourceList(): MutableList { val all = dataLogger.getPidDefinitionRegistry().findAll() val individualQuery = dataLoggerPreferences.instance.individualQueryStrategyEnabled - val list: List = - if (individualQuery) { + + val sourceList: List = + if (source == "trip_info"){ + val pidRegistry = dataLogger.getPidDefinitionRegistry() + val list = Query.instance(QueryStrategyType.TRIP_INFO_QUERY).getDefaults().map { pidRegistry.findBy(it) }.toMutableList() + list.map { PidDefinitionDetails(it, checked = false, supported = true) } + } else if (individualQuery) { findPidDefinitionByPriority(dataLogger.getPidDefinitionRegistry().findAll()) { true } } else { when (source) { @@ -286,30 +293,33 @@ class PIDsListPreferenceDialogFragment( "high" -> findPidDefinitionByPriority(all) { pidDefinition -> pidDefinition.priority == 0 } "dashboard" -> { - buildListFromSource(all) + map(all) } "graph" -> { - buildListFromSource(all) + map(all) } "gauge" -> { - buildListFromSource(all) + map(all) } "giulia" -> { - buildListFromSource(all) + map(all) } "aa" -> { - buildListFromSource(all) + map(all) } + else -> findPidDefinitionByPriority(dataLogger.getPidDefinitionRegistry().findAll()) { true } } } + Log.e(LOG_TAG,"source=${source}, size=${sourceList.size}") + val pref = Prefs.getStringSet(key).map { s -> s.toLong() } - list.let { + sourceList.let { it.forEach { p -> if (pref.contains(p.source.id)) { p.checked = true @@ -317,7 +327,7 @@ class PIDsListPreferenceDialogFragment( } } - return sortItems(list) + return sortItems(sourceList) } private fun sortItems( @@ -350,7 +360,7 @@ class PIDsListPreferenceDialogFragment( } } } catch (e: Throwable) { - Log.e(LOG_KEY, "Failed to sort PIDs", e) + Log.e(LOG_TAG, "Failed to sort PIDs", e) } } } @@ -362,7 +372,7 @@ class PIDsListPreferenceDialogFragment( private fun viewPreferencesSerializer(): ViewPreferencesSerializer = ViewPreferencesSerializer("$key.view.settings") - private fun buildListFromSource(all: MutableCollection): List { + private fun map(all: MutableCollection): List { val source = Prefs.getStringSet(HIGH_PRIO_PID_PREF).map { s -> s.toLong() } + Prefs.getStringSet(LOW_PRIO_PID_PREF).map { s -> s.toLong() } return findPidDefinitionByPriority(all.filter { source.contains(it.id) }) { true } diff --git a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferences.kt b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferences.kt index 5d0eebec..dd883d56 100644 --- a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferences.kt +++ b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferences.kt @@ -27,7 +27,7 @@ import org.obd.graphs.bl.datalogger.dataLoggerPreferences import org.obd.graphs.ui.common.COLOR_CARDINAL import org.obd.graphs.ui.common.colorize -open class PIDsListPreferences( +class PIDsListPreferences( context: Context, private val attrs: AttributeSet? ) : DialogPreference(context, attrs) { diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ae5bcafe..3883a617 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1377,6 +1377,24 @@ android:title="@string/pref.aa.trip_info.enabled" android:summary="@string/pref.aa.trip_info.enabled_summary" app:singleLineTitle="false" /> + + + + + + + + diff --git a/automotive/src/main/assets/alfa_2_0_gme_aa.properties b/automotive/src/main/assets/alfa_2_0_gme_aa.properties index 69f9b60f..2f4db9b5 100644 --- a/automotive/src/main/assets/alfa_2_0_gme_aa.properties +++ b/automotive/src/main/assets/alfa_2_0_gme_aa.properties @@ -146,4 +146,5 @@ profile_8.pref.aa.break_label.2=true profile_8.pref.aa.break_label.3=true profile_8.pref.aa.break_label.4=true -profile_8.pref.graph.filter.source="AA" \ No newline at end of file +profile_8.pref.graph.filter.source="AA" +profile_8.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/automotive/src/main/assets/alfa_2_0_gme_aa_gg_stn.properties b/automotive/src/main/assets/alfa_2_0_gme_aa_gg_stn.properties index 239d303e..54b57173 100644 --- a/automotive/src/main/assets/alfa_2_0_gme_aa_gg_stn.properties +++ b/automotive/src/main/assets/alfa_2_0_gme_aa_gg_stn.properties @@ -157,4 +157,5 @@ profile_10.pref.aa.break_label.2=true profile_10.pref.aa.break_label.3=true profile_10.pref.aa.break_label.4=true -profile_10.pref.graph.filter.source="AA" \ No newline at end of file +profile_10.pref.graph.filter.source="AA" +profile_10.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/automotive/src/main/assets/alfa_2_0_gme_aa_stn.properties b/automotive/src/main/assets/alfa_2_0_gme_aa_stn.properties index 30edc1bd..7cecfab2 100644 --- a/automotive/src/main/assets/alfa_2_0_gme_aa_stn.properties +++ b/automotive/src/main/assets/alfa_2_0_gme_aa_stn.properties @@ -154,4 +154,5 @@ profile_9.pref.aa.break_label.2=true profile_9.pref.aa.break_label.3=true profile_9.pref.aa.break_label.4=true -profile_9.pref.graph.filter.source="AA" \ No newline at end of file +profile_9.pref.graph.filter.source="AA" +profile_9.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/automotive/src/main/assets/alfa_2_0_gme_aa_stn_gpf.properties b/automotive/src/main/assets/alfa_2_0_gme_aa_stn_gpf.properties index aa50d230..116c72dc 100644 --- a/automotive/src/main/assets/alfa_2_0_gme_aa_stn_gpf.properties +++ b/automotive/src/main/assets/alfa_2_0_gme_aa_stn_gpf.properties @@ -155,4 +155,5 @@ profile_13.pref.adapter.stn.enabled=true profile_13.pref.profile.2_0_GME_extension.enabled=true -profile_13.pref.graph.filter.source="AA" \ No newline at end of file +profile_13.pref.graph.filter.source="AA" +profile_13.pref.aa.trip_info.pids.selected=[7021, 7076, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt index d0325c07..1deb057a 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt @@ -66,6 +66,11 @@ internal class SurfaceRendererScreen( } } + AA_TRIP_INFO_PID_SELECTION_CHANGED_EVENT -> { + updateQuery() + renderFrame() + } + AA_HIGH_FREQ_PID_SELECTION_CHANGED_EVENT -> { updateQuery() renderFrame() @@ -247,6 +252,7 @@ internal class SurfaceRendererScreen( it.addAction(AA_VIRTUAL_SCREEN_REFRESH_EVENT) it.addAction(AA_VIRTUAL_SCREEN_RENDERER_CHANGED_EVENT) it.addAction(AA_REFRESH_EVENT) + it.addAction(AA_TRIP_INFO_PID_SELECTION_CHANGED_EVENT) } } diff --git a/common/src/main/java/org/obd/graphs/Constants.kt b/common/src/main/java/org/obd/graphs/Constants.kt index e2b8bd52..a1d25257 100644 --- a/common/src/main/java/org/obd/graphs/Constants.kt +++ b/common/src/main/java/org/obd/graphs/Constants.kt @@ -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_TRIP_INFO_PID_SELECTION_CHANGED_EVENT = "pref.aa.trip_info.pids.selected.event.changed" const val AA_REFRESH_EVENT = "pref.pids.refresh.event" const val PREF_DYNAMIC_SELECTOR_ENABLED = "pref.aa.theme.dynamic-selector.enabled" diff --git a/common/src/main/java/org/obd/graphs/preferences/Preferences.kt b/common/src/main/java/org/obd/graphs/preferences/Preferences.kt index b293a98e..dc972b35 100644 --- a/common/src/main/java/org/obd/graphs/preferences/Preferences.kt +++ b/common/src/main/java/org/obd/graphs/preferences/Preferences.kt @@ -74,8 +74,8 @@ fun SharedPreferences.updateLongSet(key: String, list: List) { edit().putStringSet(key, list.map { l -> l.toString() }.toSet()).commit() } -fun SharedPreferences.getLongSet(key: String): Set { - return getStringSet(key, emptySet())?.map { s -> s.toLong() }?.toSet()!! +fun SharedPreferences.getLongSet(key: String, defaults: MutableSet = mutableSetOf()): Set { + return getStringSet(key,defaults)?.map { s -> s.toLong() }?.toSet()!! } fun SharedPreferences.getStringSet(key: String): MutableSet { diff --git a/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt b/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt index 9a8c01be..e5d8777f 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt @@ -33,7 +33,13 @@ internal class InMemoryCarMetricsCollector : MetricsCollector { override fun getMetrics(enabled: Boolean): List = metrics.values.filter { it.enabled == enabled } - override fun getMetric(id: Long): Metric? = metrics[id] + override fun getMetric(id: Long, enabled: Boolean): Metric? = + if (metrics.containsKey(id) && metrics[id]!!.enabled) { + metrics[id] + } else { + null + } + override fun applyFilter(enabled: Set, order: Map?) { Log.i(LOG_KEY, "Updating visible PIDs=$enabled with order=$order") diff --git a/datalogger/src/main/java/org/obd/graphs/bl/collector/MetricsCollector.kt b/datalogger/src/main/java/org/obd/graphs/bl/collector/MetricsCollector.kt index 8d7b0197..e27f4686 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/collector/MetricsCollector.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/collector/MetricsCollector.kt @@ -22,7 +22,7 @@ import org.obd.metrics.api.model.ObdMetric interface MetricsCollector { - fun getMetric(id: Long): Metric? + fun getMetric(id: Long,enabled: Boolean = true): Metric? fun getMetrics(enabled: Boolean = true): List diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/Query.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/Query.kt index ecfb2cb3..96ac682d 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/Query.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/Query.kt @@ -19,6 +19,7 @@ package org.obd.graphs.bl.query interface Query: java.io.Serializable { + fun getDefaults(): Set fun getIDs(): MutableSet fun getStrategy(): QueryStrategyType fun setStrategy(queryStrategyType: QueryStrategyType): Query diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategy.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategy.kt index 10d8e7ba..d43876f9 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategy.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategy.kt @@ -23,5 +23,7 @@ internal open class QueryStrategy(protected val pids: MutableSet = mutable pids.addAll(newPIDs) } + open fun getDefaults(): Set = emptySet() + open fun getPIDs(): MutableSet = pids } \ No newline at end of file diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategyOrchestrator.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategyOrchestrator.kt index 42bfceee..578b2924 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategyOrchestrator.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/QueryStrategyOrchestrator.kt @@ -20,7 +20,10 @@ internal class QueryStrategyOrchestrator : java.io.Serializable, Query { } } + + private var strategy: QueryStrategyType = QueryStrategyType.SHARED_QUERY + override fun getDefaults(): Set = strategies[strategy]?.getDefaults() ?: emptySet() override fun getIDs(): MutableSet = strategies[strategy]?.getPIDs() ?: mutableSetOf() diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt index 5109b9b4..43d1fc3a 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/TripInfoQueryStrategy.kt @@ -18,29 +18,36 @@ **/ package org.obd.graphs.bl.query +import org.obd.graphs.preferences.Prefs +import org.obd.graphs.preferences.getLongSet + + +private const val TRIP_INFO_QUERY_PREF_KEY = "pref.aa.trip_info.pids.selected" internal class TripInfoQueryStrategy : QueryStrategy() { - override fun getPIDs(): MutableSet = - mutableSetOf( - namesRegistry.getVehicleSpeedPID(), - namesRegistry.getFuelConsumptionPID(), - namesRegistry.getFuelLevelPID(), - namesRegistry.getAtmPressurePID(), - namesRegistry.getAmbientTempPID(), - namesRegistry.getGearboxOilTempPID(), - namesRegistry.getOilTempPID(), - namesRegistry.getCoolantTempPID(), - namesRegistry.getExhaustTempPID(), - namesRegistry.getAirTempPID(), - namesRegistry.getTotalMisfiresPID(), - namesRegistry.getOilLevelPID(), - namesRegistry.getTorquePID(), - namesRegistry.getIntakePressurePID(), - namesRegistry.getDynamicSelectorPID(), - namesRegistry.getDistancePID(), - namesRegistry.getBatteryVoltagePID(), - namesRegistry.getIbsPID(), - namesRegistry.getOilPressurePID(), - ) + + private val defaults = mutableSetOf( + namesRegistry.getFuelConsumptionPID(), + namesRegistry.getFuelLevelPID(), + namesRegistry.getAtmPressurePID(), + namesRegistry.getAmbientTempPID(), + namesRegistry.getGearboxOilTempPID(), + namesRegistry.getOilTempPID(), + namesRegistry.getCoolantTempPID(), + namesRegistry.getExhaustTempPID(), + namesRegistry.getAirTempPID(), + namesRegistry.getTotalMisfiresPID(), + namesRegistry.getOilLevelPID(), + namesRegistry.getTorquePID(), + namesRegistry.getIntakePressurePID(), + namesRegistry.getDynamicSelectorPID(), + namesRegistry.getDistancePID(), + namesRegistry.getBatteryVoltagePID(), + namesRegistry.getIbsPID(), + namesRegistry.getOilPressurePID(), + ) + override fun getDefaults() = defaults + + override fun getPIDs() = Prefs.getLongSet(TRIP_INFO_QUERY_PREF_KEY).toMutableSet() } diff --git a/ext/src/main/assets/giulia_2_2_multijet.properties b/ext/src/main/assets/giulia_2_2_multijet.properties index 6f40649e..6fd59daf 100644 --- a/ext/src/main/assets/giulia_2_2_multijet.properties +++ b/ext/src/main/assets/giulia_2_2_multijet.properties @@ -147,3 +147,4 @@ profile_15.pref.aa.break_label.4=true profile_15.pref.graph.filter.source="AA" profile_15.pref.aa.trip_info.enabled=false +profile_15.pref.aa.trip_info.pids.selected=[7021, 7076, 7046, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/ext/src/main/assets/qiulia_qv.properties b/ext/src/main/assets/qiulia_qv.properties index 0b2af0d2..cec9ed43 100644 --- a/ext/src/main/assets/qiulia_qv.properties +++ b/ext/src/main/assets/qiulia_qv.properties @@ -159,3 +159,4 @@ profile_14.pref.aa.break_label.4=true profile_14.pref.graph.filter.source="AA" profile_14.pref.aa.trip_info.enabled=false +profile_profile_14.pref.aa.trip_info.pids.selected=[7021, 7076, 7046, 7035, 7002, 7037, 7014, 7047, 7025, 7003, 7036, 7028, 7016, 17078, 7005, 7020, 7019, 7018, 7009] \ No newline at end of file diff --git a/profile/src/main/java/org/obd/graphs/profile/Profile.kt b/profile/src/main/java/org/obd/graphs/profile/Profile.kt index 33b3af08..91b6b9d4 100644 --- a/profile/src/main/java/org/obd/graphs/profile/Profile.kt +++ b/profile/src/main/java/org/obd/graphs/profile/Profile.kt @@ -18,7 +18,6 @@ **/ package org.obd.graphs.profile -import android.content.SharedPreferences const val PROFILE_CHANGED_EVENT = "data.logger.profile.changed.event" const val PROFILE_RESET_EVENT = "data.logger.profile.reset.event" @@ -27,7 +26,7 @@ const val PROFILE_ID_PREF = "pref.profile.id" val profile: Profile = ProfilePreferencesBackend() -interface Profile : SharedPreferences.OnSharedPreferenceChangeListener { +interface Profile { fun updateCurrentProfileName(newName: String) fun getAvailableProfiles(): Map diff --git a/profile/src/main/java/org/obd/graphs/profile/ProfilePreferencesBackend.kt b/profile/src/main/java/org/obd/graphs/profile/ProfilePreferencesBackend.kt index 0e252aed..d6bc7a09 100644 --- a/profile/src/main/java/org/obd/graphs/profile/ProfilePreferencesBackend.kt +++ b/profile/src/main/java/org/obd/graphs/profile/ProfilePreferencesBackend.kt @@ -40,7 +40,7 @@ private const val DEFAULT_MAX_PROFILES = 20 private const val BACKUP_FILE_NAME = "obd_graphs.backup" private const val DEFAULT_PROFILE = "profile_1" -internal class ProfilePreferencesBackend : Profile { +internal class ProfilePreferencesBackend : Profile, SharedPreferences.OnSharedPreferenceChangeListener { private var versionCode: Int = 0 private var defaultProfile: String? = null @@ -154,6 +154,7 @@ internal class ProfilePreferencesBackend : Profile { this.versionName = versionName updateBuildSettings() + Prefs.registerOnSharedPreferenceChangeListener(this) } override fun setupProfiles(forceOverrideRecommendation: Boolean) { diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt index 605aec96..38e80539 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt @@ -50,30 +50,47 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst val x = maxItemWidth(area) + 4 var rowTop = top + 12f - tripInfo.airTemp?.let { drawMetric(it, top = rowTop, left = left, canvas, textSizeBase, statsEnabled = true, area=area) } - tripInfo.coolantTemp?.let { drawMetric(it, rowTop, left + 1 * x, canvas, textSizeBase, statsEnabled = true,area=area) } - tripInfo.oilTemp?.let{drawMetric(it, rowTop, left + 2 * x, canvas, textSizeBase, statsEnabled = true,area=area) } - tripInfo.exhaustTemp?.let { drawMetric(it, rowTop, left + 3 * x, canvas, textSizeBase, statsEnabled = true, area=area) } - tripInfo.gearboxOilTemp?.let {drawMetric(it, rowTop, left + 4 * x, canvas, textSizeBase, statsEnabled = true, area=area) } - tripInfo.distance?.let{drawMetric(diff(it), rowTop, left + 5 * x, canvas, textSizeBase, area=area) } + var leftAlignment = 0 + tripInfo.airTemp?.let { drawMetric(it, top = rowTop, left = left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area=area) } + tripInfo.coolantTemp?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true,area=area) } + tripInfo.oilTemp?.let{drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true,area=area) } + tripInfo.exhaustTemp?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area=area) } + tripInfo.gearboxOilTemp?.let {drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area=area) } + tripInfo.distance?.let{drawMetric(diff(it), rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, area=area) } //second row + leftAlignment = 0 rowTop = top + (textSizeBase) + 52f - tripInfo.fuellevel?.let { drawMetric(it, rowTop, left, canvas, textSizeBase, statsEnabled = true, area=area, statsDoublePrecision = 1, valueDoublePrecision = 1)} - tripInfo.fuelConsumption?.let {drawMetric(it, rowTop, left + 1 * x, canvas, textSizeBase, statsEnabled = true, unitEnabled = false, area=area, statsDoublePrecision = 1)} - tripInfo.batteryVoltage?.let { drawMetric(it, rowTop, left + 2 * x, canvas, textSizeBase, statsEnabled = true, area=area) } - tripInfo.ibs?.let { drawMetric(it, rowTop, left + 3 * x, canvas, textSizeBase, area=area, castToInt = true)} - tripInfo.oilLevel?.let { drawMetric(it, rowTop, left + 4 * x, canvas, textSizeBase, statsEnabled = true, area = area) } - tripInfo.totalMisfires?.let { drawMetric(it, rowTop, left + 5 * x, canvas, textSizeBase, unitEnabled = false, area = area) } + tripInfo.fuellevel?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area=area, statsDoublePrecision = 1, valueDoublePrecision = 1)} + tripInfo.fuelConsumption?.let {drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, unitEnabled = false, area=area, statsDoublePrecision = 1)} + tripInfo.batteryVoltage?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area=area) } + tripInfo.ibs?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, area=area, castToInt = true)} + tripInfo.oilLevel?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, statsEnabled = true, area = area) } + tripInfo.totalMisfires?.let { drawMetric(it, rowTop, left + (leftAlignment++) * x, canvas, textSizeBase, unitEnabled = false, area = area) } drawDivider(canvas, left, area.width().toFloat(), rowTop + textSizeBase + 4, Color.DKGRAY) //metrics rowTop += 2.2f * textSizeBase - tripInfo.intakePressure?.let { drawMetric(canvas, area, it, left, rowTop) } - tripInfo.torque?.let { drawMetric(canvas, area, it, left + getAreaWidth(area) + 5, rowTop) } - tripInfo.oilPressure?.let { drawMetric(canvas, area, it, left + 2 * getAreaWidth(area) + 5, rowTop) } + leftAlignment = 0 + val bottomMetrics = mutableListOf() + + tripInfo.intakePressure?.let { + bottomMetrics.add(it) + } + + tripInfo.oilPressure?.let { + bottomMetrics.add(it) + } + + tripInfo.torque?.let { + bottomMetrics.add(it) + } + + bottomMetrics.forEachIndexed{ index, metric -> + drawMetric(canvas, area, metric, left + (index * getAreaWidth(area, items = bottomMetrics.size) + 5), rowTop, bottomMetrics.size) + } } private fun diff(metric: Metric) : Metric { @@ -105,7 +122,8 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst area: Rect, metric: Metric, left: Float, - top: Float + top: Float, + items: Int ): Float { val (valueTextSize, textSizeBase) = calculateFontSize(area) @@ -121,12 +139,13 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst textSizeBase * 0.75f ) + val areaWidth = getAreaWidth(area, items = items) drawValue( canvas, metric, top1 + 44, valueTextSize * 0.9f, - left = left + getAreaWidth(area) - 50f + left = left + areaWidth - 50f ) val scaleRatio = getScaleRatio() @@ -184,7 +203,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst drawProgressBar( canvas, left, - getAreaWidth(area), top1, metric, + areaWidth, top1, metric, color = settings.getColorTheme().progressColor ) @@ -192,7 +211,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst drawDivider( canvas, - left, getAreaWidth(area), top1, + left, areaWidth, top1, color = settings.getColorTheme().dividerColor ) @@ -209,7 +228,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst ) private inline fun calculateDividerSpacing(): Int = 14 - private inline fun getAreaWidth(area: Rect): Float = area.width().toFloat() / 3 + private inline fun getAreaWidth(area: Rect, items: Int = 3): Float = area.width().toFloat() / items private fun drawProgressBar( canvas: Canvas, diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt index 6a8d27ef..64425d80 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt @@ -22,10 +22,13 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Color import android.graphics.Rect +import android.util.Log import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.query.* import org.obd.graphs.renderer.* +private const val LOG_TAG = "TripInfoSurfaceRenderer" + @Suppress("NOTHING_TO_INLINE") internal class TripInfoSurfaceRenderer( context: Context, @@ -37,11 +40,12 @@ internal class TripInfoSurfaceRenderer( private val tripInfo = TripInfoDetails() private val tripInfoDrawer = TripInfoDrawer(context, settings) override fun applyMetricsFilter(query: Query) { + Log.e(LOG_TAG,"Query strategy ${query.getStrategy()}, selected ids: ${query.getIDs()}") + metricsCollector.applyFilter( enabled = query.getIDs() ) } - override fun onDraw(canvas: Canvas, drawArea: Rect?) { drawArea?.let { it -> @@ -90,6 +94,7 @@ internal class TripInfoSurfaceRenderer( } } + override fun recycle() { tripInfoDrawer.recycle() }