From 042d75ce5f58a795a7b1d0cb2e7413aae467527f Mon Sep 17 00:00:00 2001 From: raghavmanchanda2 Date: Thu, 23 Nov 2023 14:31:28 -0500 Subject: [PATCH] [Issue-258][SubTask-3][Add toggle Distance in the aggregated stats option under settings][Fixed ByRaghav-40276920] --- .../opentracks/settings/PreferencesUtils.java | 10 ++++++ .../AggregatedStatisticsAdapter.java | 32 +++++++++++++++++++ src/main/res/values/settings.xml | 1 + .../res/xml/settings_aggregated_stats.xml | 4 +++ 4 files changed, 47 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java index 192bf533d..af171efd3 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java @@ -460,6 +460,16 @@ public static void setElevationGain(boolean value) { setBoolean(R.string.aggregated_stats_package_key, value); } + public static boolean shouldDistance() { + Log.d("myLogs", String.valueOf(R.string.distance_preference_key)); + return getBoolean(R.string.distance_preference_key, false); + } + + @VisibleForTesting + public static void setDistance(boolean value) { + setBoolean(R.string.distance_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 0ee06cd4c..1d5c29fc2 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java @@ -1,6 +1,7 @@ package de.dennisguse.opentracks.ui.aggregatedStatistics; import android.content.Context; +import android.util.Log; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -23,6 +24,7 @@ import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.StringUtils; import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldElevationGain; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldDistance; public class AggregatedStatisticsAdapter extends RecyclerView.Adapter { @@ -53,6 +55,14 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi if(shouldElevationGain()) { viewHolder.setElevation(aggregatedStatistic); } + if(shouldDistance()) { + Log.d("myLogs", "ShouldDistance is called"); + viewHolder.setDistance(aggregatedStatistic, true); + } + else { + Log.d("myLogs", "Inside Else"); + viewHolder.setDistance(aggregatedStatistic, false); + } } else { viewHolder.setPace(aggregatedStatistic); } @@ -131,6 +141,28 @@ public void setElevation(AggregatedStatistics.AggregatedStatistic aggregatedStat elevationGain.setText(aggregatedStatistic.getTrackStatistics().getTotalAltitudeGain().toString()); System.out.println(); } + + public void setDistance(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + if(visibility) { + if (aggregatedStatistic.getTrackStatistics().getTotalDistance() == null) { + Log.d("myLogs", "aggregate value is null"); + distance.setText("0.0"); + } else { + Log.d("myLogs", "Visibility true, setting value in else"); + Pair parts = DistanceFormatter.Builder() + .setUnit(unitSystem) + .build(context).getDistanceParts(aggregatedStatistic.getTrackStatistics().getTotalDistance()); + distance.setText(parts.first); + distanceUnit.setText(parts.second); + } + } + else{ + Log.d("myLogs", "Visibility is false"); + distance.setText(""); + distanceUnit.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 b63b107f8..8243c56f5 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -290,6 +290,7 @@ apiEnabledKey AggregatedStatsPackageKey false + DistancePreferenceKey false apiDashboardEnabledKey false diff --git a/src/main/res/xml/settings_aggregated_stats.xml b/src/main/res/xml/settings_aggregated_stats.xml index 15b09bc83..9eeb1b5dc 100644 --- a/src/main/res/xml/settings_aggregated_stats.xml +++ b/src/main/res/xml/settings_aggregated_stats.xml @@ -14,6 +14,10 @@ android:title="@string/settings_aggregated_stats"> android:defaultValue="false" android:key="@string/aggregated_stats_package_key" android:title="@string/settings_elevation_gain" /> +