diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java index 409e30903..69652d0aa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StressChartFragment.java @@ -53,6 +53,7 @@ import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -103,11 +104,19 @@ public class StressChartFragment extends AbstractChartFragment samples = getSamples(db, device); + int tsEnd = getTSEnd(); + Calendar day = Calendar.getInstance(); + day.setTimeInMillis(tsEnd * 1000L); + day.set(Calendar.HOUR_OF_DAY, 0); + day.set(Calendar.MINUTE, 0); + day.set(Calendar.SECOND, 0); + final int tsStart = (int) (day.getTimeInMillis() / 1000); + tsEnd = tsStart + 24 * 60 * 60 - 1; + final List samples = getSamples(db, device, tsStart, tsEnd); LOG.info("Got {} stress samples", samples.size()); - ensureStartAndEndSamples((List) samples); + ensureStartAndEndSamples((List) samples, tsStart, tsEnd); return new StressChartsDataBuilder(samples, device.getDeviceCoordinator().getStressRanges()).build(); } @@ -247,6 +256,8 @@ public class StressChartFragment extends AbstractChartFragment getSamples(final DBHandler db, final GBDevice device) { - final int tsStart = getTSStart(); - final int tsEnd = getTSEnd(); + private List getSamples(final DBHandler db, final GBDevice device, int tsStart, int tsEnd) { final DeviceCoordinator coordinator = device.getDeviceCoordinator(); final TimeSampleProvider sampleProvider = coordinator.getStressSampleProvider(device, db.getDaoSession()); return sampleProvider.getAllSamples(tsStart * 1000L, tsEnd * 1000L); } - protected void ensureStartAndEndSamples(final List samples) { + protected void ensureStartAndEndSamples(final List samples, int tsStart, int tsEnd) { if (samples == null || samples.isEmpty()) { return; } - final long tsEndMillis = getTSEnd() * 1000L; - final long tsStartMillis = getTSStart() * 1000L; + final long tsEndMillis = tsEnd * 1000L; + final long tsStartMillis = tsStart * 1000L; final StressSample lastSample = samples.get(samples.size() - 1); if (lastSample.getTimestamp() < tsEndMillis) {