diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index c6b2e3ce96..4ffec6aef3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -264,6 +264,7 @@ public class ConfigBuilderPlugin extends PluginBase { return activeAPS; } + @Nullable public static LoopPlugin getActiveLoop() { return activeLoop; } 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 d6c9c70c4e..a05df99efd 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 @@ -459,10 +459,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (v == apsModeView) { final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) + if (!MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) return; menu.setHeaderTitle(MainApp.gs(R.string.loop)); - if (activeloop.isEnabled(PluginType.LOOP)) { + if (activeloop == null) { + menu.add(MainApp.gs(R.string.enableloop)); + } else { menu.add(MainApp.gs(R.string.disableloop)); if (!activeloop.isSuspended()) { menu.add(MainApp.gs(R.string.suspendloopfor1h)); @@ -480,8 +482,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, menu.add(MainApp.gs(R.string.resume)); } } - if (!activeloop.isEnabled(PluginType.LOOP)) - menu.add(MainApp.gs(R.string.enableloop)); } else if (v == activeProfileView) { menu.setHeaderTitle(MainApp.gs(R.string.profile)); menu.add(MainApp.gs(R.string.danar_viewprofile)); @@ -496,13 +496,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) return true; - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); if (item.getTitle().equals(MainApp.gs(R.string.disableloop))) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.setPluginEnabled(PluginType.LOOP, false); activeloop.setFragmentVisible(PluginType.LOOP, false); MainApp.getConfigBuilder().storeSettings("DisablingLoop"); updateGUI("suspendmenu"); - MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { if (!result.success) { @@ -513,16 +513,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration return true; } else if (item.getTitle().equals(MainApp.gs(R.string.enableloop))) { - activeloop.setPluginEnabled(PluginType.LOOP, true); - activeloop.setFragmentVisible(PluginType.LOOP, true); + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + loopPlugin.setPluginEnabled(PluginType.LOOP, true); + loopPlugin.setFragmentVisible(PluginType.LOOP, true); MainApp.getConfigBuilder().storeSettings("EnablingLoop"); updateGUI("suspendmenu"); NSUpload.uploadOpenAPSOffline(0); return true; } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.suspendTo(0L); updateGUI("suspendmenu"); - MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { if (!result.success) {