1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 02:16:48 +01:00

Fix imperial unit on steps charts

This commit is contained in:
José Rebelo 2024-11-15 23:16:40 +00:00
parent 9bd828814e
commit 87bc2e6ed7
3 changed files with 15 additions and 3 deletions

View File

@ -37,6 +37,7 @@ import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueFormatter;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
@ -132,7 +133,9 @@ public class StepsDailyFragment extends StepsFragment<StepsDailyFragment.StepsDa
));
steps.setText(String.format(String.valueOf(stepsData.todayStepsDay.steps)));
distance.setText(getString(R.string.steps_distance_unit, stepsData.todayStepsDay.distance));
final WorkoutValueFormatter valueFormatter = new WorkoutValueFormatter();
distance.setText(valueFormatter.formatValue(stepsData.todayStepsDay.distance, "km"));
// Chart
final List<LegendEntry> legendEntries = new ArrayList<>(1);

View File

@ -31,6 +31,7 @@ import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueFormatter;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
@ -177,9 +178,10 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
}
stepsChart.setData(barData);
stepsAvg.setText(String.format(String.valueOf(stepsData.stepsDailyAvg)));
distanceAvg.setText(getString(R.string.steps_distance_unit, stepsData.distanceDailyAvg));
final WorkoutValueFormatter valueFormatter = new WorkoutValueFormatter();
distanceAvg.setText(valueFormatter.formatValue(stepsData.distanceDailyAvg, "km"));
stepsTotal.setText(String.format(String.valueOf(stepsData.totalSteps)));
distanceTotal.setText(getString(R.string.steps_distance_unit, stepsData.totalDistance));
distanceTotal.setText(valueFormatter.formatValue(stepsData.totalDistance, "km"));
}
ValueFormatter getStepsChartDayValueFormatter(StepsPeriodFragment.StepsData stepsData) {

View File

@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.workouts;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_CM;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_KG;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_KILOMETERS;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_METERS;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_METERS_PER_SECOND;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SECONDS_PER_KM;
@ -106,6 +107,12 @@ public class WorkoutValueFormatter {
unit = "minutes_km";
}
break;
case UNIT_KILOMETERS:
if (units.equals(UNIT_IMPERIAL)) {
value = value * 0.621371D;
unit = "mi";
}
break;
case UNIT_METERS:
if (units.equals(UNIT_IMPERIAL)) {
value = value * 3.28084D;