From 58d79892edeeee1e057cd9fd6abd8b170befa5aa Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 21 Jun 2018 19:01:12 +0200 Subject: [PATCH 1/2] Overview: TT context menu. --- .../plugins/Overview/OverviewFragment.java | 72 ++++++++++++++++--- app/src/main/res/values/strings.xml | 1 + 2 files changed, 62 insertions(+), 11 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 86c2e40272..4c3d442cc1 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 @@ -114,6 +114,7 @@ import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.DefaultValueHelper; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NSUpload; import info.nightscout.utils.OKDialog; @@ -122,6 +123,8 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SingleClickButton; import info.nightscout.utils.ToastUtils; +import static info.nightscout.utils.DateUtil.now; + public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); @@ -488,6 +491,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null) { menu.add(MainApp.gs(R.string.careportal_profileswitch)); } + } else if (v == tempTargetView) { + menu.setHeaderTitle(MainApp.gs(R.string.careportal_temporarytarget)); + menu.add(MainApp.gs(R.string.custom)); + menu.add(MainApp.gs(R.string.activity)); + menu.add(MainApp.gs(R.string.eatingsoon)); + menu.add(MainApp.gs(R.string.hypo)); + if (TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null) { + menu.add(MainApp.gs(R.string.cancel)); + } } } @@ -578,6 +590,53 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis()); FragmentManager manager = getFragmentManager(); pvd.show(manager, "ProfileViewDialog"); + } else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) { + DefaultValueHelper defHelper = new DefaultValueHelper(); + double target = defHelper.determineEatingSoonTT(profile.getUnits()); + TempTarget tempTarget = new TempTarget() + .date(System.currentTimeMillis()) + .duration(defHelper.determineEatingSoonTTDuration()) + .reason(MainApp.gs(R.string.eatingsoon)) + .source(Source.USER) + .low(target) + .high(target); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); + } else if (item.getTitle().equals(MainApp.gs(R.string.activity))) { + DefaultValueHelper defHelper = new DefaultValueHelper(); + double target = defHelper.determineActivityTT(profile.getUnits()); + TempTarget tempTarget = new TempTarget() + .date(now()) + .duration(defHelper.determineActivityTTDuration()) + .reason(MainApp.gs(R.string.activity)) + .source(Source.USER) + .low(target) + .high(target); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); + } else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) { + DefaultValueHelper defHelper = new DefaultValueHelper(); + double target = defHelper.determineHypoTT(profile.getUnits()); + TempTarget tempTarget = new TempTarget() + .date(now()) + .duration(defHelper.determineHypoTTDuration()) + .reason(MainApp.gs(R.string.activity)) + .source(Source.USER) + .low(target) + .high(target); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); + } else if (item.getTitle().equals(MainApp.gs(R.string.custom))) { + NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); + final OptionsToShow temptarget = CareportalFragment.TEMPTARGET; + temptarget.executeTempTarget = true; + newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget); + newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); + } else if (item.getTitle().equals(MainApp.gs(R.string.cancel))) { + TempTarget tempTarget = new TempTarget() + .source(Source.USER) + .date(now()) + .duration(0) + .low(0) + .high(0); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } return super.onContextItemSelected(item); @@ -843,6 +902,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sLoopHandler.removeCallbacksAndMessages(null); unregisterForContextMenu(apsModeView); unregisterForContextMenu(activeProfileView); + unregisterForContextMenu(tempTargetView); } @Override @@ -856,6 +916,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L); registerForContextMenu(apsModeView); registerForContextMenu(activeProfileView); + registerForContextMenu(tempTargetView); updateGUI("onResume"); } @@ -1196,17 +1257,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, activeProfileView.setText(MainApp.getConfigBuilder().getProfileName()); activeProfileView.setBackgroundColor(Color.GRAY); - tempTargetView.setOnLongClickListener(view -> { - view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); - final OptionsToShow temptarget = CareportalFragment.TEMPTARGET; - temptarget.executeTempTarget = true; - newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget); - newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); - return true; - }); - tempTargetView.setLongClickable(true); - // QuickWizard button QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4dbb471618..fc889de627 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1163,6 +1163,7 @@ Poctech Receive BG values from Poctech app Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software. + Custom %d day From 3eed0afe61a52df82c71668f2228322adf0cfc23 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 21 Jun 2018 22:29:16 +0200 Subject: [PATCH 2/2] Move 'eating soon' TT to top (ordering of dialog). --- .../androidaps/plugins/Overview/OverviewFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4c3d442cc1..18a756d142 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 @@ -494,8 +494,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (v == tempTargetView) { menu.setHeaderTitle(MainApp.gs(R.string.careportal_temporarytarget)); menu.add(MainApp.gs(R.string.custom)); - menu.add(MainApp.gs(R.string.activity)); menu.add(MainApp.gs(R.string.eatingsoon)); + menu.add(MainApp.gs(R.string.activity)); menu.add(MainApp.gs(R.string.hypo)); if (TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null) { menu.add(MainApp.gs(R.string.cancel));