Overview: fix predictions checkbox disappearing after unchecking it.

This commit is contained in:
Johannes Mockenhaupt 2017-11-18 18:44:59 +01:00
parent a293f86978
commit d21a2bd691
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -1170,8 +1170,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 {
@ -1214,7 +1214,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);
@ -1226,7 +1226,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);
@ -1295,7 +1295,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);