From 5e721f0f7d7cb908065a02ab6ee40c226bfbf510 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 24 Feb 2026 20:25:21 +0100 Subject: [PATCH] lib/TwoContentDescriptions: new class I used this class to display a gauge that shows the (instantaneous) power measurement, and additionally it shows the average power over the last 10 minutes in the small bottom line. This class isn't currently used anywhere, but we may add a user once cockpits are configurable. --- .../IndexedAttributeDescription.kt | 6 +++ .../description/TwoContentDescriptions.kt | 53 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 aat-lib/src/main/java/ch/bailu/aat_lib/description/TwoContentDescriptions.kt diff --git a/aat-lib/src/main/java/ch/bailu/aat_lib/description/IndexedAttributeDescription.kt b/aat-lib/src/main/java/ch/bailu/aat_lib/description/IndexedAttributeDescription.kt index 514014e4f..c7afc6850 100644 --- a/aat-lib/src/main/java/ch/bailu/aat_lib/description/IndexedAttributeDescription.kt +++ b/aat-lib/src/main/java/ch/bailu/aat_lib/description/IndexedAttributeDescription.kt @@ -69,4 +69,10 @@ open class IndexedAttributeDescription( PowerDescription.UNIT, TimeWindowAttributes.INDEX_WINDOW_POWER ) + + class _WindowPower : IndexedAttributeDescription( + "10'", + PowerDescription.UNIT, + TimeWindowAttributes.INDEX_WINDOW_POWER + ) } diff --git a/aat-lib/src/main/java/ch/bailu/aat_lib/description/TwoContentDescriptions.kt b/aat-lib/src/main/java/ch/bailu/aat_lib/description/TwoContentDescriptions.kt new file mode 100644 index 000000000..5ecd7756b --- /dev/null +++ b/aat-lib/src/main/java/ch/bailu/aat_lib/description/TwoContentDescriptions.kt @@ -0,0 +1,53 @@ +package ch.bailu.aat_lib.description + +import ch.bailu.aat_lib.gpx.information.GpxInformation +import ch.bailu.aat_lib.gpx.information.InfoID + +/** + * Composite that delegates to two [ContentDescription] instances. + * + * [getValue]/[getLabel] expose the first description; [getUnit] merges the + * second description's label and value with the first's unit + * ("secondLabel: secondValue firstUnit"). Both descriptions receive every + * [onContentUpdated] call so they stay in sync. + * + * When the two sub-descriptions need different [InfoID] updates (e.g. + * [PowerDescription] needs POWER_SENSOR while a window-power description + * needs TRACKER), pass [firstIid]/[secondIid] to filter updates per + * sub-description. [InfoID.ALL] (the default) disables filtering. + */ +class TwoContentDescriptions( + private val first: ContentDescription, + private val second: ContentDescription, + private val firstIid: Int = InfoID.ALL, + private val secondIid: Int = InfoID.ALL +) : ContentDescription() { + override fun getValue(): String { + return first.getValue() + } + + override fun getLabel(): String { + return first.getLabel() + } + + override fun getUnit(): String { + val value = second.getValue() + val unit = first.getUnit() + + if (value == "") + /* there is no secondary value: show just the unit */ + return unit + + /* there is a secondary value: show the second label, value and + the unit in the bottom row */ + var label = second.getLabel() + return "$label: $value $unit" } + + override fun onContentUpdated(iid: Int, info: GpxInformation) { + if (firstIid == InfoID.ALL || iid == firstIid) + first.onContentUpdated(iid, info) + + if (secondIid == InfoID.ALL || iid == secondIid) + second.onContentUpdated(iid, info) + } +}