1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 01:25:50 +01:00

Workout page: hr zones add colors

This commit is contained in:
a0z 2024-12-03 09:11:50 +01:00 committed by José Rebelo
parent 9748f389dd
commit 6a68071702
14 changed files with 67 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries; package nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -11,6 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueForm
public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry { public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
private final int progress; private final int progress;
private int color;
public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress) { public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress) {
this(null, value, unit, progress); this(null, value, unit, progress);
@ -21,6 +23,11 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
this.progress = progress; this.progress = progress;
} }
public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress, final int color) {
this(null, value, unit, progress);
this.color = color;
}
public int getProgress() { public int getProgress() {
return progress; return progress;
} }
@ -59,6 +66,9 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
progressBar.setIndeterminate(false); progressBar.setIndeterminate(false);
progressBar.setProgress(progress); progressBar.setProgress(progress);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
if (color != 0) {
progressBar.setProgressTintList(ColorStateList.valueOf(color));
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
progressLayout.addView(progressBar, params); progressLayout.addView(progressBar, params);

View File

@ -16,6 +16,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue;
@ -246,6 +247,14 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
continue; continue;
} }
final List<String> zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_EASY, HR_ZONE_AEROBIC, HR_ZONE_THRESHOLD, HR_ZONE_MAXIMUM); final List<String> zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_EASY, HR_ZONE_AEROBIC, HR_ZONE_THRESHOLD, HR_ZONE_MAXIMUM);
final int[] zoneColors = new int[]{
0,
context.getResources().getColor(R.color.hr_zone_warm_up_color),
context.getResources().getColor(R.color.hr_zone_easy_color),
context.getResources().getColor(R.color.hr_zone_aerobic_color),
context.getResources().getColor(R.color.hr_zone_threshold_color),
context.getResources().getColor(R.color.hr_zone_maximum_color),
};
for (int i = 0; i < zoneOrder.size(); i++) { for (int i = 0; i < zoneOrder.size(); i++) {
double timeInZone = timeInZones[i] != null ? Math.rint(timeInZones[i]) : 0; double timeInZone = timeInZones[i] != null ? Math.rint(timeInZones[i]) : 0;
summaryData.add( summaryData.add(
@ -253,7 +262,8 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
new ActivitySummaryProgressEntry( new ActivitySummaryProgressEntry(
timeInZone, timeInZone,
UNIT_SECONDS, UNIT_SECONDS,
(int) (100 * timeInZone / totalTime) (int) (100 * timeInZone / totalTime),
zoneColors[i]
) )
); );
} }

View File

@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.*; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.*;
import android.content.Context;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -28,6 +30,7 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser;
import nodomain.freeyourgadget.gadgetbridge.proto.HuamiProtos; import nodomain.freeyourgadget.gadgetbridge.proto.HuamiProtos;
@ -39,12 +42,17 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsA
public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser { public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser {
private static final Logger LOG = LoggerFactory.getLogger(ZeppOsActivitySummaryParser.class); private static final Logger LOG = LoggerFactory.getLogger(ZeppOsActivitySummaryParser.class);
private final Context context;
@Override @Override
public AbstractHuamiActivityDetailsParser getDetailsParser(final BaseActivitySummary summary) { public AbstractHuamiActivityDetailsParser getDetailsParser(final BaseActivitySummary summary) {
return new ZeppOsActivityDetailsParser(summary); return new ZeppOsActivityDetailsParser(summary);
} }
public ZeppOsActivitySummaryParser(final Context context) {
this.context = context;
}
@Override @Override
protected void parseBinaryData(final BaseActivitySummary summary, final Date startTime) { protected void parseBinaryData(final BaseActivitySummary summary, final Date startTime) {
final byte[] rawData = summary.getRawSummaryData(); final byte[] rawData = summary.getRawSummaryData();
@ -130,13 +138,22 @@ public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser {
.sum(); .sum();
final List<String> zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC, HR_ZONE_EXTREME); final List<String> zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC, HR_ZONE_EXTREME);
final int[] zoneColors = new int[]{
0,
context.getResources().getColor(R.color.hr_zone_warm_up_color),
context.getResources().getColor(R.color.hr_zone_easy_color),
context.getResources().getColor(R.color.hr_zone_aerobic_color),
context.getResources().getColor(R.color.hr_zone_threshold_color),
context.getResources().getColor(R.color.hr_zone_maximum_color),
};
for (int i = 0; i < zoneOrder.size(); i++) { for (int i = 0; i < zoneOrder.size(); i++) {
summaryData.add( summaryData.add(
zoneOrder.get(i), zoneOrder.get(i),
new ActivitySummaryProgressEntry( new ActivitySummaryProgressEntry(
summaryProto.getHeartRateZones().getZoneTime(i), summaryProto.getHeartRateZones().getZoneTime(i),
UNIT_SECONDS, UNIT_SECONDS,
(int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime) (int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime),
zoneColors[i]
) )
); );
} }

View File

@ -321,7 +321,7 @@ public abstract class ZeppOsCoordinator extends HuamiCoordinator {
@Override @Override
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
return new ZeppOsActivitySummaryParser(); return new ZeppOsActivitySummaryParser(context);
} }
@Override @Override

View File

@ -205,7 +205,7 @@ public abstract class HuaweiBRCoordinator extends AbstractBLClassicDeviceCoordin
@Override @Override
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
return new HuaweiWorkoutGbParser(device); return new HuaweiWorkoutGbParser(device, context);
} }
@Override @Override

View File

@ -214,7 +214,7 @@ public abstract class HuaweiLECoordinator extends AbstractBLEDeviceCoordinator i
@Override @Override
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
return new HuaweiWorkoutGbParser(device); return new HuaweiWorkoutGbParser(device, context);
} }
@Override @Override

View File

@ -70,7 +70,7 @@ public class HuaweiSettingsCustomizer implements DeviceSpecificSettingsCustomize
if (preference.getKey().equals("huawei_reparse_workout_data")) { if (preference.getKey().equals("huawei_reparse_workout_data")) {
if (((SwitchPreferenceCompat) preference).isChecked()) { if (((SwitchPreferenceCompat) preference).isChecked()) {
GB.toast("Starting workout reparse", Toast.LENGTH_SHORT, 0); GB.toast("Starting workout reparse", Toast.LENGTH_SHORT, 0);
new HuaweiWorkoutGbParser(handler.getDevice()).parseAllWorkouts(); new HuaweiWorkoutGbParser(handler.getDevice(), handler.getContext()).parseAllWorkouts();
GB.toast("Workout reparse is complete", Toast.LENGTH_SHORT, 0); GB.toast("Workout reparse is complete", Toast.LENGTH_SHORT, 0);
((SwitchPreferenceCompat) preference).setChecked(false); ((SwitchPreferenceCompat) preference).setChecked(false);

View File

@ -2443,7 +2443,7 @@ public class HuaweiSupportProvider {
return; return;
} }
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId); new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId);
LOG.debug("Completed workout GPS parsing and inserting"); LOG.debug("Completed workout GPS parsing and inserting");
syncState.stopWorkoutGpsDownload(); syncState.stopWorkoutGpsDownload();

View File

@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei; package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -76,9 +77,11 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
// TODO: Might be nicer to propagate the exceptions, so they can be handled upstream // TODO: Might be nicer to propagate the exceptions, so they can be handled upstream
private final GBDevice gbDevice; private final GBDevice gbDevice;
private final Context context;
public HuaweiWorkoutGbParser(final GBDevice gbDevice) { public HuaweiWorkoutGbParser(final GBDevice gbDevice, final Context context) {
this.gbDevice = gbDevice; this.gbDevice = gbDevice;
this.context = context;
} }
@Override @Override
@ -633,6 +636,13 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
if(HRZonesCfg != null) { if(HRZonesCfg != null) {
final double totalTime = Arrays.stream(HRZones).sum(); final double totalTime = Arrays.stream(HRZones).sum();
final List<String> zoneOrder = Arrays.asList(ActivitySummaryEntries.HR_ZONE_WARM_UP, ActivitySummaryEntries.HR_ZONE_FAT_BURN, ActivitySummaryEntries.HR_ZONE_AEROBIC, ActivitySummaryEntries.HR_ZONE_ANAEROBIC, ActivitySummaryEntries.HR_ZONE_EXTREME); final List<String> zoneOrder = Arrays.asList(ActivitySummaryEntries.HR_ZONE_WARM_UP, ActivitySummaryEntries.HR_ZONE_FAT_BURN, ActivitySummaryEntries.HR_ZONE_AEROBIC, ActivitySummaryEntries.HR_ZONE_ANAEROBIC, ActivitySummaryEntries.HR_ZONE_EXTREME);
final int[] zoneColors = new int[]{
context.getResources().getColor(R.color.hr_zone_warm_up_color),
context.getResources().getColor(R.color.hr_zone_easy_color),
context.getResources().getColor(R.color.hr_zone_aerobic_color),
context.getResources().getColor(R.color.hr_zone_threshold_color),
context.getResources().getColor(R.color.hr_zone_maximum_color),
};
for (int i = zoneOrder.size() - 1; i >= 0; i--) { for (int i = zoneOrder.size() - 1; i >= 0; i--) {
double timeInZone = HRZones[i]; double timeInZone = HRZones[i];
LOG.info("Zone: {} {}", zoneOrder.get(i), timeInZone); LOG.info("Zone: {} {}", zoneOrder.get(i), timeInZone);
@ -641,7 +651,8 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
new ActivitySummaryProgressEntry( new ActivitySummaryProgressEntry(
timeInZone, timeInZone,
ActivitySummaryEntries.UNIT_SECONDS, ActivitySummaryEntries.UNIT_SECONDS,
(int) (100 * timeInZone / totalTime) (int) (100 * timeInZone / totalTime),
zoneColors[i]
) )
); );
} }

View File

@ -123,7 +123,7 @@ public class GetWorkoutDataRequest extends Request {
nextRequest.setFinalizeReq(this.finalizeReq); nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest); this.nextRequest(nextRequest);
} else { } else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -100,7 +100,7 @@ public class GetWorkoutPaceRequest extends Request {
nextRequest.setFinalizeReq(this.finalizeReq); nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest); this.nextRequest(nextRequest);
} else { } else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -74,7 +74,7 @@ public class GetWorkoutSwimSegmentsRequest extends Request {
nextRequest.setFinalizeReq(this.finalizeReq); nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest); this.nextRequest(nextRequest);
} else { } else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -114,7 +114,7 @@ public class GetWorkoutTotalsRequest extends Request {
nextRequest.setFinalizeReq(this.finalizeReq); nextRequest.setFinalizeReq(this.finalizeReq);
this.nextRequest(nextRequest); this.nextRequest(nextRequest);
} else { } else {
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId); new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId);
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId, new Runnable() { supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -70,6 +70,12 @@
<color name="row_separator_dark" type="color">#19808080</color> <color name="row_separator_dark" type="color">#19808080</color>
<color name="gauge_line_color" type="color">#19808080</color> <color name="gauge_line_color" type="color">#19808080</color>
<color name="hr_zone_warm_up_color" type="color">#92a4ad</color>
<color name="hr_zone_easy_color" type="color">#80D8FF</color>
<color name="hr_zone_aerobic_color" type="color">#66BB6A</color>
<color name="hr_zone_threshold_color" type="color">#FF7043</color>
<color name="hr_zone_maximum_color" type="color">#F44336</color>
<attr name="row_separator" format="color" /> <attr name="row_separator" format="color" />
<color name="alternate_row_background_light">#FFEDEDED</color> <color name="alternate_row_background_light">#FFEDEDED</color>
<color name="alternate_row_background_dark">#545254</color> <color name="alternate_row_background_dark">#545254</color>