revert asynctask
This commit is contained in:
parent
f93090b012
commit
b8b00dbc81
1 changed files with 655 additions and 705 deletions
|
@ -7,7 +7,6 @@ import android.content.DialogInterface;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.graphics.Paint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
|
@ -54,6 +53,8 @@ import java.util.Calendar;
|
|||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
@ -189,8 +190,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||
private static ScheduledFuture<?> scheduledUpdate = null;
|
||||
|
||||
private static UpdateGUIAsyncTask updateGUIAsyncTask;
|
||||
|
||||
public OverviewFragment() {
|
||||
super();
|
||||
if (sHandlerThread == null) {
|
||||
|
@ -324,6 +323,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
});
|
||||
|
||||
Timer timeTimer = new Timer();
|
||||
timeTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
timeUpdate();
|
||||
}
|
||||
}, 0, 30000);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -359,15 +366,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
switch (buttonView.getId()) {
|
||||
case R.id.overview_showprediction:
|
||||
SP.putBoolean("showprediction", showPredictionView.isChecked());
|
||||
updateGUI("onPredictionCheckedChanged");
|
||||
scheduleUpdateGUI("onPredictionCheckedChanged");
|
||||
break;
|
||||
case R.id.overview_showbasals:
|
||||
SP.putBoolean("showbasals", showBasalsView.isChecked());
|
||||
updateGUI("onBasalsCheckedChanged");
|
||||
scheduleUpdateGUI("onBasalsCheckedChanged");
|
||||
break;
|
||||
case R.id.overview_showiob:
|
||||
SP.putBoolean("showiob", showIobView.isChecked());
|
||||
updateGUI("onIobCheckedChanged");
|
||||
scheduleUpdateGUI("onIobCheckedChanged");
|
||||
break;
|
||||
case R.id.overview_showcob:
|
||||
showDeviationsView.setOnCheckedChangeListener(null);
|
||||
|
@ -375,7 +382,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
showDeviationsView.setOnCheckedChangeListener(this);
|
||||
SP.putBoolean("showcob", showCobView.isChecked());
|
||||
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
|
||||
updateGUI("onCobCheckedChanged");
|
||||
scheduleUpdateGUI("onCobCheckedChanged");
|
||||
break;
|
||||
case R.id.overview_showdeviations:
|
||||
showCobView.setOnCheckedChangeListener(null);
|
||||
|
@ -383,7 +390,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
showCobView.setOnCheckedChangeListener(this);
|
||||
SP.putBoolean("showcob", showCobView.isChecked());
|
||||
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
|
||||
updateGUI("onDeviationsCheckedChanged");
|
||||
scheduleUpdateGUI("onDeviationsCheckedChanged");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -458,7 +465,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
return true;
|
||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
||||
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
|
||||
scheduleUpdateGUI("suspendmenu");
|
||||
updateGUI("suspendmenu");
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -770,6 +777,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
scheduleUpdateGUI("EventTreatmentChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventCareportalEventChange ev) {
|
||||
scheduleUpdateGUI("EventCareportalEventChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||
scheduleUpdateGUI("EventTempBasalChange");
|
||||
|
@ -780,11 +792,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
scheduleUpdateGUI("EventExtendedBolusChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventCareportalEventChange ev) {
|
||||
scheduleUpdateGUI("EventCareportalEventChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
scheduleUpdateGUI("EventNewBG");
|
||||
|
@ -849,6 +856,20 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
}
|
||||
|
||||
private void timeUpdate() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timeView != null) { //must not exists
|
||||
timeView.setText(DateUtil.timeString(new Date()));
|
||||
}
|
||||
log.debug("Time updated");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scheduleUpdateGUI(final String from) {
|
||||
class UpdateRunnable implements Runnable {
|
||||
public void run() {
|
||||
|
@ -868,92 +889,45 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
if (scheduledUpdate != null)
|
||||
scheduledUpdate.cancel(false);
|
||||
Runnable task = new UpdateRunnable();
|
||||
final int msec = 1000;
|
||||
final int msec = 400;
|
||||
scheduledUpdate = worker.schedule(task, msec, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private class UpdateGUIAsyncTask extends AsyncTask<String, Void, String> {
|
||||
private String from;
|
||||
@SuppressLint("SetTextI18n")
|
||||
public void updateGUI(String from) {
|
||||
log.debug("updateGUI entered from: " + from);
|
||||
|
||||
BgReading actualBG = DatabaseHelper.actualBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
String units = profile.getUnits();
|
||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
|
||||
long now = new Date().getTime();
|
||||
|
||||
IobTotal bolusIob;
|
||||
IobTotal basalIob;
|
||||
|
||||
Double lowLine;
|
||||
Double highLine;
|
||||
|
||||
int hoursToFetch;
|
||||
long toTime;
|
||||
long fromTime;
|
||||
long endTime;
|
||||
|
||||
boolean showPrediction;
|
||||
boolean showBasals;
|
||||
boolean showIob;
|
||||
boolean showCob;
|
||||
boolean showDeviations;
|
||||
|
||||
LineGraphSeries<DataPoint> basalsLineSeries;
|
||||
LineGraphSeries<DataPoint> absoluteBasalsLineSeries;
|
||||
LineGraphSeries<DataPoint> baseBasalsSeries;
|
||||
LineGraphSeries<DataPoint> tempBasalsSeries;
|
||||
AreaGraphSeries<DoubleDataPoint> areaSeries;
|
||||
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
|
||||
PointsWithLabelGraphSeries<DataPointWithLabelInterface> bgSeries = null;
|
||||
PointsWithLabelGraphSeries<DataPointWithLabelInterface> treatmentSeries = null;
|
||||
|
||||
class DeviationDataPoint extends DataPoint {
|
||||
public int color;
|
||||
|
||||
public DeviationDataPoint(double x, double y, int color) {
|
||||
super(x, y);
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
FixedLineGraphSeries<DataPoint> iobSeries;
|
||||
FixedLineGraphSeries<DataPoint> cobSeries;
|
||||
BarGraphSeries<DeviationDataPoint> devSeries;
|
||||
DataPoint[] cobData;
|
||||
DeviationDataPoint[] devData;
|
||||
|
||||
List<BgReading> bgReadingsArray;
|
||||
Double maxBgValue = 0d;
|
||||
Double maxIobValueFound = 0d;
|
||||
Double maxCobValueFound = 0d;
|
||||
Double maxDevValueFound = 0d;
|
||||
Double maxBasalValueFound = 0d;
|
||||
|
||||
Integer numOfHorizLines;
|
||||
|
||||
public UpdateGUIAsyncTask(String from) {
|
||||
super();
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
log.debug("UpdateGUIAsyncTask onPreExecute from: " + from);
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.VISIBLE);
|
||||
if (timeView != null) { //must not exists
|
||||
timeView.setText(DateUtil.timeString(new Date()));
|
||||
}
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.VISIBLE);
|
||||
|
||||
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
|
||||
pumpStatusView.setText(R.string.noprofileset);
|
||||
pumpStatusLayout.setVisibility(View.VISIBLE);
|
||||
loopStatusLayout.setVisibility(View.GONE);
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
pumpStatusLayout.setVisibility(View.GONE);
|
||||
loopStatusLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
updateNotifications();
|
||||
CareportalFragment.updateAge(getActivity(), sage, iage, cage, pbage);
|
||||
BgReading actualBG = DatabaseHelper.actualBg();
|
||||
BgReading lastBG = DatabaseHelper.lastBg();
|
||||
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
// open loop mode
|
||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||
if (Config.APS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) {
|
||||
apsModeView.setVisibility(View.VISIBLE);
|
||||
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
|
||||
|
@ -1117,8 +1091,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
|
||||
String units = profile.getUnits();
|
||||
|
||||
lowLine = SP.getDouble("low_mark", 0d);
|
||||
highLine = SP.getDouble("high_mark", 0d);
|
||||
Double lowLine = SP.getDouble("low_mark", 0d);
|
||||
Double highLine = SP.getDouble("high_mark", 0d);
|
||||
if (lowLine < 1) {
|
||||
lowLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units);
|
||||
}
|
||||
|
@ -1126,6 +1100,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
highLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units);
|
||||
}
|
||||
|
||||
timeUpdate();
|
||||
|
||||
// **** BG value ****
|
||||
if (lastBG != null) {
|
||||
int color = MainApp.sResources.getColor(R.color.inrange);
|
||||
|
@ -1148,9 +1124,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
BgReading.units = profile.getUnits();
|
||||
} else
|
||||
} else {
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.GONE);
|
||||
return;
|
||||
|
||||
}
|
||||
Integer flag = bgView.getPaintFlags();
|
||||
if (actualBG == null) {
|
||||
flag |= Paint.STRIKE_THRU_TEXT_FLAG;
|
||||
|
@ -1162,6 +1140,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin));
|
||||
|
||||
// iob
|
||||
MainApp.getConfigBuilder().updateTotalIOBTreatments();
|
||||
MainApp.getConfigBuilder().updateTotalIOBTempBasals();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
|
||||
|
||||
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||
iobView.setText(iobtext);
|
||||
|
||||
// cob
|
||||
if (cobView != null) { // view must not exists
|
||||
String cobText = "";
|
||||
|
@ -1171,6 +1160,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
cobView.setText(cobText);
|
||||
}
|
||||
|
||||
boolean showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
|
||||
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) {
|
||||
showPredictionView.setVisibility(View.VISIBLE);
|
||||
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
|
||||
|
@ -1189,12 +1179,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
|
||||
showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
|
||||
showBasals = showBasalsView.isChecked();
|
||||
showIob = showIobView.isChecked();
|
||||
showCob = showCobView.isChecked();
|
||||
showDeviations = showDeviationsView.isChecked();
|
||||
|
||||
int hoursToFetch;
|
||||
long toTime;
|
||||
long fromTime;
|
||||
long endTime;
|
||||
if (showPrediction) {
|
||||
int predHours = (int) (Math.ceil(((DetermineBasalResultAMA) finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000));
|
||||
predHours = Math.min(2, predHours);
|
||||
|
@ -1210,47 +1198,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
endTime = toTime;
|
||||
}
|
||||
|
||||
// **** Area ****
|
||||
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
|
||||
new DoubleDataPoint(fromTime, lowLine, highLine),
|
||||
new DoubleDataPoint(endTime, lowLine, highLine)
|
||||
};
|
||||
areaSeries = new AreaGraphSeries<>(areaDataPoints);
|
||||
areaSeries.setColor(0);
|
||||
areaSeries.setDrawBackground(true);
|
||||
areaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground));
|
||||
|
||||
// set manual x bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxX(endTime);
|
||||
bgGraph.getViewport().setMinX(fromTime);
|
||||
bgGraph.getViewport().setXAxisBoundsManual(true);
|
||||
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
||||
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
iobGraph.getViewport().setMaxX(endTime);
|
||||
iobGraph.getViewport().setMinX(fromTime);
|
||||
iobGraph.getViewport().setXAxisBoundsManual(true);
|
||||
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
||||
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
bgGraph.onDataChanged(true, true);
|
||||
iobGraph.onDataChanged(true, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
log.debug("UpdateGUIAsyncTask doInBackground from: " + from);
|
||||
|
||||
// IOB
|
||||
MainApp.getConfigBuilder().updateTotalIOBTreatments();
|
||||
MainApp.getConfigBuilder().updateTotalIOBTempBasals();
|
||||
bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
|
||||
basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
|
||||
|
||||
// ****** GRAPH *******
|
||||
LineGraphSeries<DataPoint> basalsLineSeries = null;
|
||||
LineGraphSeries<DataPoint> absoluteBasalsLineSeries = null;
|
||||
LineGraphSeries<DataPoint> baseBasalsSeries = null;
|
||||
LineGraphSeries<DataPoint> tempBasalsSeries = null;
|
||||
AreaGraphSeries<DoubleDataPoint> areaSeries;
|
||||
LineGraphSeries<DataPoint> seriesNow, seriesNow2;
|
||||
|
||||
// **** TEMP BASALS graph ****
|
||||
Double maxBasalValueFound = 0d;
|
||||
|
||||
if (pump.getPumpDescription().isTempBasalCapable && showBasals) {
|
||||
long now = new Date().getTime();
|
||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
||||
List<DataPoint> baseBasalArray = new ArrayList<>();
|
||||
List<DataPoint> tempBasalArray = new ArrayList<>();
|
||||
List<DataPoint> basalLineArray = new ArrayList<>();
|
||||
|
@ -1343,25 +1302,39 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
// **** IOB COB DEV graph ****
|
||||
class DeviationDataPoint extends DataPoint {
|
||||
public int color;
|
||||
|
||||
if (showIob || showCob || showDeviations) {
|
||||
public DeviationDataPoint(double x, double y, int color) {
|
||||
super(x, y);
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
FixedLineGraphSeries<DataPoint> iobSeries;
|
||||
FixedLineGraphSeries<DataPoint> cobSeries;
|
||||
BarGraphSeries<DeviationDataPoint> devSeries;
|
||||
Double maxIobValueFound = 0d;
|
||||
Double maxCobValueFound = 0d;
|
||||
Double maxDevValueFound = 0d;
|
||||
|
||||
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) {
|
||||
//Date start = new Date();
|
||||
List<DataPoint> iobArray = new ArrayList<>();
|
||||
List<DataPoint> cobArray = new ArrayList<>();
|
||||
List<DeviationDataPoint> devArray = new ArrayList<>();
|
||||
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
||||
if (showIob) {
|
||||
if (showIobView.isChecked()) {
|
||||
IobTotal iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time);
|
||||
iobArray.add(new DataPoint(time, iob.iob));
|
||||
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob.iob));
|
||||
}
|
||||
if (showCob || showDeviations) {
|
||||
if (showCobView.isChecked() || showDeviationsView.isChecked()) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||
if (autosensData != null && showCob) {
|
||||
if (autosensData != null && showCobView.isChecked()) {
|
||||
cobArray.add(new DataPoint(time, autosensData.cob));
|
||||
maxCobValueFound = Math.max(maxCobValueFound, autosensData.cob);
|
||||
}
|
||||
if (autosensData != null && showDeviations) {
|
||||
if (autosensData != null && showDeviationsView.isChecked()) {
|
||||
int color = Color.BLACK; // "="
|
||||
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
|
||||
if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN;
|
||||
|
@ -1381,7 +1354,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
iobSeries.setThickness(3);
|
||||
|
||||
|
||||
if (showIob && (showCob || showDeviations)) {
|
||||
if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) {
|
||||
List<DataPoint> cobArrayRescaled = new ArrayList<>();
|
||||
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
|
||||
for (int ci = 0; ci < cobArray.size(); ci++) {
|
||||
|
@ -1394,7 +1367,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
devArray = devArrayRescaled;
|
||||
}
|
||||
// COB
|
||||
cobData = new DataPoint[cobArray.size()];
|
||||
DataPoint[] cobData = new DataPoint[cobArray.size()];
|
||||
cobData = cobArray.toArray(cobData);
|
||||
cobSeries = new FixedLineGraphSeries<>(cobData);
|
||||
cobSeries.setDrawBackground(true);
|
||||
|
@ -1403,7 +1376,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
cobSeries.setThickness(3);
|
||||
|
||||
// DEVIATIONS
|
||||
devData = new DeviationDataPoint[devArray.size()];
|
||||
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
||||
devData = devArray.toArray(devData);
|
||||
devSeries = new BarGraphSeries<>(devData);
|
||||
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
|
||||
|
@ -1412,13 +1385,64 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
return data.color;
|
||||
}
|
||||
});
|
||||
//devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
|
||||
//devSeries.setColor(MainApp.sResources.getColor(R.color.cob));
|
||||
//devSeries.setThickness(3);
|
||||
|
||||
iobGraph.removeAllSeries();
|
||||
|
||||
if (showIobView.isChecked()) {
|
||||
iobGraph.addSeries(iobSeries);
|
||||
}
|
||||
if (showCobView.isChecked() && cobData.length > 0) {
|
||||
iobGraph.addSeries(cobSeries);
|
||||
}
|
||||
if (showDeviationsView.isChecked() && devData.length > 0) {
|
||||
iobGraph.addSeries(devSeries);
|
||||
}
|
||||
iobGraph.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
iobGraph.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// remove old data from graph
|
||||
bgGraph.getSecondScale().getSeries().clear();
|
||||
bgGraph.removeAllSeries();
|
||||
|
||||
// **** Area ****
|
||||
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
|
||||
new DoubleDataPoint(fromTime, lowLine, highLine),
|
||||
new DoubleDataPoint(endTime, lowLine, highLine)
|
||||
};
|
||||
bgGraph.addSeries(areaSeries = new AreaGraphSeries<>(areaDataPoints));
|
||||
areaSeries.setColor(0);
|
||||
areaSeries.setDrawBackground(true);
|
||||
areaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground));
|
||||
|
||||
// set manual x bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxX(endTime);
|
||||
bgGraph.getViewport().setMinX(fromTime);
|
||||
bgGraph.getViewport().setXAxisBoundsManual(true);
|
||||
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
||||
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
iobGraph.getViewport().setMaxX(endTime);
|
||||
iobGraph.getViewport().setMinX(fromTime);
|
||||
iobGraph.getViewport().setXAxisBoundsManual(true);
|
||||
iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
||||
iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
|
||||
// **** BG graph ****
|
||||
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
||||
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
||||
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
||||
|
||||
if (bgReadingsArray.size() == 0) {
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<BgReading> it = bgReadingsArray.iterator();
|
||||
Double maxBgValue = 0d;
|
||||
while (it.hasNext()) {
|
||||
BgReading bg = it.next();
|
||||
if (bg.value > maxBgValue) maxBgValue = bg.value;
|
||||
|
@ -1437,14 +1461,40 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
||||
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
|
||||
if (highLine > maxBgValue) maxBgValue = highLine;
|
||||
numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
||||
Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
||||
|
||||
DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()];
|
||||
bg = bgListArray.toArray(bg);
|
||||
if (bg.length > 0)
|
||||
bgSeries = new PointsWithLabelGraphSeries<>(bg);
|
||||
|
||||
// **** treatments graph ****
|
||||
if (bg.length > 0) {
|
||||
bgGraph.addSeries(new PointsWithLabelGraphSeries<>(bg));
|
||||
}
|
||||
|
||||
// **** NOW line ****
|
||||
DataPoint[] nowPoints = new DataPoint[]{
|
||||
new DataPoint(now, 0),
|
||||
new DataPoint(now, maxBgValue)
|
||||
};
|
||||
bgGraph.addSeries(seriesNow = new LineGraphSeries<>(nowPoints));
|
||||
seriesNow.setDrawDataPoints(false);
|
||||
DataPoint[] nowPoints2 = new DataPoint[]{
|
||||
new DataPoint(now, 0),
|
||||
new DataPoint(now, maxIobValueFound)
|
||||
};
|
||||
iobGraph.addSeries(seriesNow2 = new LineGraphSeries<>(nowPoints2));
|
||||
seriesNow2.setDrawDataPoints(false);
|
||||
//seriesNow.setThickness(1);
|
||||
// custom paint to make a dotted line
|
||||
Paint paint = new Paint();
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(2);
|
||||
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
|
||||
paint.setColor(Color.WHITE);
|
||||
seriesNow.setCustomPaint(paint);
|
||||
seriesNow2.setCustomPaint(paint);
|
||||
|
||||
|
||||
// Treatments
|
||||
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
||||
|
||||
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
|
||||
|
@ -1491,86 +1541,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()];
|
||||
treatmentsArray = filteredTreatments.toArray(treatmentsArray);
|
||||
if (treatmentsArray.length > 0) {
|
||||
treatmentSeries = new PointsWithLabelGraphSeries<>(treatmentsArray);
|
||||
bgGraph.addSeries(new PointsWithLabelGraphSeries<>(treatmentsArray));
|
||||
}
|
||||
|
||||
|
||||
return params[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
log.debug("UpdateGUIAsyncTask onPostExecute from: " + from);
|
||||
// IOB
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||
iobView.setText(iobtext);
|
||||
|
||||
// ****** GRAPH *******
|
||||
|
||||
// **** IOB COB DEV graph ****
|
||||
if (showIob || showCob || showDeviations) {
|
||||
iobGraph.removeAllSeries();
|
||||
|
||||
if (showIob) {
|
||||
iobGraph.addSeries(iobSeries);
|
||||
}
|
||||
if (showCob && cobData.length > 0) {
|
||||
iobGraph.addSeries(cobSeries);
|
||||
}
|
||||
if (showDeviations && devData.length > 0) {
|
||||
iobGraph.addSeries(devSeries);
|
||||
}
|
||||
iobGraph.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
iobGraph.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// remove old data from graph
|
||||
bgGraph.getSecondScale().getSeries().clear();
|
||||
bgGraph.removeAllSeries();
|
||||
|
||||
// **** Area ***
|
||||
if (areaSeries != null)
|
||||
bgGraph.addSeries(areaSeries);
|
||||
|
||||
// **** BG graph ****
|
||||
|
||||
if (bgSeries != null) {
|
||||
bgGraph.addSeries(bgSeries);
|
||||
}
|
||||
|
||||
// **** treatments graph ****
|
||||
if (treatmentSeries != null) {
|
||||
bgGraph.addSeries(treatmentSeries);
|
||||
}
|
||||
|
||||
// **** NOW line ****
|
||||
DataPoint[] nowPoints = new DataPoint[]{
|
||||
new DataPoint(now, 0),
|
||||
new DataPoint(now, maxBgValue)
|
||||
};
|
||||
bgGraph.addSeries(seriesNow = new LineGraphSeries<>(nowPoints));
|
||||
seriesNow.setDrawDataPoints(false);
|
||||
DataPoint[] nowPoints2 = new DataPoint[]{
|
||||
new DataPoint(now, 0),
|
||||
new DataPoint(now, maxIobValueFound)
|
||||
};
|
||||
iobGraph.addSeries(seriesNow2 = new LineGraphSeries<>(nowPoints2));
|
||||
seriesNow2.setDrawDataPoints(false);
|
||||
//seriesNow.setThickness(1);
|
||||
// custom paint to make a dotted line
|
||||
Paint paint = new Paint();
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(2);
|
||||
paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));
|
||||
paint.setColor(Color.WHITE);
|
||||
seriesNow.setCustomPaint(paint);
|
||||
seriesNow2.setCustomPaint(paint);
|
||||
|
||||
// set manual y bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxY(maxBgValue);
|
||||
bgGraph.getViewport().setMinY(0);
|
||||
|
@ -1578,7 +1551,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
|
||||
|
||||
// set second scale
|
||||
if (pump.getPumpDescription().isTempBasalCapable && showBasals) {
|
||||
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
|
||||
bgGraph.getSecondScale().addSeries(baseBasalsSeries);
|
||||
bgGraph.getSecondScale().addSeries(tempBasalsSeries);
|
||||
bgGraph.getSecondScale().addSeries(basalsLineSeries);
|
||||
|
@ -1599,29 +1572,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
});
|
||||
if (updating != null)
|
||||
updating.setVisibility(View.GONE);
|
||||
// release for next run
|
||||
log.debug("UpdateGUIAsyncTask finishing onPostExecute from: " + from);
|
||||
updateGUIAsyncTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGUI(String from) {
|
||||
if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
|
||||
pumpStatusView.setText(R.string.noprofileset);
|
||||
pumpStatusLayout.setVisibility(View.VISIBLE);
|
||||
loopStatusLayout.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
pumpStatusLayout.setVisibility(View.GONE);
|
||||
loopStatusLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
if (updateGUIAsyncTask != null) {
|
||||
log.debug("Update already running. From: " + from);
|
||||
return;
|
||||
}
|
||||
log.debug("updateGUI entered from: " + from);
|
||||
updateGUIAsyncTask = new UpdateGUIAsyncTask(from);
|
||||
updateGUIAsyncTask.execute(from);
|
||||
}
|
||||
|
||||
public double getNearestBg(long date, List<BgReading> bgReadingsArray) {
|
||||
|
|
Loading…
Reference in a new issue