From 547f09ffbd96c3077536c71e036083d0ea3650d3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 24 Sep 2017 11:45:32 +0200 Subject: [PATCH] allow to view profile from overview --- .../plugins/Overview/OverviewFragment.java | 72 ++++++++++--------- .../fragments/ProfileViewerDialog.java | 2 +- 2 files changed, 39 insertions(+), 35 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 fe4a1ea637..ca9362efbd 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 @@ -120,6 +120,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGrap import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -350,27 +351,33 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop == null) - return; - menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); - if (activeloop.isEnabled(PluginBase.LOOP)) { - menu.add(MainApp.sResources.getString(R.string.disableloop)); - if (!activeloop.isSuspended()) { - menu.add(MainApp.sResources.getString(R.string.suspendloopfor1h)); - menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); - menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); - menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); - menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); - menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); - menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); - menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor3h)); - } else { - menu.add(MainApp.sResources.getString(R.string.resume)); + if (v == apsModeView) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + if (activeloop == null) + return; + menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); + if (activeloop.isEnabled(PluginBase.LOOP)) { + menu.add(MainApp.sResources.getString(R.string.disableloop)); + if (!activeloop.isSuspended()) { + menu.add(MainApp.sResources.getString(R.string.suspendloopfor1h)); + menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); + menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); + menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); + menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); + menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); + menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); + menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor3h)); + } else { + menu.add(MainApp.sResources.getString(R.string.resume)); + } } + if (!activeloop.isEnabled(PluginBase.LOOP)) + menu.add(MainApp.sResources.getString(R.string.enableloop)); + } else if (v == activeProfileView) { + menu.setHeaderTitle(MainApp.sResources.getString(R.string.profile)); + menu.add(MainApp.sResources.getString(R.string.danar_viewprofile)); + menu.add(MainApp.sResources.getString(R.string.careportal_profileswitch)); } - if (!activeloop.isEnabled(PluginBase.LOOP)) - menu.add(MainApp.sResources.getString(R.string.enableloop)); } @Override @@ -554,6 +561,16 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, }); NSUpload.uploadOpenAPSOffline(180); return true; + } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.careportal_profileswitch))) { + NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); + final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; + profileswitch.executeProfileSwitch = true; + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); + newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); + } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.danar_viewprofile))) { + ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis()); + FragmentManager manager = getFragmentManager(); + pvd.show(manager, "ProfileViewDialog"); } return super.onContextItemSelected(item); @@ -738,6 +755,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, MainApp.bus().unregister(this); sLoopHandler.removeCallbacksAndMessages(null); unregisterForContextMenu(apsModeView); + unregisterForContextMenu(activeProfileView); } @Override @@ -753,6 +771,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, }; sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L); registerForContextMenu(apsModeView); + registerForContextMenu(activeProfileView); updateGUI("onResume"); } @@ -1088,21 +1107,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, activeProfileView.setText(MainApp.getConfigBuilder().getProfileName()); activeProfileView.setBackgroundColor(Color.GRAY); - activeProfileView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); - final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; - profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); - newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); - return true; - } - }); - activeProfileView.setLongClickable(true); - - tempTargetView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index 42e36bba27..a34146f04a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -43,7 +43,7 @@ public class ProfileViewerDialog extends DialogFragment { private TextView dateTextView; private Button refreshButton; - static ProfileViewerDialog newInstance(long time) { + public static ProfileViewerDialog newInstance(long time) { ProfileViewerDialog dialog = new ProfileViewerDialog(); Bundle args = new Bundle();