mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Sport Activity Summary: fix group order instability
Previously group order was determined on the fly by available entries order or appearance. This commit changes it to use group definition order.
This commit is contained in:
parent
9095ffad8b
commit
414cf5e472
@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -120,9 +121,9 @@ public class ActivitySummaryJsonSummary {
|
|||||||
private JSONObject setSummaryGroupedList(JSONObject summaryDatalist){
|
private JSONObject setSummaryGroupedList(JSONObject summaryDatalist){
|
||||||
this.groupData = createActivitySummaryGroups(); //structure for grouping activities into groups, when vizualizing
|
this.groupData = createActivitySummaryGroups(); //structure for grouping activities into groups, when vizualizing
|
||||||
|
|
||||||
if (summaryDatalist ==null ) return null;
|
if (summaryDatalist == null) return null;
|
||||||
Iterator<String> keys = summaryDatalist.keys();
|
Iterator<String> keys = summaryDatalist.keys();
|
||||||
JSONObject list=new JSONObject();
|
Map<String, JSONArray> activeGroups = new HashMap<>();
|
||||||
|
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
@ -130,27 +131,43 @@ public class ActivitySummaryJsonSummary {
|
|||||||
JSONObject innerData = (JSONObject) summaryDatalist.get(key);
|
JSONObject innerData = (JSONObject) summaryDatalist.get(key);
|
||||||
Object value = innerData.get("value");
|
Object value = innerData.get("value");
|
||||||
String unit = innerData.getString("unit");
|
String unit = innerData.getString("unit");
|
||||||
String group = getGroup(key);
|
String groupName = getGroup(key);
|
||||||
|
|
||||||
if (!list.has(group)) {
|
JSONArray group = activeGroups.get(groupName);
|
||||||
list.put(group,new JSONArray());
|
if (group == null) {
|
||||||
|
group = new JSONArray();
|
||||||
|
activeGroups.put(groupName, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray tmpl = (JSONArray) list.get(group);
|
JSONObject item = new JSONObject();
|
||||||
JSONObject innernew = new JSONObject();
|
item.put("name", key);
|
||||||
innernew.put("name", key);
|
item.put("value", value);
|
||||||
innernew.put("value", value);
|
item.put("unit", unit);
|
||||||
innernew.put("unit", unit);
|
group.put(item);
|
||||||
tmpl.put(innernew);
|
|
||||||
list.put(group, tmpl);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOG.error("SportsActivity", e);
|
LOG.error("SportsActivity internal error building grouped summary", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getGroup(String searchItem) {
|
private String getGroup(String searchItem) {
|
||||||
|
// NB: Default group must be present in group JSONObject created by createActivitySummaryGroups
|
||||||
String defaultGroup = "Activity";
|
String defaultGroup = "Activity";
|
||||||
if (groupData == null) return defaultGroup;
|
if (groupData == null) return defaultGroup;
|
||||||
Iterator<String> keys = groupData.keys();
|
Iterator<String> keys = groupData.keys();
|
||||||
@ -170,31 +187,33 @@ public class ActivitySummaryJsonSummary {
|
|||||||
return defaultGroup;
|
return defaultGroup;
|
||||||
}
|
}
|
||||||
private JSONObject createActivitySummaryGroups(){
|
private JSONObject createActivitySummaryGroups(){
|
||||||
final Map<String, List<String>> groupDefinitions = new HashMap<String, List<String>>() {{
|
final Map<String, List<String>> groupDefinitions = new LinkedHashMap<String, List<String>>() {{
|
||||||
put("Strokes", Arrays.asList(
|
// NB: Default group Activity must be present in this definition, otherwise it wouldn't
|
||||||
STROKE_DISTANCE_AVG, STROKE_AVG_PER_SECOND, STROKES,
|
// be shown.
|
||||||
STROKE_RATE_AVG, STROKE_RATE_MAX
|
put("Activity", Arrays.asList(
|
||||||
|
DISTANCE_METERS, STEPS, ACTIVE_SECONDS, CALORIES_BURNT, STRIDE_TOTAL,
|
||||||
|
HR_AVG, HR_MAX, HR_MIN, STRIDE_AVG, STRIDE_MAX, STRIDE_MIN
|
||||||
));
|
));
|
||||||
put("Swimming", Arrays.asList(
|
put("Speed", Arrays.asList(
|
||||||
SWOLF_INDEX, SWIM_STYLE
|
SPEED_AVG, SPEED_MAX, SPEED_MIN, PACE_AVG_SECONDS_KM, PACE_MIN,
|
||||||
|
PACE_MAX, "averageSpeed2", CADENCE_AVG, CADENCE_MAX, CADENCE_MIN
|
||||||
));
|
));
|
||||||
put("Elevation", Arrays.asList(
|
put("Elevation", Arrays.asList(
|
||||||
ASCENT_METERS, DESCENT_METERS, ALTITUDE_MAX, ALTITUDE_MIN, ALTITUDE_AVG,
|
ASCENT_METERS, DESCENT_METERS, ALTITUDE_MAX, ALTITUDE_MIN, ALTITUDE_AVG,
|
||||||
ALTITUDE_BASE, ASCENT_SECONDS, DESCENT_SECONDS, FLAT_SECONDS, ASCENT_DISTANCE,
|
ALTITUDE_BASE, ASCENT_SECONDS, DESCENT_SECONDS, FLAT_SECONDS, ASCENT_DISTANCE,
|
||||||
DESCENT_DISTANCE, FLAT_DISTANCE, ELEVATION_GAIN, ELEVATION_LOSS
|
DESCENT_DISTANCE, FLAT_DISTANCE, ELEVATION_GAIN, ELEVATION_LOSS
|
||||||
));
|
));
|
||||||
put("Speed", Arrays.asList(
|
|
||||||
SPEED_AVG, SPEED_MAX, SPEED_MIN, PACE_AVG_SECONDS_KM, PACE_MIN,
|
|
||||||
PACE_MAX, "averageSpeed2", CADENCE_AVG, CADENCE_MAX, CADENCE_MIN
|
|
||||||
));
|
|
||||||
put("Activity", Arrays.asList(
|
|
||||||
DISTANCE_METERS, STEPS, ACTIVE_SECONDS, CALORIES_BURNT, STRIDE_TOTAL,
|
|
||||||
HR_AVG, HR_MAX, HR_MIN, STRIDE_AVG, STRIDE_MAX, STRIDE_MIN
|
|
||||||
));
|
|
||||||
put("HeartRateZones", Arrays.asList(
|
put("HeartRateZones", Arrays.asList(
|
||||||
HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC,
|
HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC,
|
||||||
HR_ZONE_EXTREME
|
HR_ZONE_EXTREME
|
||||||
));
|
));
|
||||||
|
put("Strokes", Arrays.asList(
|
||||||
|
STROKE_DISTANCE_AVG, STROKE_AVG_PER_SECOND, STROKES,
|
||||||
|
STROKE_RATE_AVG, STROKE_RATE_MAX
|
||||||
|
));
|
||||||
|
put("Swimming", Arrays.asList(
|
||||||
|
SWOLF_INDEX, SWIM_STYLE
|
||||||
|
));
|
||||||
put("TrainingEffect", Arrays.asList(
|
put("TrainingEffect", Arrays.asList(
|
||||||
TRAINING_EFFECT_AEROBIC, TRAINING_EFFECT_ANAEROBIC, WORKOUT_LOAD,
|
TRAINING_EFFECT_AEROBIC, TRAINING_EFFECT_ANAEROBIC, WORKOUT_LOAD,
|
||||||
MAXIMUM_OXYGEN_UPTAKE
|
MAXIMUM_OXYGEN_UPTAKE
|
||||||
|
Loading…
Reference in New Issue
Block a user