Fix finding BG in graph for treatments before the first displayed BG.

(cherry picked from commit 8bdafe3)
This commit is contained in:
Johannes Mockenhaupt 2018-05-05 19:09:22 +02:00
parent 260e259fb0
commit 1e0b7d331a
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -320,14 +320,13 @@ public class GraphData {
} }
private double getNearestBg(long date) { private double getNearestBg(long date) {
double bg = 0;
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
BgReading reading = bgReadingsArray.get(r); BgReading reading = bgReadingsArray.get(r);
if (reading.date > date) continue; if (reading.date > date) continue;
bg = Profile.fromMgdlToUnits(reading.value, units); return Profile.fromMgdlToUnits(reading.value, units);
break;
} }
return bg; return bgReadingsArray.size() > 0
? Profile.fromMgdlToUnits(bgReadingsArray.get(0).value, units) : 0;
} }
// scale in % of vertical size (like 0.3) // scale in % of vertical size (like 0.3)