1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-22 14:52:25 +02:00

Huawei Workout use translatable strings

This commit is contained in:
Martin.JM 2024-03-21 09:25:11 +01:00
parent e8ddc1fd17
commit e9090ec082
2 changed files with 91 additions and 61 deletions

View File

@ -29,6 +29,7 @@ import java.util.ListIterator;
import de.greenrobot.dao.query.QueryBuilder; import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Workout; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Workout;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
@ -197,8 +198,7 @@ public class HuaweiWorkoutGbParser {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
// TODO: Use translatable strings // The first few should get auto translated in ActivitySummariesAdapter:fill_dashboard
JSONObject calories = new JSONObject(); JSONObject calories = new JSONObject();
calories.put("value", summary.getCalories()); calories.put("value", summary.getCalories());
calories.put("unit", "calories_unit"); calories.put("unit", "calories_unit");
@ -222,46 +222,46 @@ public class HuaweiWorkoutGbParser {
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
status.put("value", summary.getStatus() & 0xFF); status.put("value", summary.getStatus() & 0xFF);
status.put("unit", ""); status.put("unit", "");
jsonObject.put("Status", status); jsonObject.put(GBApplication.getContext().getString(R.string.status), status);
JSONObject typeJson = new JSONObject(); JSONObject typeJson = new JSONObject();
typeJson.put("value", summary.getType() & 0xFF); typeJson.put("value", summary.getType() & 0xFF);
typeJson.put("unit", ""); typeJson.put("unit", "");
jsonObject.put("Type", typeJson); jsonObject.put(GBApplication.getContext().getString(R.string.watchface_dialog_widget_type), typeJson);
if (summary.getStrokes() != -1) { if (summary.getStrokes() != -1) {
JSONObject strokesJson = new JSONObject(); JSONObject strokesJson = new JSONObject();
strokesJson.put("value", summary.getStrokes()); strokesJson.put("value", summary.getStrokes());
strokesJson.put("unit", ""); strokesJson.put("unit", GBApplication.getContext().getString(R.string.strokes_unit));
jsonObject.put("Strokes", strokesJson); jsonObject.put(GBApplication.getContext().getString(R.string.Strokes), strokesJson);
} }
if (summary.getAvgStrokeRate() != -1) { if (summary.getAvgStrokeRate() != -1) {
JSONObject avgStrokeRateJson = new JSONObject(); JSONObject avgStrokeRateJson = new JSONObject();
avgStrokeRateJson.put("value", summary.getAvgStrokeRate()); avgStrokeRateJson.put("value", summary.getAvgStrokeRate());
avgStrokeRateJson.put("unit", ""); avgStrokeRateJson.put("unit", ""); // TODO: find out unit
jsonObject.put("Average reported stroke rate", avgStrokeRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.avgStrokeRate), avgStrokeRateJson);
} }
if (summary.getPoolLength() != -1) { if (summary.getPoolLength() != -1) {
JSONObject poolLengthJson = new JSONObject(); JSONObject poolLengthJson = new JSONObject();
poolLengthJson.put("value", summary.getPoolLength()); poolLengthJson.put("value", summary.getPoolLength());
poolLengthJson.put("unit", "cm"); poolLengthJson.put("unit", GBApplication.getContext().getString(R.string.cm));
jsonObject.put("Pool length", poolLengthJson); jsonObject.put(GBApplication.getContext().getString(R.string.laneLength), poolLengthJson);
} }
if (summary.getLaps() != -1) { if (summary.getLaps() != -1) {
JSONObject lapsJson = new JSONObject(); JSONObject lapsJson = new JSONObject();
lapsJson.put("value", summary.getLaps()); lapsJson.put("value", summary.getLaps());
lapsJson.put("unit", ""); lapsJson.put("unit", GBApplication.getContext().getString(R.string.laps_unit));
jsonObject.put("Laps", lapsJson); jsonObject.put(GBApplication.getContext().getString(R.string.laps), lapsJson);
} }
if (summary.getAvgSwolf() != -1) { if (summary.getAvgSwolf() != -1) {
JSONObject avgSwolfJson = new JSONObject(); JSONObject avgSwolfJson = new JSONObject();
avgSwolfJson.put("value", summary.getAvgSwolf()); avgSwolfJson.put("value", summary.getAvgSwolf());
avgSwolfJson.put("unit", ""); avgSwolfJson.put("unit", "");
jsonObject.put("Average reported swolf", avgSwolfJson); jsonObject.put(GBApplication.getContext().getString(R.string.swolfAvg), avgSwolfJson);
} }
boolean unknownData = false; boolean unknownData = false;
@ -292,6 +292,7 @@ public class HuaweiWorkoutGbParser {
int swolf = 0; int swolf = 0;
int swolfCount = 0; int swolfCount = 0;
int maxSwolf = 0; int maxSwolf = 0;
int minSwolf = 0;
int strokeRate = 0; int strokeRate = 0;
int strokeRateCount = 0; int strokeRateCount = 0;
int maxStrokeRate = 0; int maxStrokeRate = 0;
@ -353,6 +354,8 @@ public class HuaweiWorkoutGbParser {
swolfCount += 1; swolfCount += 1;
if (dataSample.getSwolf() > maxSwolf) if (dataSample.getSwolf() > maxSwolf)
maxSwolf = dataSample.getSwolf(); maxSwolf = dataSample.getSwolf();
if (dataSample.getSwolf() < minSwolf)
minSwolf = dataSample.getSwolf();
} }
if (dataSample.getStrokeRate() != -1) { if (dataSample.getStrokeRate() != -1) {
strokeRate += dataSample.getStrokeRate(); strokeRate += dataSample.getStrokeRate();
@ -399,131 +402,136 @@ public class HuaweiWorkoutGbParser {
if (speedCount > 0) { if (speedCount > 0) {
JSONObject speedJson = new JSONObject(); JSONObject speedJson = new JSONObject();
speedJson.put("value", speed); speedJson.put("value", speed / 10);
speedJson.put("unit", "cm/s"); speedJson.put("unit", GBApplication.getContext().getString(R.string.meters_second));
jsonObject.put("Reported speed (avg)", speedJson); jsonObject.put(GBApplication.getContext().getString(R.string.averageSpeed), speedJson);
} }
if (stepRatePresent) { if (stepRatePresent) {
JSONObject stepRateSumJson = new JSONObject(); JSONObject stepRateSumJson = new JSONObject();
stepRateSumJson.put("value", stepRate); stepRateSumJson.put("value", stepRate);
stepRateSumJson.put("unit", ""); stepRateSumJson.put("unit", GBApplication.getContext().getString(R.string.steps_unit));
jsonObject.put("Step rate (sum)", stepRateSumJson); jsonObject.put(GBApplication.getContext().getString(R.string.stepRateSum), stepRateSumJson);
JSONObject stepRateAvgJson = new JSONObject(); JSONObject stepRateAvgJson = new JSONObject();
stepRateAvgJson.put("value", avgStepRate); stepRateAvgJson.put("value", avgStepRate);
stepRateAvgJson.put("unit", "steps/min"); stepRateAvgJson.put("unit", GBApplication.getContext().getString(R.string.spm));
jsonObject.put("Step rate (avg)", stepRateAvgJson); jsonObject.put(GBApplication.getContext().getString(R.string.stepRateAvg), stepRateAvgJson);
} }
if (cadenceCount > 0) { if (cadenceCount > 0) {
JSONObject cadenceJson = new JSONObject(); JSONObject cadenceJson = new JSONObject();
cadenceJson.put("value", cadence); cadenceJson.put("value", cadence);
cadenceJson.put("unit", "steps/min"); cadenceJson.put("unit", GBApplication.getContext().getString(R.string.spm));
jsonObject.put("Cadence (avg)", cadenceJson); jsonObject.put(GBApplication.getContext().getString(R.string.averageCadence), cadenceJson);
} }
if (stepLengthCount > 0) { if (stepLengthCount > 0) {
JSONObject stepLengthJson = new JSONObject(); JSONObject stepLengthJson = new JSONObject();
stepLengthJson.put("value", stepLength); stepLengthJson.put("value", stepLength);
stepLengthJson.put("unit", "cm"); stepLengthJson.put("unit", GBApplication.getContext().getString(R.string.cm));
jsonObject.put("Step Length (avg)", stepLengthJson); jsonObject.put(GBApplication.getContext().getString(R.string.stepLengthAvg), stepLengthJson);
} }
if (groundContactTimeCount > 0) { if (groundContactTimeCount > 0) {
JSONObject groundContactTimeJson = new JSONObject(); JSONObject groundContactTimeJson = new JSONObject();
groundContactTimeJson.put("value", groundContactTime); groundContactTimeJson.put("value", groundContactTime);
groundContactTimeJson.put("unit", "milliseconds"); groundContactTimeJson.put("unit", GBApplication.getContext().getString(R.string.milliseconds));
jsonObject.put("Ground contact time (avg)", groundContactTimeJson); jsonObject.put(GBApplication.getContext().getString(R.string.groundContactTimeAvg), groundContactTimeJson);
} }
if (impactCount > 0) { if (impactCount > 0) {
JSONObject impactJson = new JSONObject(); JSONObject impactJson = new JSONObject();
impactJson.put("value", impact); impactJson.put("value", impact);
impactJson.put("unit", "g"); impactJson.put("unit", "g");
jsonObject.put("Impact (avg)", impactJson); jsonObject.put(GBApplication.getContext().getString(R.string.impactAvg), impactJson);
JSONObject maxImpactJson = new JSONObject(); JSONObject maxImpactJson = new JSONObject();
maxImpactJson.put("value", maxImpact); maxImpactJson.put("value", maxImpact);
maxImpactJson.put("unit", "g"); maxImpactJson.put("unit", "g");
jsonObject.put("Impact (max)", maxImpactJson); jsonObject.put(GBApplication.getContext().getString(R.string.impactMax), maxImpactJson);
} }
if (swingAngleCount > 0) { if (swingAngleCount > 0) {
JSONObject swingAngleJson = new JSONObject(); JSONObject swingAngleJson = new JSONObject();
swingAngleJson.put("value", swingAngle); swingAngleJson.put("value", swingAngle);
swingAngleJson.put("unit", "degrees"); swingAngleJson.put("unit", GBApplication.getContext().getString(R.string.degrees));
jsonObject.put("Swing angle (avg)", swingAngleJson); jsonObject.put(GBApplication.getContext().getString(R.string.swingAngleAvg), swingAngleJson);
} }
if (footLandingPresent) { if (footLandingPresent) {
JSONObject foreFootLandingJson = new JSONObject(); JSONObject foreFootLandingJson = new JSONObject();
foreFootLandingJson.put("value", foreFootLanding); foreFootLandingJson.put("value", foreFootLanding);
foreFootLandingJson.put("unit", ""); foreFootLandingJson.put("unit", "");
jsonObject.put("Fore foot landings", foreFootLandingJson); jsonObject.put(GBApplication.getContext().getString(R.string.foreFootLandings), foreFootLandingJson);
JSONObject midFootLandingJson = new JSONObject(); JSONObject midFootLandingJson = new JSONObject();
midFootLandingJson.put("value", midFootLanding); midFootLandingJson.put("value", midFootLanding);
midFootLandingJson.put("unit", ""); midFootLandingJson.put("unit", "");
jsonObject.put("Mid foot landings", midFootLandingJson); jsonObject.put(GBApplication.getContext().getString(R.string.midFootLandings), midFootLandingJson);
JSONObject backFootLandingJson = new JSONObject(); JSONObject backFootLandingJson = new JSONObject();
backFootLandingJson.put("value", backFootLanding); backFootLandingJson.put("value", backFootLanding);
backFootLandingJson.put("unit", ""); backFootLandingJson.put("unit", "");
jsonObject.put("Back foot landings", backFootLandingJson); jsonObject.put(GBApplication.getContext().getString(R.string.backFootLandings), backFootLandingJson);
} }
if (eversionAngleCount > 0) { if (eversionAngleCount > 0) {
JSONObject eversionAngleJson = new JSONObject(); JSONObject eversionAngleJson = new JSONObject();
eversionAngleJson.put("value", eversionAngle); eversionAngleJson.put("value", eversionAngle);
eversionAngleJson.put("unit", "degrees"); eversionAngleJson.put("unit", GBApplication.getContext().getString(R.string.degrees));
jsonObject.put("Eversion angle (avg)", eversionAngleJson); jsonObject.put(GBApplication.getContext().getString(R.string.eversionAngleAvg), eversionAngleJson);
JSONObject maxEversionAngleJson = new JSONObject(); JSONObject maxEversionAngleJson = new JSONObject();
maxEversionAngleJson.put("value", maxEversionAngle); maxEversionAngleJson.put("value", maxEversionAngle);
maxEversionAngleJson.put("unit", "degrees"); maxEversionAngleJson.put("unit", GBApplication.getContext().getString(R.string.degrees));
jsonObject.put("Eversion angle (max)", maxEversionAngleJson); jsonObject.put(GBApplication.getContext().getString(R.string.eversionAngleMax), maxEversionAngleJson);
} }
if (swolfCount > 0) { if (swolfCount > 0) {
JSONObject swolfJson = new JSONObject(); JSONObject swolfJson = new JSONObject();
swolfJson.put("value", swolf); swolfJson.put("value", swolf);
swolfJson.put("unit", ""); swolfJson.put("unit", "");
jsonObject.put("Swolf (avg calculated)", swolfJson); jsonObject.put(GBApplication.getContext().getString(R.string.swolfAvg), swolfJson);
JSONObject maxSwolfJson = new JSONObject(); JSONObject maxSwolfJson = new JSONObject();
maxSwolfJson.put("value", maxSwolf); maxSwolfJson.put("value", maxSwolf);
maxSwolfJson.put("unit", ""); maxSwolfJson.put("unit", "");
jsonObject.put("Swolf (max)", maxSwolfJson); jsonObject.put(GBApplication.getContext().getString(R.string.swolfMax), maxSwolfJson);
JSONObject minSwolfJson = new JSONObject();
minSwolfJson.put("value", minSwolf);
minSwolfJson.put("unit", "");
jsonObject.put(GBApplication.getContext().getString(R.string.swolfMin), minSwolfJson);
} }
if (strokeRateCount > 0) { if (strokeRateCount > 0) {
JSONObject strokeRateJson = new JSONObject(); JSONObject strokeRateJson = new JSONObject();
strokeRateJson.put("value", strokeRate); strokeRateJson.put("value", strokeRate);
strokeRateJson.put("unit", ""); strokeRateJson.put("unit", ""); // TODO: find out unit?
jsonObject.put("Stroke rate (avg calculated)", strokeRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.avgStrokeRate), strokeRateJson);
JSONObject maxStrokeRateJson = new JSONObject(); JSONObject maxStrokeRateJson = new JSONObject();
maxStrokeRateJson.put("value", maxStrokeRate); maxStrokeRateJson.put("value", maxStrokeRate);
maxStrokeRateJson.put("unit", ""); maxStrokeRateJson.put("unit", ""); // TODO: find out unit?
jsonObject.put("Stroke rate (max)", maxStrokeRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.maxStrokeRate), maxStrokeRateJson);
} }
if (heartRateCount > 0) { if (heartRateCount > 0) {
JSONObject heartRateJson = new JSONObject(); JSONObject heartRateJson = new JSONObject();
heartRateJson.put("value", heartRate); heartRateJson.put("value", heartRate);
heartRateJson.put("unit", "bpm"); heartRateJson.put("unit", GBApplication.getContext().getString(R.string.bpm));
jsonObject.put("Heart rate (avg)", heartRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.averageHR), heartRateJson);
JSONObject maxHeartRateJson = new JSONObject(); JSONObject maxHeartRateJson = new JSONObject();
maxHeartRateJson.put("value", maxHeartRate); maxHeartRateJson.put("value", maxHeartRate);
maxHeartRateJson.put("unit", "bpm"); maxHeartRateJson.put("unit", GBApplication.getContext().getString(R.string.bpm));
jsonObject.put("Heart rate (max)", maxHeartRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.maxHR), maxHeartRateJson);
JSONObject minHeartRateJson = new JSONObject(); JSONObject minHeartRateJson = new JSONObject();
minHeartRateJson.put("value", minHeartRate); minHeartRateJson.put("value", minHeartRate);
minHeartRateJson.put("unit", "bpm"); minHeartRateJson.put("unit", GBApplication.getContext().getString(R.string.bpm));
jsonObject.put("Heart rate (min)", minHeartRateJson); jsonObject.put(GBApplication.getContext().getString(R.string.minHR), minHeartRateJson);
} }
} }
@ -539,40 +547,40 @@ public class HuaweiWorkoutGbParser {
JSONObject paceDistance = new JSONObject(); JSONObject paceDistance = new JSONObject();
paceDistance.put("value", sample.getDistance()); paceDistance.put("value", sample.getDistance());
paceDistance.put("unit", "kilometers"); paceDistance.put("unit", GBApplication.getContext().getString(R.string.km));
jsonObject.put(String.format(GBApplication.getLanguage() , "Pace %d distance", index), paceDistance); jsonObject.put(String.format(GBApplication.getLanguage() , GBApplication.getContext().getString(R.string.fmtPaceDistance), index), paceDistance);
JSONObject paceType = new JSONObject(); JSONObject paceType = new JSONObject();
paceType.put("value", sample.getType()); paceType.put("value", sample.getType());
paceType.put("unit", ""); // TODO: not sure paceType.put("unit", ""); // TODO: not sure
jsonObject.put(String.format(GBApplication.getLanguage(), "Pace %d type", index), paceType); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceType), index), paceType);
JSONObject pacePace = new JSONObject(); JSONObject pacePace = new JSONObject();
pacePace.put("value", sample.getPace()); pacePace.put("value", sample.getPace());
pacePace.put("unit", "seconds_km"); pacePace.put("unit", GBApplication.getContext().getString(R.string.seconds_km));
jsonObject.put(String.format(GBApplication.getLanguage(), "Pace %d pace", index), pacePace); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPacePace), index), pacePace);
if (sample.getCorrection() != 0) { if (sample.getCorrection() != 0) {
JSONObject paceCorrection = new JSONObject(); JSONObject paceCorrection = new JSONObject();
paceCorrection.put("value", sample.getCorrection()); paceCorrection.put("value", sample.getCorrection() / 10);
paceCorrection.put("unit", "m"); paceCorrection.put("unit", GBApplication.getContext().getString(R.string.meters));
jsonObject.put(String.format(GBApplication.getLanguage(), "Pace %d correction", index), paceCorrection); jsonObject.put(String.format(GBApplication.getLanguage(), GBApplication.getContext().getString(R.string.fmtPaceCorrection), index), paceCorrection);
} }
} }
if (count != 0) { if (count != 0) {
// TODO: should probably be split on type?
JSONObject avgPace = new JSONObject(); JSONObject avgPace = new JSONObject();
avgPace.put("value", pace / count); avgPace.put("value", pace / count);
avgPace.put("unit", "seconds_km"); avgPace.put("unit", "seconds_km");
jsonObject.put("Average pace", avgPace); jsonObject.put("Average pace", avgPace); // TODO: translatable string
} }
if (unknownData) { if (unknownData) {
JSONObject unknownDataJson = new JSONObject(); JSONObject unknownDataJson = new JSONObject();
unknownDataJson.put("value", "YES"); unknownDataJson.put("value", GBApplication.getContext().getString(R.string.yes).toUpperCase());
unknownDataJson.put("unit", "string"); unknownDataJson.put("unit", "string");
jsonObject.put(GBApplication.getContext().getString(R.string.unknownDataEncountered), unknownDataJson);
jsonObject.put("Unknown data encountered", unknownDataJson);
} }
BaseActivitySummary baseSummary; BaseActivitySummary baseSummary;

View File

@ -1871,6 +1871,9 @@
<string name="strokes">Total Strokes</string> <string name="strokes">Total Strokes</string>
<string name="averageLapPace">Average Lap Pace</string> <string name="averageLapPace">Average Lap Pace</string>
<string name="swolfIndex">SWOLF</string> <string name="swolfIndex">SWOLF</string>
<string name="swolfAvg">Average swolf</string>
<string name="swolfMax">Maximum swolf</string>
<string name="swolfMin">Minimum swolf</string>
<string name="swimStyle">Swim Style</string> <string name="swimStyle">Swim Style</string>
<string name="laneLength">Lane Length</string> <string name="laneLength">Lane Length</string>
<string name="laps">Laps</string> <string name="laps">Laps</string>
@ -1879,6 +1882,23 @@
<string name="flatSeconds">Flat</string> <string name="flatSeconds">Flat</string>
<string name="baseAltitude">Base Elevation</string> <string name="baseAltitude">Base Elevation</string>
<string name="averageSpeed">Average Speed</string> <string name="averageSpeed">Average Speed</string>
<string name="stepRateSum">Sum of step rate</string>
<string name="stepRateAvg">Average step rate</string>
<string name="stepLengthAvg">Average Step Length</string>
<string name="groundContactTimeAvg">Average ground contact time</string>
<string name="impactAvg">Average impact</string>
<string name="impactMax">Maximum impact</string>
<string name="swingAngleAvg">Average swing angle</string>
<string name="foreFootLandings">Fore foot landings</string>
<string name="midFootLandings">Mid foot landings</string>
<string name="backFootLandings">Back foot landings</string>
<string name="eversionAngleAvg">Average eversion angle</string>
<string name="eversionAngleMax">Max eversion angle</string>
<string name="fmtPaceDistance">Pace %d distance</string>
<string name="fmtPaceType">Pace %d type</string>
<string name="fmtPacePace">Pace %d pace</string>
<string name="fmtPaceCorrection">Pace %d correction</string>
<string name="unknownDataEncountered">Unknown data encountered</string>
<!-- activity summary units--> <!-- activity summary units-->
<string name="meters">m</string> <string name="meters">m</string>
<string name="cm">cm</string> <string name="cm">cm</string>
@ -1893,6 +1913,7 @@
<string name="strokes_minute">str/min</string> <string name="strokes_minute">str/min</string>
<string name="strokes_unit">str</string> <string name="strokes_unit">str</string>
<string name="seconds">sec</string> <string name="seconds">sec</string>
<string name="milliseconds">milliseconds</string>
<string name="swolf_index">swolf index</string> <string name="swolf_index">swolf index</string>
<string name="swim_style">swim style</string> <string name="swim_style">swim style</string>
<string name="laps_unit">laps</string> <string name="laps_unit">laps</string>
@ -1904,6 +1925,7 @@
<string name="bpm">bpm</string> <string name="bpm">bpm</string>
<string name="km">km</string> <string name="km">km</string>
<string name="mi">mi</string> <string name="mi">mi</string>
<string name="degrees">degrees</string>
<!-- activity summary groups--> <!-- activity summary groups-->
<string name="Strokes">Strokes</string> <string name="Strokes">Strokes</string>
<string name="Swimming">Swimming</string> <string name="Swimming">Swimming</string>