Skip to content

Commit

Permalink
feat: Rework unsupported PID list
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Aug 28, 2023
1 parent e7757eb commit b6fc823
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<PidDefinitionWrapper> {
val entriesValues: MutableList<PidDefinitionWrapper> =
LinkedList()
private fun findPidDefinitionByPriority(predicate: (PidDefinition) -> Boolean): List<PidDefinitionWrapper> {

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<String>, p: PidDefinition) : Boolean = if (p.mode == "01"){
ecuSupportedPIDs.contains(p.pid.lowercase())
} else true

private fun getPidList() = dataLogger.getPidDefinitionRegistry().findAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PidDefinitionWrapper>
var data: List<PidDefinitionWrapper>
) : RecyclerView.Adapter<PIDsViewAdapter.ViewHolder>() {

private val mInflater: LayoutInflater = LayoutInflater.from(context)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)

}
}
11 changes: 10 additions & 1 deletion app/src/main/res/layout/dialog_pids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />


<TextView
android:layout_width="0dp"
android:layout_weight="0.5"
android:gravity="start"
android:text="@string/pids_alert"
android:textAllCaps="false"
android:textColor="@color/gray_dark"
android:textSize="14sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
Expand Down
21 changes: 16 additions & 5 deletions app/src/main/res/layout/item_pids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:paddingStart="4dp"
android:paddingEnd="0dp"
android:textColor="@color/gray_dark"
android:textSize="16sp"
android:textSize="14sp"
android:textStyle="bold" />

<TextView
Expand All @@ -39,7 +39,7 @@
android:paddingEnd="0dp"
android:text="@string/pids_file"
android:textColor="@color/gray_light"
android:textSize="16sp" />
android:textSize="14sp" />

<TextView
android:id="@+id/pid_name"
Expand All @@ -49,7 +49,7 @@
android:text="@string/pids_name"
android:textAllCaps="false"
android:textColor="@color/gray_light"
android:textSize="16sp" />
android:textSize="14sp" />

<TextView
android:id="@+id/pid_status"
Expand All @@ -59,7 +59,18 @@
android:text="@string/pids_stable"
android:textAllCaps="false"
android:textColor="@color/gray_light"
android:textSize="16sp" />
android:textSize="14sp" />

<TextView
android:id="@+id/pid_supported"
android:layout_width="0dp"
android:layout_weight="0.5"
android:gravity="start"
android:text="@string/pids_supported"
android:textAllCaps="false"
android:textColor="@color/gray_dark"
android:textSize="14sp"
android:textStyle="bold" />

<TextView
android:id="@+id/pid_alert"
Expand All @@ -68,7 +79,7 @@
android:gravity="start"
android:textAllCaps="false"
android:textColor="@color/gray_light"
android:textSize="16sp"/>
android:textSize="14sp"/>

</TableRow>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="virtual_screen_7">7</string>
<string name="virtual_screen_8">8</string>
<string name="dialog_save_action">Save</string>
<string name="pids_supported">Supported</string>


<string-array name="pref.numbers_1_20">
Expand Down

0 comments on commit b6fc823

Please sign in to comment.