Merge branch 'disappearing-predections-checkbox' into 'smb060'

Overview: fix predictions checkbox disappearing after unchecking it.

See merge request MilosKozak/AndroidAPS!370
This commit is contained in:
Johannes Mockenhaupt 2017-12-20 16:58:12 +00:00
commit c5089d821e

View file

@ -1167,8 +1167,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobView.setText(cobText); cobView.setText(cobText);
} }
boolean showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.request.hasPredictions; boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
if (showPrediction) { if (predictionsAvailable) {
showPredictionView.setVisibility(View.VISIBLE); showPredictionView.setVisibility(View.VISIBLE);
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE); getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
} else { } else {
@ -1211,7 +1211,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// ****** GRAPH ******* // ****** GRAPH *******
// allign to hours // align to hours
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis()); calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.MILLISECOND, 0);
@ -1223,7 +1223,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
long toTime; long toTime;
long fromTime; long fromTime;
long endTime; long endTime;
if (showPrediction) { if (predictionsAvailable && showPredictionView.isChecked()) {
int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000)); int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000));
predHours = Math.min(2, predHours); predHours = Math.min(2, predHours);
predHours = Math.max(0, predHours); predHours = Math.max(0, predHours);
@ -1292,7 +1292,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
graphData.addInRangeArea(bgGraph, fromTime, endTime, lowLine, highLine); graphData.addInRangeArea(bgGraph, fromTime, endTime, lowLine, highLine);
// **** BG **** // **** BG ****
if (showPrediction) if (predictionsAvailable && showPredictionView.isChecked())
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed); graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed);
else else
graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null); graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null);