mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 08:10:52 +02:00
Make sure that the charts display the requested time range
(instead of only the range with available samples)
This commit is contained in:
parent
8d6888a13a
commit
dfbaba4cb6
@ -709,7 +709,10 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
}
|
||||
|
||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
||||
List<? extends ActivitySample> samples = getSamples(db, device, getTSStart(), getTSEnd());
|
||||
int tsStart = getTSStart();
|
||||
int tsEnd = getTSEnd();
|
||||
List<ActivitySample> samples = (List<ActivitySample>) getSamples(db, device, tsStart, tsEnd);
|
||||
ensureStartAndEndSamples(samples, tsStart, tsEnd);
|
||||
// List<ActivitySample> samples2 = new ArrayList<>();
|
||||
// int min = Math.min(samples.size(), 10);
|
||||
// int min = Math.min(samples.size(), 10);
|
||||
@ -720,6 +723,33 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
return samples;
|
||||
}
|
||||
|
||||
protected void ensureStartAndEndSamples(List<ActivitySample> samples, int tsStart, int tsEnd) {
|
||||
if (samples == null || samples.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ActivitySample lastSample = samples.get(samples.size() - 1);
|
||||
if (lastSample.getTimestamp() < tsEnd) {
|
||||
samples.add(createTrailingActivitySample(lastSample, tsEnd));
|
||||
}
|
||||
|
||||
ActivitySample firstSample = samples.get(0);
|
||||
if (firstSample.getTimestamp() > tsStart) {
|
||||
samples.add(createTrailingActivitySample(firstSample, tsStart));
|
||||
}
|
||||
}
|
||||
|
||||
private ActivitySample createTrailingActivitySample(ActivitySample referenceSample, int timestamp) {
|
||||
TrailingActivitySample sample = new TrailingActivitySample();
|
||||
if (referenceSample instanceof AbstractActivitySample) {
|
||||
AbstractActivitySample reference = (AbstractActivitySample) referenceSample;
|
||||
sample.setUserId(reference.getUserId());
|
||||
sample.setDeviceId(reference.getDeviceId());
|
||||
sample.setProvider(reference.getProvider());
|
||||
}
|
||||
sample.setTimestamp(timestamp);
|
||||
return sample;
|
||||
}
|
||||
|
||||
private int getTSEnd() {
|
||||
return toTimestamp(getEndDate());
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
|
||||
public class TrailingActivitySample extends AbstractActivitySample {
|
||||
private int timestamp;
|
||||
private long userId;
|
||||
private long deviceId;
|
||||
|
||||
@Override
|
||||
public void setTimestamp(int timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceId(long deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
@ -236,12 +236,14 @@ public class FetchActivityOperation extends AbstractMiBand2Operation {
|
||||
DateFormat.getDateTimeInstance().format(startTimestamp.getTime())), Toast.LENGTH_LONG, GB.INFO);
|
||||
} else {
|
||||
LOG.warn("Unexpected activity metadata: " + Logging.formatBytes(value));
|
||||
handleActivityFetchFinish();
|
||||
}
|
||||
} else if (value.length == 3) {
|
||||
if (Arrays.equals(MiBand2Service.RESPONSE_FINISH_SUCCESS, value)) {
|
||||
handleActivityFetchFinish();
|
||||
} else {
|
||||
LOG.warn("Unexpected activity metadata: " + Logging.formatBytes(value));
|
||||
handleActivityFetchFinish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user