From fd3a725b102a78f9fb2632c72dfbe8d5eece9d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Fri, 4 Oct 2024 20:08:05 +0100 Subject: [PATCH] Huawei: Format pace values in a table --- .../devices/huawei/HuaweiWorkoutGbParser.java | 72 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java index 8a9ac1cf9..c173bcb21 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java @@ -22,15 +22,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Optional; import de.greenrobot.dao.query.CloseableListIterator; import de.greenrobot.dao.query.QueryBuilder; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry; +import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Workout; @@ -647,6 +653,23 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser { } } + final LinkedHashMap pacesTable = new LinkedHashMap<>(); + + pacesTable.put("paces_table", + new ActivitySummaryTableRowEntry( + ActivitySummaryEntries.GROUP_PACE, + Arrays.asList( + new ActivitySummaryValue("#", ActivitySummaryEntries.UNIT_RAW_STRING), + new ActivitySummaryValue("distance"), + new ActivitySummaryValue("watchface_dialog_widget_type"), + new ActivitySummaryValue("Pace"), + new ActivitySummaryValue("paceCorrection") + ), + true, + true + ) + ); + try (CloseableListIterator it = qbPace.build().listIterator()) { HashMap typeCount = new HashMap<>(); HashMap typePace = new HashMap<>(); @@ -667,34 +690,31 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser { typeCount.put(sample.getType(), count); typePace.put(sample.getType(), pace); - summaryData.add( - ActivitySummaryEntries.GROUP_PACE, - GBApplication.getContext().getString(R.string.fmtPaceDistance, index), - sample.getDistance(), - ActivitySummaryEntries.UNIT_KILOMETERS - ); - - summaryData.add( - ActivitySummaryEntries.GROUP_PACE, - GBApplication.getContext().getString(R.string.fmtPaceType, index), - sample.getType(), - ActivitySummaryEntries.UNIT_NONE // TODO: find out types - ); - - summaryData.add( - ActivitySummaryEntries.GROUP_PACE, - GBApplication.getContext().getString(R.string.fmtPacePace, index), - sample.getPace(), - ActivitySummaryEntries.UNIT_SECONDS_PER_KM - ); + final List columns = new LinkedList<>(); + columns.add(new ActivitySummaryValue(index, ActivitySummaryEntries.UNIT_NONE)); + columns.add(new ActivitySummaryValue(sample.getDistance(), ActivitySummaryEntries.UNIT_KILOMETERS)); + columns.add(new ActivitySummaryValue(sample.getType(), ActivitySummaryEntries.UNIT_NONE)); // TODO: find out types + columns.add(new ActivitySummaryValue(sample.getPace(), ActivitySummaryEntries.UNIT_SECONDS_PER_KM)); if (sample.getCorrection() != 0) { - summaryData.add( - ActivitySummaryEntries.GROUP_PACE, - GBApplication.getContext().getString(R.string.fmtPaceCorrection, index), - sample.getCorrection() / 10f, - ActivitySummaryEntries.UNIT_METERS - ); + columns.add(new ActivitySummaryValue(sample.getCorrection() / 10f, ActivitySummaryEntries.UNIT_METERS)); + } else { + columns.add(new ActivitySummaryValue("stats_empty_value")); + } + + pacesTable.put("paces_table_" + index, + new ActivitySummaryTableRowEntry( + ActivitySummaryEntries.GROUP_PACE, + columns, + false, + true + ) + ); + } + + if (pacesTable.size() > 1) { + for (final Map.Entry e : pacesTable.entrySet()) { + summaryData.add(e.getKey(), e.getValue()); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 28e777822..47e471891 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2228,6 +2228,7 @@ Pace %d type Pace %d pace Pace %d correction + Correction Pace Type %d average Unknown data encountered Average cycling power