Skip to content

Commit

Permalink
feat:TripInfo: Conditionall displaying PIDs on the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski authored Sep 15, 2024
1 parent 6303d45 commit 3a2459a
Show file tree
Hide file tree
Showing 29 changed files with 194 additions and 96 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -72,7 +72,7 @@ android {
dimension "version"
resValue "string", "DEFAULT_PROFILE", "profile_3"
applicationId "org.obd.graphs.my.giulia"
versionCode 59
versionCode 60
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/assets/alfa_2_0_gme.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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]
3 changes: 2 additions & 1 deletion app/src/main/assets/alfa_2_0_gme_stn_usb.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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]
3 changes: 2 additions & 1 deletion app/src/main/assets/alfa_2_0_gme_stn_wifi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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]
2 changes: 0 additions & 2 deletions app/src/main/java/org/obd/graphs/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -221,7 +220,6 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
versionName = BuildConfig.VERSION_NAME
)

Prefs.registerOnSharedPreferenceChangeListener(profile)
profile.setupProfiles(forceOverrideRecommendation = false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down Expand Up @@ -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) }
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<PidDefinitionDetails>
private val detailsViewEnabled: Boolean = (source == "low" || source == "high")

@SuppressLint("NotifyDataSetChanged")
override fun onCreateView(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
Expand All @@ -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()
Expand Down Expand Up @@ -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) {
Expand All @@ -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()) {
Expand All @@ -274,50 +276,58 @@ class PIDsListPreferenceDialogFragment(

private fun getAdapter() = (getRecyclerView(root).adapter as PIDsViewAdapter)

private fun buildInitialList(): MutableList<PidDefinitionDetails> {
private fun sourceList(): MutableList<PidDefinitionDetails> {
val all = dataLogger.getPidDefinitionRegistry().findAll()
val individualQuery = dataLoggerPreferences.instance.individualQueryStrategyEnabled
val list: List<PidDefinitionDetails> =
if (individualQuery) {

val sourceList: List<PidDefinitionDetails> =
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) {
"low" -> findPidDefinitionByPriority(all) { pidDefinition -> pidDefinition.priority > 0 }
"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
}
}
}

return sortItems(list)
return sortItems(sourceList)
}

private fun sortItems(
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -362,7 +372,7 @@ class PIDsListPreferenceDialogFragment(

private fun viewPreferencesSerializer(): ViewPreferencesSerializer = ViewPreferencesSerializer("$key.view.settings")

private fun buildListFromSource(all: MutableCollection<PidDefinition>): List<PidDefinitionDetails> {
private fun map(all: MutableCollection<PidDefinition>): List<PidDefinitionDetails> {
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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,24 @@
android:title="@string/pref.aa.trip_info.enabled"
android:summary="@string/pref.aa.trip_info.enabled_summary"
app:singleLineTitle="false" />


<PreferenceScreen
android:key="pref.trip_info.displayed_parameter_ids"
android:summary="@string/pref.displayed_parameter_ids_summary"
android:title="@string/pref.displayed_parameter_ids">
<PreferenceCategory android:title="@string/pref.pids_category">
<org.obd.graphs.preferences.pid.PIDsListPreferences
android:defaultValue="@array/pref.empty_array"
android:dialogTitle="@string/pref.displayed_parameter_ids"
android:key="pref.aa.trip_info.pids.selected"
android:summary="@string/pref.displayed_parameter_ids_summary"
android:title="@string/pref.displayed_parameter_ids"
app:source="trip_info"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</PreferenceScreen>

</PreferenceCategory>


Expand Down
3 changes: 2 additions & 1 deletion automotive/src/main/assets/alfa_2_0_gme_aa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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]
3 changes: 2 additions & 1 deletion automotive/src/main/assets/alfa_2_0_gme_aa_gg_stn.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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]
3 changes: 2 additions & 1 deletion automotive/src/main/assets/alfa_2_0_gme_aa_stn.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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]
Loading

0 comments on commit 3a2459a

Please sign in to comment.