Skip to content

Commit

Permalink
feat: add option to disable displays
Browse files Browse the repository at this point in the history
  • Loading branch information
agronick committed Jan 6, 2024
1 parent ade612e commit 12a05ba
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 35 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/com/aatorque/prefs/PrefStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ screens {
wholeNumbers: true
ticksActive: true
chartColor: -12734743
disabled: false
}
gauges {
pid: "torque_0d,0"
Expand All @@ -38,6 +39,7 @@ screens {
highVisActive: true
ticksActive: true
chartColor: -5314243
disabled: false
}
gauges {
pid: "torque_11,0"
Expand All @@ -48,6 +50,7 @@ screens {
unit: "%"
ticksActive: true
chartColor: -1476547
disabled: false
}
displays {}
displays {}
Expand Down Expand Up @@ -76,14 +79,14 @@ object UserPreferenceSerializer : Serializer<UserPreference> {
override var defaultValue: UserPreference

init {
try {
defaultValue = TextFormat.parse(
defaultValue = try {
TextFormat.parse(
DEFAULT_SETTINGS,
UserPreference::class.java
)
} catch (e: Exception) {
Timber.e("Failed to load defaults", e)
defaultValue = UserPreference.newBuilder().addScreens(defaultScreen).build()
UserPreference.newBuilder().addScreens(defaultScreen).build()
}
}

Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/aatorque/prefs/SettingsPIDFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.aatorque.datastore.Display
import com.aatorque.datastore.MaxControl
import com.aatorque.datastore.Screen
Expand All @@ -35,6 +36,7 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {
var screen = 0
var index = 0

lateinit var enabledPref: SwitchPreferenceCompat
lateinit var pidPref: ListPreference
lateinit var showLabelPref: CheckBoxPreference
lateinit var labelPref: EditTextPreference
Expand Down Expand Up @@ -89,6 +91,7 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {
index = parts[2].toInt()
preferenceManager.sharedPreferencesName = null

enabledPref = findPreference("enabled")!!
pidPref = findPreference("pidList")!!
showLabelPref = findPreference("showLabel")!!
labelPref = findPreference("label")!!
Expand Down Expand Up @@ -172,6 +175,7 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {
val data = requireContext().dataStore.data.first()
val screen = data.getScreens(screen)
val display = if (isClock) screen.getGauges(index) else screen.getDisplays(index)
enabledPref.isChecked = !display.disabled
pidPref.value = display.pid
showLabelPref.isChecked = display.showLabel
labelPref.text = display.label
Expand All @@ -187,7 +191,11 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {
highVisActivePref.isChecked = display.highVisActive
colorPref.colorValue = display.chartColor.let {
if (it == 0) {
resources.obtainTypedArray(R.array.chartColors).getColor(index, Color.WHITE)
resources.obtainTypedArray(R.array.chartColors).run {
val color = getColor(index, Color.WHITE)
recycle()
color
}
} else it
}
jsPref.setValue(display.customScript)
Expand Down Expand Up @@ -230,7 +238,9 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {

val minVal = coerce(minValuePref.text, 0)
val maxVal = coerce(maxValuePref.text, 100)
var display = Display.newBuilder().setPid(
var display = Display.newBuilder().setDisabled(
!enabledPref.isChecked
).setPid(
pidPref.value
).setShowLabel(
showLabelPref.isChecked
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/aatorque/stats/TorqueData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class TorqueData(var display: Display) {
}

var pid: String? = null
get() {
return if (display.disabled) null else field
}
var minValue: Double = Double.POSITIVE_INFINITY
var maxValue: Double = Double.NEGATIVE_INFINITY
private var expression: Expression? = null
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/aatorque/stats/TorqueGauge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class TorqueGauge : Fragment() {
}

fun setupClock(data: TorqueData) {
binding.visible = data.pid != null

data.notifyUpdate = this::onUpdate
val iconDrawableName = data.getDrawableName() ?: "ic_none"
val iconText = if (data.display.showLabel) data.display.label else ""
Expand Down
1 change: 1 addition & 0 deletions app/src/main/proto/user_prefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum MaxControl {
}

message Display {
bool disabled = 25;
string pid = 1;
bool showLabel = 2;
string label = 3;
Expand Down
48 changes: 26 additions & 22 deletions app/src/main/res/layout/fragment_gauge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,39 @@
<variable
name="icon"
type="Drawable" />

<variable
name="visible"
type="Boolean" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="0dp"
app:layout_constraintGuide_percent="0.5"
/>

<TextView
android:id="@+id/textMax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:drawableStart="@{showLimitBelow == MaxControl.MAX ? @drawable/ic_max_text : @drawable/ic_min_text}"
android:elevation="1dp"
android:ellipsize="marquee"
android:text="@{limitValue}"
android:textAlignment="center"
android:textColor="@android:color/white"
android:clipChildren="false"
android:visibility="@{visible ? View.VISIBLE : View.GONE}">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="0dp"
app:layout_constraintGuide_percent="0.5" />

<TextView
android:id="@+id/textMax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:drawableStart="@{showLimitBelow == MaxControl.MAX ? @drawable/ic_max_text : @drawable/ic_min_text}"
android:elevation="1dp"
android:ellipsize="marquee"
android:text="@{limitValue}"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="24sp"
android:typeface="@{font}"
android:visibility="@{showLimitBelow == MaxControl.OFF ? View.INVISIBLE : View.VISIBLE}"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,7 @@
<string name="media_blur_summary">Blur artwork to help improve readability</string>
<string name="media_darken_title">Darken artwork</string>
<string name="media_darken_summary">Darken artwork to help improve readability</string>
<string name="enabled">Enabled</string>
<string name="enabled_desc_on">Show this item</string>
<string name="enabled_desc_off">Hide this item</string>
</resources>
22 changes: 14 additions & 8 deletions app/src/main/res/xml/pid_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
android:key="pidCategory"
android:enabled="false"
android:summary="@string/torque_waiting">
<ListPreference
android:key="pidList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:title="@string/pid"
app:dialogTitle="@string/pid"
android:persistent="false"
/>
<SwitchPreferenceCompat
android:dependency="pidList"
android:key="enabled"
android:persistent="false"
android:summaryOff="@string/enabled_desc_off"
android:summaryOn="@string/enabled_desc_on"
android:title="@string/enabled" />
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:key="pidList"
android:persistent="false"
android:title="@string/pid"
app:dialogTitle="@string/pid" />
</PreferenceCategory>
<CheckBoxPreference
android:key="showLabel"
Expand Down

0 comments on commit 12a05ba

Please sign in to comment.