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 12a05ba commit 6bbed4a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 52 deletions.
9 changes: 3 additions & 6 deletions app/src/main/java/com/aatorque/prefs/PrefStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ screens {
wholeNumbers: true
ticksActive: true
chartColor: -12734743
disabled: false
}
gauges {
pid: "torque_0d,0"
Expand All @@ -39,7 +38,6 @@ screens {
highVisActive: true
ticksActive: true
chartColor: -5314243
disabled: false
}
gauges {
pid: "torque_11,0"
Expand All @@ -50,7 +48,6 @@ screens {
unit: "%"
ticksActive: true
chartColor: -1476547
disabled: false
}
displays {}
displays {}
Expand Down Expand Up @@ -79,14 +76,14 @@ object UserPreferenceSerializer : Serializer<UserPreference> {
override var defaultValue: UserPreference

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

Expand Down
14 changes: 2 additions & 12 deletions app/src/main/java/com/aatorque/prefs/SettingsPIDFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -36,7 +35,6 @@ 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 @@ -91,7 +89,6 @@ 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 @@ -175,7 +172,6 @@ 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 @@ -191,11 +187,7 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {
highVisActivePref.isChecked = display.highVisActive
colorPref.colorValue = display.chartColor.let {
if (it == 0) {
resources.obtainTypedArray(R.array.chartColors).run {
val color = getColor(index, Color.WHITE)
recycle()
color
}
resources.obtainTypedArray(R.array.chartColors).getColor(index, Color.WHITE)
} else it
}
jsPref.setValue(display.customScript)
Expand Down Expand Up @@ -238,9 +230,7 @@ class SettingsPIDFragment: PreferenceFragmentCompat() {

val minVal = coerce(minValuePref.text, 0)
val maxVal = coerce(maxValuePref.text, 100)
var display = Display.newBuilder().setDisabled(
!enabledPref.isChecked
).setPid(
var display = Display.newBuilder().setPid(
pidPref.value
).setShowLabel(
showLabelPref.isChecked
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/aatorque/stats/TorqueData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ 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: 0 additions & 2 deletions app/src/main/java/com/aatorque/stats/TorqueGauge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ 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: 0 additions & 1 deletion app/src/main/proto/user_prefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ enum MaxControl {
}

message Display {
bool disabled = 25;
string pid = 1;
bool showLabel = 2;
string label = 3;
Expand Down
27 changes: 11 additions & 16 deletions app/src/main/res/layout/fragment_gauge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,14 @@
<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"
android:visibility="@{visible ? View.VISIBLE : View.GONE}">
android:clipChildren="false">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfTop"
Expand All @@ -106,16 +101,16 @@
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}"
app:layout_constraintHeight="true"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintTop_toBottomOf="@{minMaxBelow ? @id/dial : LayoutParams.UNSET}"
app:layout_constraintBottom_toBottomOf="@{minMaxBelow ? @id/constraintWrapper : @id/dial}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:textSize="24sp"
android:typeface="@{font}"
android:visibility="@{showLimitBelow == MaxControl.OFF ? View.INVISIBLE : View.VISIBLE}"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@{minMaxBelow ? @id/constraintWrapper : @id/dial}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@{minMaxBelow ? @id/dial : LayoutParams.UNSET}" />

<TextView
android:id="@+id/textTitle"
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,4 @@
<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>
11 changes: 2 additions & 9 deletions app/src/main/res/xml/pid_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@
android:key="pidCategory"
android:enabled="false"
android:summary="@string/torque_waiting">
<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:key="pidList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:key="pidList"
android:persistent="false"
android:title="@string/pid"
android:persistent="false"
app:dialogTitle="@string/pid" />
</PreferenceCategory>
<CheckBoxPreference
Expand Down

0 comments on commit 6bbed4a

Please sign in to comment.