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

Commit

Permalink
Issue 259- Subtask 4: Add toggle “Max Speed” in the aggregated stats …
Browse files Browse the repository at this point in the history
…option under settings.
  • Loading branch information
bhavya-bugude committed Nov 23, 2023
1 parent 042d75c commit 7078064
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ public static void setDistance(boolean value) {
setBoolean(R.string.distance_preference_key, value);
}

public static boolean shouldMaxSpeed() {
return getBoolean(R.string.max_speed_preference_key, false);
}

@VisibleForTesting
public static void setMaxSpeed(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
Expand Up @@ -25,6 +25,7 @@
import de.dennisguse.opentracks.util.StringUtils;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldElevationGain;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldDistance;
import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMaxSpeed;

public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

Expand Down Expand Up @@ -63,6 +64,12 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
Log.d("myLogs", "Inside Else");
viewHolder.setDistance(aggregatedStatistic, false);
}
if(shouldMaxSpeed()) {
viewHolder.setMaxSpeed(aggregatedStatistic, true);
}
else {
viewHolder.setMaxSpeed(aggregatedStatistic, false);
}
} else {
viewHolder.setPace(aggregatedStatistic);
}
Expand Down Expand Up @@ -163,6 +170,28 @@ public void setDistance(AggregatedStatistics.AggregatedStatistic aggregatedStati
}
}

public void setMaxSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) {
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context);
if(visibility){
if(aggregatedStatistic.getTrackStatistics().getMaxSpeed() ==null)
maxSpeed.setText("0.0");

else
{
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed());
maxSpeed.setText(parts.first);
maxSpeedUnit.setText(parts.second);
maxSpeedLabel.setText(context.getString(R.string.stats_max_speed));
}
}
else{
maxSpeed.setText("");
maxSpeedUnit.setText("");
maxSpeedLabel.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 @@ -291,6 +291,7 @@
<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>
<string name="max_speed_preference_key" translatable="false">MaxSpeedPreferenceKey</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 @@ -18,6 +18,10 @@ android:title="@string/settings_aggregated_stats">
android:defaultValue="false"
android:key="@string/distance_preference_key"
android:title="@string/stats_distance" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/max_speed_preference_key"
android:title="@string/stats_max_speed" />

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

0 comments on commit 7078064

Please sign in to comment.