From f05ddd2d2426ca2428d109ad4e3d67c60cac8ff7 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 20 Aug 2020 22:27:33 +0200 Subject: [PATCH] display swim style as string --- .../activities/ActivitySummaryDetail.java | 65 ++++++++++--------- .../huami/HuamiActivitySummaryParser.java | 29 ++++++++- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java index dce2de53d..836b21307 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java @@ -238,43 +238,48 @@ public class ActivitySummaryDetail extends AbstractGBActivity { fieldLayout.addView(label_row); for (int i = 0; i < innerList.length(); i++) { - JSONObject innerData = innerList.getJSONObject(i); - double value = innerData.getDouble("value"); - String unit = innerData.getString("unit"); - String name = innerData.getString("name"); - - if (!show_raw_data) { - //special casing here: - switch (unit) { - case "meters_second": - value = value * 3.6; - unit = "km_h"; - break; - case "seconds_m": - value = 3.6 / value; - unit = "minutes_km"; - break; - case "seconds_km": - value = value / 60; - unit = "minutes_km"; - break; - - } - } - TableRow field_row = new TableRow(ActivitySummaryDetail.this); - if (i % 2 == 0) field_row.setBackgroundColor(alternateColor); - TextView name_field = new TextView(ActivitySummaryDetail.this); TextView value_field = new TextView(ActivitySummaryDetail.this); name_field.setGravity(Gravity.START); value_field.setGravity(Gravity.END); - if (unit.equals("seconds") && !show_raw_data) { //rather then plain seconds, show formatted duration - value_field.setText(DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS)); - }else { - value_field.setText(String.format("%s %s", df.format(value), getStringResourceByName(unit))); + JSONObject innerData = innerList.getJSONObject(i); + String unit = innerData.getString("unit"); + String name = innerData.getString("name"); + if (!unit.equals("string")) { + double value = innerData.getDouble("value"); + + if (!show_raw_data) { + //special casing here: + switch (unit) { + case "meters_second": + value = value * 3.6; + unit = "km_h"; + break; + case "seconds_m": + value = 3.6 / value; + unit = "minutes_km"; + break; + case "seconds_km": + value = value / 60; + unit = "minutes_km"; + break; + + } + } + + if (unit.equals("seconds") && !show_raw_data) { //rather then plain seconds, show formatted duration + value_field.setText(DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS)); + } else { + value_field.setText(String.format("%s %s", df.format(value), getStringResourceByName(unit))); + } + } else { + value_field.setText(innerData.getString("value")); } + TableRow field_row = new TableRow(ActivitySummaryDetail.this); + if (i % 2 == 0) field_row.setBackgroundColor(alternateColor); + name_field.setText(getStringResourceByName(name)); TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1f); value_field.setLayoutParams(params); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiActivitySummaryParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiActivitySummaryParser.java index 22946787e..c627b0bb6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiActivitySummaryParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiActivitySummaryParser.java @@ -291,7 +291,22 @@ public class HuamiActivitySummaryParser implements ActivitySummaryParser { addSummaryData("averageLapPace", averageLapPace, "second"); addSummaryData("strokes", strokes, "strokes"); addSummaryData("swolfIndex", swolfIndex, "swolf_index"); - addSummaryData("swimStyle", swimStyle, "swim_style"); + String swimStyleName = "unknown"; // TODO: translate here or keep as string identifier here? + switch (swimStyle) { + case 1: + swimStyleName = "breaststroke"; + break; + case 2: + swimStyleName = "freestyle"; + break; + case 3: + swimStyleName = "backstroke"; + break; + case 4: + swimStyleName = "medley"; + break; + } + addSummaryData("swimStyle", swimStyleName); addSummaryData("laps", laps, "laps"); } @@ -311,4 +326,16 @@ public class HuamiActivitySummaryParser implements ActivitySummaryParser { } } } + + private void addSummaryData(String key, String value) { + if (key != null && !key.equals("") && value != null && !value.equals("")) { + try { + JSONObject innerData = new JSONObject(); + innerData.put("value", value); + innerData.put("unit", "string"); + summaryData.put(key, innerData); + } catch (JSONException ignore) { + } + } + } }