From 534d6d37a03697c1d923954a602f122b46d1a337 Mon Sep 17 00:00:00 2001 From: udisha0606 Date: Sun, 26 Nov 2023 16:22:21 -0500 Subject: [PATCH] Added toggle for moving speed --- .../opentracks/settings/PreferencesUtils.java | 8 ++++++ .../AggregatedStatisticsAdapter.java | 28 +++++++++++++++++++ src/main/res/values/settings.xml | 2 ++ .../res/xml/settings_aggregated_stats.xml | 5 ++++ 4 files changed, 43 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java index 2dceb27a8..8eb01895c 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java @@ -479,6 +479,14 @@ public static void setMaxSpeed(boolean value) { setBoolean(R.string.distance_preference_key, value); } + public static boolean shouldMovingSpeed() { + return getBoolean(R.string.moving_speed_preference_key, false); + } + + @VisibleForTesting + public static void setMovingSpeed(boolean value) { + setBoolean(R.string.moving_speed_preference_key, value); + } public static Distance getRecordingDistanceInterval() { return Distance.of(getInt(R.string.recording_distance_interval_key, getRecordingDistanceIntervalDefaultInternal())); } diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java index fcabf66e6..68f5a44ce 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java @@ -26,6 +26,8 @@ import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldElevationGain; import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldDistance; import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMaxSpeed; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMovingSpeed; +import static de.dennisguse.opentracks.settings.PreferencesUtils.setMovingSpeed; public class AggregatedStatisticsAdapter extends RecyclerView.Adapter { @@ -70,6 +72,12 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi else { viewHolder.setMaxSpeed(aggregatedStatistic, false); } + if(shouldMovingSpeed()){ + viewHolder.setMovingSpeed(aggregatedStatistic, true); + } + else { + viewHolder.setMovingSpeed(aggregatedStatistic, false); + } } else { viewHolder.setPace(aggregatedStatistic); } @@ -192,6 +200,26 @@ public void setMaxSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStati } + public void setMovingSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context); + if(visibility){ + if(aggregatedStatistic.getTrackStatistics().getMaxSpeed() ==null) + avgSpeed.setText("0.0"); + else + { + Pair parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed()); + avgSpeed.setText(parts.first); + avgSpeedUnit.setText(parts.second); + avgSpeedLabel.setText(context.getString(R.string.stats_max_speed)); + } + } + else{ + avgSpeed.setText(""); + avgSpeedUnit.setText(""); + avgSpeedLabel.setText(""); + } + + } public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) { setCommonValues(aggregatedStatistic); diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index e53b6ee7d..4af511fce 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -292,6 +292,8 @@ false DistancePreferenceKey MaxSpeedPreferenceKey + MovingSpeedPreferenceKey + Moving Speed false apiDashboardEnabledKey false diff --git a/src/main/res/xml/settings_aggregated_stats.xml b/src/main/res/xml/settings_aggregated_stats.xml index 9be87de54..23f067632 100644 --- a/src/main/res/xml/settings_aggregated_stats.xml +++ b/src/main/res/xml/settings_aggregated_stats.xml @@ -23,6 +23,11 @@ android:title="@string/settings_aggregated_stats"> android:key="@string/max_speed_preference_key" android:title="@string/stats_max_speed" /> + +