From 44d6ce094a388a7c6b653786f978eb1972576d96 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Fri, 1 Dec 2023 14:09:56 -0500 Subject: [PATCH] Allow fused altimeter recalibration interval to be changed Closes #2085 --- .../ui/CalibrateAltimeterFragment.kt | 32 ++++++++++++++++++- .../infrastructure/AltimeterPreferences.kt | 2 +- app/src/main/res/values/strings.xml | 6 +++- .../main/res/xml/altimeter_calibration.xml | 6 ++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/calibration/ui/CalibrateAltimeterFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/calibration/ui/CalibrateAltimeterFragment.kt index 8145f6952..e68b1cc84 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/calibration/ui/CalibrateAltimeterFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/calibration/ui/CalibrateAltimeterFragment.kt @@ -56,6 +56,7 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() { private lateinit var accuracyPref: Preference private lateinit var clearCachePref: Preference private lateinit var continuousCalibrationPref: SwitchPreferenceCompat + private lateinit var forceCalibrationPref: Preference private lateinit var lastMode: UserPreferences.AltimeterMode private val updateTimer = CoroutineTimer { updateAltitude() } @@ -90,6 +91,7 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() { accuracyPref = preference(R.string.pref_altimeter_accuracy_holder)!! clearCachePref = preference(R.string.pref_altimeter_clear_cache_holder)!! continuousCalibrationPref = switch(R.string.pref_altimeter_continuous_calibration)!! + forceCalibrationPref = preference(R.string.pref_fused_altimeter_force_calibration_holder)!! val altitudeOverride = Distance.meters(prefs.altitudeOverride).convertTo(distanceUnits) altitudeOverridePref.summary = formatService.formatDistance(altitudeOverride) @@ -153,6 +155,12 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() { restartAltimeter() } + onClick(forceCalibrationPref) { + updateForceCalibrationInterval() + } + + updateForceCalibrationIntervalSummary() + // Update the altitude override to the current altitude if (prefs.altimeterMode == UserPreferences.AltimeterMode.Barometer) { updateAltitudeOverride() @@ -165,11 +173,13 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() { val hasBarometer = prefs.weather.hasBarometer val mode = prefs.altimeterMode - // Cache and continuous calibration are only available on the fused barometer + // Cache, continuous calibration, and force calibration interval are only available on the fused barometer clearCachePref.isVisible = hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer continuousCalibrationPref.isVisible = hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer + forceCalibrationPref.isVisible = + hasBarometer && mode == UserPreferences.AltimeterMode.GPSBarometer // Overrides are available on the barometer or the manual mode val canProvideOverrides = @@ -292,6 +302,26 @@ class CalibrateAltimeterFragment : AndromedaPreferenceFragment() { } } + private fun updateForceCalibrationInterval() { + CustomUiUtils.pickDuration( + requireContext(), + prefs.altimeter.fusedAltimeterForcedRecalibrationInterval, + getString(R.string.fused_altimeter_force_calibration) + ) { + if (it != null) { + prefs.altimeter.fusedAltimeterForcedRecalibrationInterval = it + updateForceCalibrationIntervalSummary() + } + } + } + + private fun updateForceCalibrationIntervalSummary() { + val interval = + formatService.formatDuration(prefs.altimeter.fusedAltimeterForcedRecalibrationInterval) + forceCalibrationPref.summary = + getString(R.string.fused_altimeter_force_calibration_summary, interval) + } + private fun updateAltitude(): Boolean { if (throttle.isThrottled()) { return true diff --git a/app/src/main/java/com/kylecorry/trail_sense/settings/infrastructure/AltimeterPreferences.kt b/app/src/main/java/com/kylecorry/trail_sense/settings/infrastructure/AltimeterPreferences.kt index 049c46968..c76da90d8 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/settings/infrastructure/AltimeterPreferences.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/settings/infrastructure/AltimeterPreferences.kt @@ -14,7 +14,7 @@ class AltimeterPreferences(context: Context) : PreferenceRepo(context) { false ) - val fusedAltimeterForcedRecalibrationInterval by DurationPreference( + var fusedAltimeterForcedRecalibrationInterval by DurationPreference( cache, context.getString(R.string.pref_altimeter_forced_recalibration_interval), Duration.ofHours(1) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index faf6fd790..d7af28e5f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -863,7 +863,7 @@ Weight per item Create packing lists Humidity - + Your device does not have a %s sensor %d satellites WGS 84 @@ -1382,6 +1382,10 @@ Restart services Background services could not be restarted. Tap to restart. pref_altimeter_forced_recalibration_interval + Force calibration interval + pref_fused_altimeter_force_calibration_holder + + Forces a GPS calibration every %s %d map %d maps diff --git a/app/src/main/res/xml/altimeter_calibration.xml b/app/src/main/res/xml/altimeter_calibration.xml index 0cc4677a6..63ec53fa9 100644 --- a/app/src/main/res/xml/altimeter_calibration.xml +++ b/app/src/main/res/xml/altimeter_calibration.xml @@ -46,6 +46,12 @@ app:singleLineTitle="false" app:title="@string/elevation_from_pressure" /> + +