mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Huawei: Group pace values in activity summary pace group
This commit is contained in:
parent
83d2aaf30e
commit
88a1e7bb59
@ -129,4 +129,6 @@ public class ActivitySummaryEntries {
|
||||
public static final String UNIT_STROKES_PER_SECOND = "strokes_second";
|
||||
public static final String UNIT_YARD = "yard";
|
||||
public static final String UNIT_DEGREES = "degrees";
|
||||
|
||||
public static final String GROUP_PACE = "Pace";
|
||||
}
|
||||
|
@ -123,7 +123,13 @@ public class ActivitySummaryJsonSummary {
|
||||
|
||||
if (summaryDatalist == null) return null;
|
||||
Iterator<String> keys = summaryDatalist.keys();
|
||||
Map<String, JSONArray> activeGroups = new HashMap<>();
|
||||
|
||||
final Map<String, JSONArray> activeGroups = new LinkedHashMap<>();
|
||||
// Initialize activeGroups with the initial expected order and empty arrays
|
||||
final Iterator<String> names = this.groupData.keys();
|
||||
while (names.hasNext()) {
|
||||
activeGroups.put(names.next(), new JSONArray());
|
||||
}
|
||||
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
@ -131,10 +137,12 @@ public class ActivitySummaryJsonSummary {
|
||||
JSONObject innerData = (JSONObject) summaryDatalist.get(key);
|
||||
Object value = innerData.get("value");
|
||||
String unit = innerData.getString("unit");
|
||||
String groupName = getGroup(key);
|
||||
// Use the group if specified in the entry, otherwise fallback to the array below
|
||||
String groupName = innerData.optString("group", getGroup(key));
|
||||
|
||||
JSONArray group = activeGroups.get(groupName);
|
||||
if (group == null) {
|
||||
// This group is not defined in createActivitySummaryGroups - add it to the end
|
||||
group = new JSONArray();
|
||||
activeGroups.put(groupName, group);
|
||||
}
|
||||
@ -149,18 +157,18 @@ public class ActivitySummaryJsonSummary {
|
||||
}
|
||||
}
|
||||
|
||||
// Reorder collected groups according to the order set by this.groupData.
|
||||
JSONObject grouped = new JSONObject();
|
||||
Iterator<String> names = this.groupData.keys();
|
||||
while(names.hasNext()) {
|
||||
String groupName = names.next();
|
||||
JSONArray group = activeGroups.get(groupName);
|
||||
if (group != null) {
|
||||
try {
|
||||
grouped.put(groupName, group);
|
||||
} catch (JSONException e) {
|
||||
LOG.error("SportsActivity internal error building grouped summary", e);
|
||||
}
|
||||
// Convert activeGroups to the expected JSONObject
|
||||
// activeGroups is already ordered
|
||||
final JSONObject grouped = new JSONObject();
|
||||
for (final Map.Entry<String, JSONArray> entry : activeGroups.entrySet()) {
|
||||
if (entry.getValue().length() == 0) {
|
||||
// empty group
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
grouped.put(entry.getKey(), entry.getValue());
|
||||
} catch (JSONException e) {
|
||||
LOG.error("SportsActivity internal error building grouped summary", e);
|
||||
}
|
||||
}
|
||||
return grouped;
|
||||
@ -223,6 +231,8 @@ public class ActivitySummaryJsonSummary {
|
||||
put("laps", Arrays.asList(
|
||||
LAP_PACE_AVERAGE, LAPS, LANE_LENGTH
|
||||
));
|
||||
put("Pace", Arrays.asList(
|
||||
));
|
||||
put("RunningForm", Arrays.asList(
|
||||
GROUND_CONTACT_TIME_AVG, IMPACT_AVG, IMPACT_MAX, SWING_ANGLE_AVG,
|
||||
FORE_FOOT_LANDINGS, MID_FOOT_LANDINGS, BACK_FOOT_LANDINGS,
|
||||
|
@ -559,22 +559,26 @@ public class HuaweiWorkoutGbParser {
|
||||
JSONObject paceDistance = new JSONObject();
|
||||
paceDistance.put("value", sample.getDistance());
|
||||
paceDistance.put("unit", ActivitySummaryEntries.UNIT_KILOMETERS);
|
||||
paceDistance.put("group", ActivitySummaryEntries.GROUP_PACE);
|
||||
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceDistance), index), paceDistance);
|
||||
|
||||
JSONObject paceType = new JSONObject();
|
||||
paceType.put("value", sample.getType());
|
||||
paceType.put("unit", ""); // TODO: find out types
|
||||
paceType.put("group", ActivitySummaryEntries.GROUP_PACE);
|
||||
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceType), index), paceType);
|
||||
|
||||
JSONObject pacePace = new JSONObject();
|
||||
pacePace.put("value", sample.getPace());
|
||||
pacePace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM);
|
||||
pacePace.put("group", ActivitySummaryEntries.GROUP_PACE);
|
||||
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPacePace), index), pacePace);
|
||||
|
||||
if (sample.getCorrection() != 0) {
|
||||
JSONObject paceCorrection = new JSONObject();
|
||||
paceCorrection.put("value", sample.getCorrection() / 10);
|
||||
paceCorrection.put("unit", ActivitySummaryEntries.UNIT_METERS);
|
||||
paceCorrection.put("group", ActivitySummaryEntries.GROUP_PACE);
|
||||
jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceCorrection), index), paceCorrection);
|
||||
}
|
||||
}
|
||||
@ -587,6 +591,7 @@ public class HuaweiWorkoutGbParser {
|
||||
JSONObject avgPace = new JSONObject();
|
||||
avgPace.put("value", pace / count);
|
||||
avgPace.put("unit", ActivitySummaryEntries.UNIT_SECONDS_PER_KM);
|
||||
avgPace.put("group", ActivitySummaryEntries.GROUP_PACE);
|
||||
jsonObject.put(String.format(GBApplication.getContext().getString(R.string.fmtPaceTypeAverage), key), avgPace);
|
||||
}
|
||||
}
|
||||
|
@ -1927,6 +1927,7 @@
|
||||
<string name="km">km</string>
|
||||
<string name="mi">mi</string>
|
||||
<string name="degrees">degrees</string>
|
||||
<string name="Pace">Pace</string>
|
||||
<!-- activity summary groups-->
|
||||
<string name="Strokes">Strokes</string>
|
||||
<string name="Swimming">Swimming</string>
|
||||
|
Loading…
Reference in New Issue
Block a user