From 067b264ae8707211467d5ff12b4e47185e7a6375 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 16 Mar 2018 19:16:47 +0100 Subject: [PATCH] chart menu 3 --- .../plugins/Overview/OverviewFragment.java | 155 ++++-------------- app/src/main/res/layout/overview_fragment.xml | 110 ------------- .../res/layout/overview_fragment_nsclient.xml | 132 +++------------ .../overview_fragment_nsclient_tablet.xml | 131 ++------------- .../layout/overview_fragment_smallheight.xml | 132 +++------------ 5 files changed, 87 insertions(+), 573 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 9b3100e34e..97197ec065 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -126,7 +126,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SingleClickButton; import info.nightscout.utils.ToastUtils; -public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, View.OnLongClickListener { +public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); TextView timeView; @@ -157,20 +157,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, TextView sage; TextView pbage; - TextView showPredictionLabel; - TextView showBasalsLabel; - CheckBox showBasalsCheckbox; - TextView showIobLabel; - CheckBox showIobCheckbox; - TextView showCobLabel; - CheckBox showCobCheckbox; - TextView showDeviationsLabel; - CheckBox showDeviationsCheckbox; - TextView showRatiosLabel; - CheckBox showRatiosCheckbox; - CheckBox showPredictionCheckbox; - - RecyclerView notificationsView; LinearLayoutManager llm; @@ -295,38 +281,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout); - showPredictionCheckbox = (CheckBox) view.findViewById(R.id.overview_showprediction); - showBasalsCheckbox = (CheckBox) view.findViewById(R.id.overview_showbasals); - showIobCheckbox = (CheckBox) view.findViewById(R.id.overview_showiob); - showCobCheckbox = (CheckBox) view.findViewById(R.id.overview_showcob); - showDeviationsCheckbox = (CheckBox) view.findViewById(R.id.overview_showdeviations); - showRatiosCheckbox = (CheckBox) view.findViewById(R.id.overview_showratios); - showPredictionCheckbox.setChecked(SP.getBoolean("showprediction", false)); - showBasalsCheckbox.setChecked(SP.getBoolean("showbasals", true)); - showIobCheckbox.setChecked(SP.getBoolean("showiob", false)); - showCobCheckbox.setChecked(SP.getBoolean("showcob", false)); - showDeviationsCheckbox.setChecked(SP.getBoolean("showdeviations", false)); - showRatiosCheckbox.setChecked(SP.getBoolean("showratios", false)); - showPredictionCheckbox.setOnCheckedChangeListener(this); - showBasalsCheckbox.setOnCheckedChangeListener(this); - showIobCheckbox.setOnCheckedChangeListener(this); - showCobCheckbox.setOnCheckedChangeListener(this); - showDeviationsCheckbox.setOnCheckedChangeListener(this); - showRatiosCheckbox.setOnCheckedChangeListener(this); - - showPredictionLabel = (TextView) view.findViewById(R.id.overview_showprediction_label); - showPredictionLabel.setOnClickListener(this); - showBasalsLabel = (TextView) view.findViewById(R.id.overview_showbasals_label); - showBasalsLabel.setOnClickListener(this); - showIobLabel = (TextView) view.findViewById(R.id.overview_showiob_label); - showIobLabel.setOnClickListener(this); - showCobLabel = (TextView) view.findViewById(R.id.overview_showcob_label); - showCobLabel.setOnClickListener(this); - showDeviationsLabel = (TextView) view.findViewById(R.id.overview_showdeviations_label); - showDeviationsLabel.setOnClickListener(this); - showRatiosLabel = (TextView) view.findViewById(R.id.overview_showratios_label); - showRatiosLabel.setOnClickListener(this); - notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); notificationsView.setHasFixedSize(true); llm = new LinearLayoutManager(view.getContext()); @@ -382,15 +336,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, chartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - PopupMenu popup = new PopupMenu(v.getContext(), v); - MenuItem item = popup.getMenu().add(Menu.NONE, CHARTTYPE.PRE.ordinal(), Menu.NONE, "Predictions"); - CharSequence title = item.getTitle(); - SpannableString s = new SpannableString(title); - s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.prediction, null)),0, s.length(), 0); - item.setTitle(s); - item.setCheckable(true); - item.setChecked(SP.getBoolean("showprediction", false)); + final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; + final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions; + MenuItem item; + CharSequence title; + SpannableString s; + PopupMenu popup = new PopupMenu(v.getContext(), v); + + if(predictionsAvailable) { + item = popup.getMenu().add(Menu.NONE, CHARTTYPE.PRE.ordinal(), Menu.NONE, "Predictions"); + title = item.getTitle(); + s = new SpannableString(title); + s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.prediction, null)), 0, s.length(), 0); + item.setTitle(s); + item.setCheckable(true); + item.setChecked(SP.getBoolean("showprediction", true)); + } item = popup.getMenu().add(Menu.NONE, CHARTTYPE.BAS.ordinal(), Menu.NONE, "Basals"); title = item.getTitle(); @@ -406,7 +368,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.iob, null)), 0, s.length(), 0); item.setTitle(s); item.setCheckable(true); - item.setChecked(SP.getBoolean("showiob", false)); + item.setChecked(SP.getBoolean("showiob", true)); item = popup.getMenu().add(Menu.NONE, CHARTTYPE.COB.ordinal(), Menu.NONE, "Carbs On Board"); title = item.getTitle(); @@ -414,7 +376,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.cob, null)), 0, s.length(), 0); item.setTitle(s); item.setCheckable(true); - item.setChecked(SP.getBoolean("showcob", false)); + item.setChecked(SP.getBoolean("showcob", true)); item = popup.getMenu().add(Menu.NONE, CHARTTYPE.DEV.ordinal(), Menu.NONE, "Deviations"); title = item.getTitle(); @@ -506,35 +468,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - switch (buttonView.getId()) { - case R.id.overview_showprediction: - case R.id.overview_showbasals: - case R.id.overview_showiob: - break; - case R.id.overview_showcob: - showDeviationsCheckbox.setOnCheckedChangeListener(null); - showDeviationsCheckbox.setChecked(false); - showDeviationsCheckbox.setOnCheckedChangeListener(this); - break; - case R.id.overview_showdeviations: - showCobCheckbox.setOnCheckedChangeListener(null); - showCobCheckbox.setChecked(false); - showCobCheckbox.setOnCheckedChangeListener(this); - break; - case R.id.overview_showratios: - break; - } - SP.putBoolean("showiob", showIobCheckbox.isChecked()); - SP.putBoolean("showprediction", showPredictionCheckbox.isChecked()); - SP.putBoolean("showbasals", showBasalsCheckbox.isChecked()); - SP.putBoolean("showcob", showCobCheckbox.isChecked()); - SP.putBoolean("showdeviations", showDeviationsCheckbox.isChecked()); - SP.putBoolean("showratios", showRatiosCheckbox.isChecked()); - scheduleUpdateGUI("onGraphCheckboxesCheckedChanged"); - } - @Override public boolean onContextItemSelected(MenuItem item) { final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); @@ -677,24 +610,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (ConfigBuilderPlugin.getActivePump().isSuspended() || !ConfigBuilderPlugin.getActivePump().isInitialized()) ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null); break; - case R.id.overview_showprediction_label: - showPredictionCheckbox.toggle(); - break; - case R.id.overview_showbasals_label: - showBasalsCheckbox.toggle(); - break; - case R.id.overview_showiob_label: - showIobCheckbox.toggle(); - break; - case R.id.overview_showcob_label: - showCobCheckbox.toggle(); - break; - case R.id.overview_showdeviations_label: - showDeviationsCheckbox.toggle(); - break; - case R.id.overview_showratios_label: - showRatiosCheckbox.toggle(); - break; } } @@ -1374,14 +1289,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions; - if (predictionsAvailable) { - showPredictionCheckbox.setVisibility(View.VISIBLE); - showPredictionLabel.setVisibility(View.VISIBLE); - } else { - showPredictionCheckbox.setVisibility(View.GONE); - showPredictionLabel.setVisibility(View.GONE); - } - // pump status from ns if (pumpDeviceStatusView != null) { pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus()); @@ -1432,7 +1339,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final long toTime; final long fromTime; final long endTime; - if (predictionsAvailable && showPredictionCheckbox.isChecked()) { + if (predictionsAvailable && SP.getBoolean("showprediction", false)) { int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000)); predHours = Math.min(2, predHours); predHours = Math.max(0, predHours); @@ -1459,7 +1366,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, graphData.addInRangeArea(fromTime, endTime, lowLine, highLine); // **** BG **** - if (predictionsAvailable && showPredictionCheckbox.isChecked()) + if (predictionsAvailable && SP.getBoolean("showprediction", false)) graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed); else graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null); @@ -1471,7 +1378,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, graphData.addTreatments(fromTime, endTime); // add basal data - if (pump.getPumpDescription().isTempBasalCapable && showBasalsCheckbox.isChecked()) { + if (pump.getPumpDescription().isTempBasalCapable && SP.getBoolean("showbasals", true)) { graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d); } @@ -1492,25 +1399,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, boolean useRatioForScale = false; boolean useDSForScale = false; - if (showIobCheckbox.isChecked()) { + if (SP.getBoolean("showiob", true)) { useIobForScale = true; - } else if (showCobCheckbox.isChecked()) { + } else if (SP.getBoolean("showcob", true)) { useCobForScale = true; - } else if (showDeviationsCheckbox.isChecked()) { + } else if (SP.getBoolean("showdeviations", false)) { useDevForScale = true; - } else if (showRatiosCheckbox.isChecked()) { + } else if (SP.getBoolean("showratios", false)) { useRatioForScale = true; } else if (Config.displayDeviationSlope) { useDSForScale = true; } - if (showIobCheckbox.isChecked()) + if (SP.getBoolean("showiob", true)) secondGraphData.addIob(fromTime, now, useIobForScale, 1d); - if (showCobCheckbox.isChecked()) + if (SP.getBoolean("showcob", true)) secondGraphData.addCob(fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d); - if (showDeviationsCheckbox.isChecked()) + if (SP.getBoolean("showdeviations", false)) secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d); - if (showRatiosCheckbox.isChecked()) + if (SP.getBoolean("showratios", false)) secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d); if (Config.displayDeviationSlope) secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1d); @@ -1526,7 +1433,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, activity.runOnUiThread(new Runnable() { @Override public void run() { - if (showIobCheckbox.isChecked() || showCobCheckbox.isChecked() || showDeviationsCheckbox.isChecked() || showRatiosCheckbox.isChecked() || Config.displayDeviationSlope) { + if (SP.getBoolean("showiob", true) || SP.getBoolean("showcob", true) || SP.getBoolean("showdeviations", false) || SP.getBoolean("showratios", false) || Config.displayDeviationSlope) { iobGraph.setVisibility(View.VISIBLE); } else { iobGraph.setVisibility(View.GONE); diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index e540447473..c1372c5826 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -238,116 +238,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_weight="1"> + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="0dp" + android:layout_weight="1"> + + + + + +