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 d347dc6b88..0dbaedef6d 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 @@ -16,21 +16,27 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; +import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.ContextMenu; import android.view.HapticFeedbackConstants; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; @@ -120,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; @@ -144,25 +150,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, LinearLayout pumpStatusLayout; GraphView bgGraph; GraphView iobGraph; + ImageButton chartButton; TextView iage; TextView cage; TextView sage; TextView pbage; - TextView showPredictionLabel; - CheckBox showPredictionCheckbox; - TextView showBasalsLabel; - CheckBox showBasalsCheckbox; - TextView showIobLabel; - CheckBox showIobCheckbox; - TextView showCobLabel; - CheckBox showCobCheckbox; - TextView showDeviationsLabel; - CheckBox showDeviationsCheckbox; - TextView showRatiosLabel; - CheckBox showRatiosCheckbox; - RecyclerView notificationsView; LinearLayoutManager llm; @@ -193,6 +187,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Object updateSync = new Object(); + public enum CHARTTYPE {PRE,BAS, IOB, COB, DEV, SEN}; private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture scheduledUpdate = null; @@ -286,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()); @@ -345,6 +308,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } }); + setupChartMenu(view); + lockScreen = (CheckBox) view.findViewById(R.id.overview_lockscreen); if (lockScreen != null) { lockScreen.setChecked(SP.getBoolean("lockscreen", false)); @@ -366,6 +331,106 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return null; } + private void setupChartMenu(View view) { + chartButton = (ImageButton) view.findViewById(R.id.overview_chartMenuButton); + chartButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + 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, MainApp.gs(R.string.overview_show_basals)); + title = item.getTitle(); + s = new SpannableString(title); + s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.basal, null)), 0, s.length(), 0); + item.setTitle(s); + item.setCheckable(true); + item.setChecked(SP.getBoolean("showbasals", true)); + + item = popup.getMenu().add(Menu.NONE, CHARTTYPE.IOB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_iob)); + title = item.getTitle(); + s = new SpannableString(title); + 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", true)); + + item = popup.getMenu().add(Menu.NONE, CHARTTYPE.COB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_cob)); + title = item.getTitle(); + s = new SpannableString(title); + 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", true)); + + item = popup.getMenu().add(Menu.NONE, CHARTTYPE.DEV.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_deviations)); + title = item.getTitle(); + s = new SpannableString(title); + s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.deviations, null)), 0, s.length(), 0); + item.setTitle(s); + item.setCheckable(true); + item.setChecked(SP.getBoolean("showdeviations", false)); + + item = popup.getMenu().add(Menu.NONE, CHARTTYPE.SEN.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_sensitivity)); + title = item.getTitle(); + s = new SpannableString(title); + s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.ratio, null)), 0, s.length(), 0); + item.setTitle(s); + item.setCheckable(true); + item.setChecked(SP.getBoolean("showratios", false)); + + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + if (item.getItemId() == CHARTTYPE.PRE.ordinal()) { + SP.putBoolean("showprediction", !item.isChecked()); + + } else if (item.getItemId() == CHARTTYPE.BAS.ordinal()) { + SP.putBoolean("showbasals", !item.isChecked()); + + } else if (item.getItemId() == CHARTTYPE.IOB.ordinal()) { + SP.putBoolean("showiob", !item.isChecked()); + + } else if (item.getItemId() == CHARTTYPE.COB.ordinal()) { + SP.putBoolean("showcob", !item.isChecked()); + + } else if (item.getItemId() == CHARTTYPE.DEV.ordinal()) { + SP.putBoolean("showdeviations", !item.isChecked()); + + } else if (item.getItemId() == CHARTTYPE.SEN.ordinal()) { + SP.putBoolean("showratios", !item.isChecked()); + } + scheduleUpdateGUI("onGraphCheckboxesCheckedChanged"); + return true; + } + }); + chartButton.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { + @Override + public void onDismiss(PopupMenu menu) { + chartButton.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp); + } + }); + popup.show(); + } + }); + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { @@ -403,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(); @@ -574,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; } } @@ -1270,14 +1288,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()); @@ -1328,7 +1338,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); @@ -1355,7 +1365,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); @@ -1367,7 +1377,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); } @@ -1388,25 +1398,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); @@ -1422,7 +1432,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/drawable/ic_arrow_drop_down_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_down_white_24dp.xml new file mode 100644 index 0000000000..b82186765e --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_drop_down_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml new file mode 100644 index 0000000000..c63c8c6529 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 64fccac3af..c1372c5826 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -238,120 +238,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + android:layout_height="match_parent" /> + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_weight="1"> + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="200dp"> + + + + + + + android:layout_height="150dp" /> @@ -394,9 +299,7 @@ android:paddingRight="0dp" android:text="@string/overview_treatment_label" android:textColor="@color/colorTreatmentButton" - android:textSize="10sp" - android:visibility="gone"/> - + android:textSize="10sp" /> + android:textSize="10sp" /> + android:textSize="10sp"/> Autobackfill missig BGs from NS ns_autobackfill SMB set by pump + Sensitivity + Deviations + Carbs On Board + Insulin On Board + Basals