From 92407d349077d6cdae861e5d18aa8cd774317e9d Mon Sep 17 00:00:00 2001 From: vanous Date: Wed, 14 Oct 2020 20:02:01 +0200 Subject: [PATCH] Fix trailing activity 0 duration Hide intensity if not present in data --- .../charts/ActivityListingAdapter.java | 11 ++++++++++- .../activities/charts/StepAnalysis.java | 7 ++++--- .../adapter/AbstractActivityListingAdapter.java | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java index 0e072542e..9ccf53736 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java @@ -63,7 +63,7 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter 0) { return true; } else { @@ -71,6 +71,15 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter 0) { + return true; + } else { + return false; + } + } + @Override protected int getIcon(StepAnalysis.StepSession item) { int activityKind = item.getActivityKind(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java index b117b4470..f549e019b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java @@ -64,7 +64,8 @@ public class StepAnalysis { for (ActivitySample sample : samples) { - if (sample.getKind() != ActivityKind.TYPE_SLEEP) { //anything but sleep counts + if (sample.getKind() != ActivityKind.TYPE_SLEEP //anything but sleep counts + && !(sample instanceof TrailingActivitySample)) { //trailing samples have wrong date and make trailing activity have 0 duration if (sample.getHeartRate() != 255 && sample.getHeartRate() != -1) { heartRateToAdd = sample.getHeartRate(); activeHrSamplesToAdd = 1; @@ -122,7 +123,8 @@ public class StepAnalysis { previousSample = sample; } } - //make sure we show the last portion of the data as well in case no further activity is recorded yet + //trailing activity: make sure we show the last portion of the data as well in case no further activity is recorded yet + if (sessionStart != null && previousSample != null) { int current = previousSample.getTimestamp(); int starting = (int) (sessionStart.getTime() / 1000); @@ -131,7 +133,6 @@ public class StepAnalysis { if (session_length >= MIN_SESSION_LENGTH) { int heartRateAverage = activeHrSamplesForAverage > 0 ? heartRateForAverage / activeHrSamplesForAverage : 0; float distance = (float) (activeSteps * STEP_SIZE); - sessionEnd = getDateFromSample(previousSample); activityKind = detect_activity_kind(session_length, activeSteps, heartRateAverage, activeIntensity); result.add(new StepSession(sessionStart, sessionEnd, activeSteps, heartRateAverage, activeIntensity, distance, activityKind)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java index 2a984a0b3..77e628a74 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java @@ -36,8 +36,6 @@ import java.util.List; import nodomain.freeyourgadget.gadgetbridge.R; -import static nodomain.freeyourgadget.gadgetbridge.activities.charts.ActivityAnalysis.LOG; - /** * Adapter for displaying generic ItemWithDetails instances. */ @@ -108,9 +106,17 @@ public abstract class AbstractActivityListingAdapter extends ArrayAdapter hrLayout.setVisibility(View.VISIBLE); } + if (!hasIntensity(item)) { + intensityLayout.setVisibility(View.GONE); + } else { + intensityLayout.setVisibility(View.VISIBLE); + } + activityIcon.setImageResource(getIcon(item)); - if (position % 2 == 0) {parentLayout.setBackgroundColor(alternateColor);} + if (position % 2 == 0) { + parentLayout.setBackgroundColor(alternateColor); + } return view; } @@ -131,7 +137,9 @@ public abstract class AbstractActivityListingAdapter extends ArrayAdapter protected abstract String getDurationLabel(T item); - protected abstract Boolean hasHR(T item); + protected abstract boolean hasHR(T item); + + protected abstract boolean hasIntensity(T item); @DrawableRes protected abstract int getIcon(T item);