diff --git a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialog.kt b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialog.kt index 182c9b29..64e3ad58 100644 --- a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialog.kt +++ b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsListPreferenceDialog.kt @@ -20,13 +20,12 @@ import org.obd.graphs.preferences.getStringSet import org.obd.graphs.preferences.updateStringSet import org.obd.metrics.pid.PIDsGroup import org.obd.metrics.pid.PidDefinition -import java.util.* private const val FILTER_BY_ECU_SUPPORTED_PIDS_PREF = "pref.pids.registry.filter_pids_ecu_supported" private const val FILTER_BY_STABLE_PIDS_PREF = "pref.pids.registry.filter_pids_stable" -data class PidDefinitionWrapper(val source: PidDefinition, var checked: Boolean = false) +data class PidDefinitionWrapper(val source: PidDefinition, var checked: Boolean = false, var supported: Boolean = true) class PIDsListPreferenceDialog(private val key: String, private val priority: String) : DialogFragment() { @@ -90,34 +89,26 @@ class PIDsListPreferenceDialog(private val key: String, private val priority: St .map { it.source.id.toString() }.toList() - private fun findPidDefinitionByPriority(predicate: (PidDefinition) -> Boolean): MutableList { - val entriesValues: MutableList = - LinkedList() + private fun findPidDefinitionByPriority(predicate: (PidDefinition) -> Boolean): List { val ecuSupportedPIDs = vehicleCapabilitiesManager.getCapabilities() val ecuSupportedPIDsEnabled = Prefs.getBoolean(FILTER_BY_ECU_SUPPORTED_PIDS_PREF, false) val stablePIDsEnabled = Prefs.getBoolean(FILTER_BY_STABLE_PIDS_PREF, false) - getPidList() + return getPidList() .asSequence() .filter { p -> p.group == PIDsGroup.LIVEDATA } .filter { p -> if (!stablePIDsEnabled) p.stable!! else true } .filter { p -> predicate.invoke(p) } - .filter { p -> - if (ecuSupportedPIDs.size > 0 && - !ecuSupportedPIDsEnabled && p.mode == "01" - ) - ecuSupportedPIDs.contains(p.pid.lowercase()) else true - } - .sortedBy { p -> p.displayString().toString() } + .map { p -> PidDefinitionWrapper(source=p, supported=isSupported(ecuSupportedPIDs, p))} + .filter { p-> if (ecuSupportedPIDsEnabled) true else p.supported } .toList() - .forEach { p -> - - entriesValues.add(PidDefinitionWrapper(p)) - } - - return entriesValues } + private fun isSupported( + ecuSupportedPIDs: MutableList, p: PidDefinition) : Boolean = if (p.mode == "01"){ + ecuSupportedPIDs.contains(p.pid.lowercase()) + } else true + private fun getPidList() = dataLogger.getPidDefinitionRegistry().findAll() } \ No newline at end of file diff --git a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsViewAdapter.kt b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsViewAdapter.kt index 18243520..711de954 100644 --- a/app/src/main/java/org/obd/graphs/preferences/pid/PIDsViewAdapter.kt +++ b/app/src/main/java/org/obd/graphs/preferences/pid/PIDsViewAdapter.kt @@ -13,12 +13,13 @@ import androidx.recyclerview.widget.RecyclerView import org.obd.graphs.R import org.obd.graphs.ui.common.COLOR_DYNAMIC_SELECTOR_SPORT import org.obd.graphs.ui.common.COLOR_PHILIPPINE_GREEN +import org.obd.graphs.ui.common.COLOR_RAINBOW_INDIGO import org.obd.graphs.ui.common.setText class PIDsViewAdapter internal constructor( context: Context?, - var data: MutableList + var data: List ) : RecyclerView.Adapter() { private val mInflater: LayoutInflater = LayoutInflater.from(context) @@ -37,12 +38,19 @@ class PIDsViewAdapter internal constructor( data.elementAt(position).run { holder.mode.setText(source.resourceFile, COLOR_PHILIPPINE_GREEN, Typeface.NORMAL, 0.7f) holder.name.setText(source.description, Color.GRAY, Typeface.NORMAL, 1f) + if (source.stable) { holder.status.setText("Yes", Color.GRAY, Typeface.NORMAL, 0.8f) } else { holder.status.setText("No", COLOR_DYNAMIC_SELECTOR_SPORT, Typeface.NORMAL, 0.8f) } + if (supported) { + holder.supported.setText("Yes", COLOR_RAINBOW_INDIGO, Typeface.NORMAL, 0.8f) + } else { + holder.supported.setText("No", COLOR_DYNAMIC_SELECTOR_SPORT, Typeface.NORMAL, 0.8f) + } + holder.selected.isChecked = checked holder.selected.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isShown) { @@ -76,5 +84,7 @@ class PIDsViewAdapter internal constructor( val status: TextView = itemView.findViewById(R.id.pid_status) val selected: CheckBox = itemView.findViewById(R.id.pid_selected) val alert: TextView = itemView.findViewById(R.id.pid_alert) + val supported: TextView = itemView.findViewById(R.id.pid_supported) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_pids.xml b/app/src/main/res/layout/dialog_pids.xml index 80b12802..1099881a 100644 --- a/app/src/main/res/layout/dialog_pids.xml +++ b/app/src/main/res/layout/dialog_pids.xml @@ -63,13 +63,22 @@ android:layout_width="0dp" android:layout_weight="0.5" android:gravity="start" - android:text="@string/pids_alert" + android:text="@string/pids_supported" android:textAllCaps="false" android:textColor="@color/gray_dark" android:textSize="14sp" android:textStyle="bold" /> + + android:textSize="14sp" /> + android:textSize="14sp" /> + android:textSize="14sp" /> + + + android:textSize="14sp"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d9d1a6de..d81b97a2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -301,6 +301,7 @@ 7 8 Save + Supported