mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-23 17:17:46 +01:00
Workout page: hr zones add colors
This commit is contained in:
parent
9748f389dd
commit
6a68071702
@ -1,6 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
@ -11,6 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueForm
|
||||
|
||||
public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
|
||||
private final int progress;
|
||||
private int color;
|
||||
|
||||
public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress) {
|
||||
this(null, value, unit, progress);
|
||||
@ -21,6 +23,11 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
|
||||
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() {
|
||||
return progress;
|
||||
}
|
||||
@ -59,6 +66,9 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry {
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setProgress(progress);
|
||||
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);
|
||||
progressLayout.addView(progressBar, params);
|
||||
|
||||
|
@ -16,6 +16,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue;
|
||||
@ -246,6 +247,14 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
|
||||
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 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++) {
|
||||
double timeInZone = timeInZones[i] != null ? Math.rint(timeInZones[i]) : 0;
|
||||
summaryData.add(
|
||||
@ -253,7 +262,8 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
|
||||
new ActivitySummaryProgressEntry(
|
||||
timeInZone,
|
||||
UNIT_SECONDS,
|
||||
(int) (100 * timeInZone / totalTime)
|
||||
(int) (100 * timeInZone / totalTime),
|
||||
zoneColors[i]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.*;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
@ -28,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.proto.HuamiProtos;
|
||||
@ -39,12 +42,17 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsA
|
||||
|
||||
public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ZeppOsActivitySummaryParser.class);
|
||||
private final Context context;
|
||||
|
||||
@Override
|
||||
public AbstractHuamiActivityDetailsParser getDetailsParser(final BaseActivitySummary summary) {
|
||||
return new ZeppOsActivityDetailsParser(summary);
|
||||
}
|
||||
|
||||
public ZeppOsActivitySummaryParser(final Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseBinaryData(final BaseActivitySummary summary, final Date startTime) {
|
||||
final byte[] rawData = summary.getRawSummaryData();
|
||||
@ -130,13 +138,22 @@ public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser {
|
||||
.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 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++) {
|
||||
summaryData.add(
|
||||
zoneOrder.get(i),
|
||||
new ActivitySummaryProgressEntry(
|
||||
summaryProto.getHeartRateZones().getZoneTime(i),
|
||||
UNIT_SECONDS,
|
||||
(int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime)
|
||||
(int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime),
|
||||
zoneColors[i]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ public abstract class ZeppOsCoordinator extends HuamiCoordinator {
|
||||
|
||||
@Override
|
||||
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
|
||||
return new ZeppOsActivitySummaryParser();
|
||||
return new ZeppOsActivitySummaryParser(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -205,7 +205,7 @@ public abstract class HuaweiBRCoordinator extends AbstractBLClassicDeviceCoordin
|
||||
|
||||
@Override
|
||||
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
|
||||
return new HuaweiWorkoutGbParser(device);
|
||||
return new HuaweiWorkoutGbParser(device, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -214,7 +214,7 @@ public abstract class HuaweiLECoordinator extends AbstractBLEDeviceCoordinator i
|
||||
|
||||
@Override
|
||||
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) {
|
||||
return new HuaweiWorkoutGbParser(device);
|
||||
return new HuaweiWorkoutGbParser(device, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,7 +70,7 @@ public class HuaweiSettingsCustomizer implements DeviceSpecificSettingsCustomize
|
||||
if (preference.getKey().equals("huawei_reparse_workout_data")) {
|
||||
if (((SwitchPreferenceCompat) preference).isChecked()) {
|
||||
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);
|
||||
|
||||
((SwitchPreferenceCompat) preference).setChecked(false);
|
||||
|
@ -2443,7 +2443,7 @@ public class HuaweiSupportProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId);
|
||||
new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId);
|
||||
|
||||
LOG.debug("Completed workout GPS parsing and inserting");
|
||||
syncState.stopWorkoutGpsDownload();
|
||||
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
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
|
||||
|
||||
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.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -633,6 +636,13 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
|
||||
if(HRZonesCfg != null) {
|
||||
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 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--) {
|
||||
double timeInZone = HRZones[i];
|
||||
LOG.info("Zone: {} {}", zoneOrder.get(i), timeInZone);
|
||||
@ -641,7 +651,8 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
|
||||
new ActivitySummaryProgressEntry(
|
||||
timeInZone,
|
||||
ActivitySummaryEntries.UNIT_SECONDS,
|
||||
(int) (100 * timeInZone / totalTime)
|
||||
(int) (100 * timeInZone / totalTime),
|
||||
zoneColors[i]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class GetWorkoutDataRequest extends Request {
|
||||
nextRequest.setFinalizeReq(this.finalizeReq);
|
||||
this.nextRequest(nextRequest);
|
||||
} else {
|
||||
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId);
|
||||
new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
|
||||
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -100,7 +100,7 @@ public class GetWorkoutPaceRequest extends Request {
|
||||
nextRequest.setFinalizeReq(this.finalizeReq);
|
||||
this.nextRequest(nextRequest);
|
||||
} else {
|
||||
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId);
|
||||
new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
|
||||
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -74,7 +74,7 @@ public class GetWorkoutSwimSegmentsRequest extends Request {
|
||||
nextRequest.setFinalizeReq(this.finalizeReq);
|
||||
this.nextRequest(nextRequest);
|
||||
} else {
|
||||
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId);
|
||||
new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId);
|
||||
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -114,7 +114,7 @@ public class GetWorkoutTotalsRequest extends Request {
|
||||
nextRequest.setFinalizeReq(this.finalizeReq);
|
||||
this.nextRequest(nextRequest);
|
||||
} else {
|
||||
new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId);
|
||||
new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId);
|
||||
supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -70,6 +70,12 @@
|
||||
<color name="row_separator_dark" 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" />
|
||||
<color name="alternate_row_background_light">#FFEDEDED</color>
|
||||
<color name="alternate_row_background_dark">#545254</color>
|
||||
|
Loading…
Reference in New Issue
Block a user