Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
[Issue-258][SubTask-3][Add toggle Distance in the aggregated stats op…
Browse files Browse the repository at this point in the history
…tion under settings][Fixed ByRaghav-40276920]
  • Loading branch information
raghavmanchanda2 committed Nov 23, 2023
1 parent 077b5de commit 042d75c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<RecyclerView.ViewHolder> {

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<String, String> 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);

Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<string name="publicapi_enabled_key" translatable="false">apiEnabledKey</string>
<string name="aggregated_stats_package_key" translatable="false">AggregatedStatsPackageKey</string>
<bool name="aggregated_stats_enabled_default">false</bool>
<string name="distance_preference_key" translatable="false">DistancePreferenceKey</string>
<bool name="publicapi_enabled_default">false</bool>
<string name="publicapi_dashboard_enabled_key" translatable="false">apiDashboardEnabledKey</string>
<bool name="publicapi_dashboard_enabled_default">false</bool>
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/xml/settings_aggregated_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/distance_preference_key"
android:title="@string/stats_distance" />

<!--<SwitchPreferenceCompat-->
<!-- android:title="@string/settings_public_api_dashboard_enabled_title"-->
Expand Down

0 comments on commit 042d75c

Please sign in to comment.