diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 12ec4dfca7..07c4655de7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -64,7 +64,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte @Override public void onStateChange(PluginType type, State oldState, State newState) { // if pump profile was enabled need to switch to another too - if (type == PluginType.PUMP && newState == State.DISABLED && isProfileInterfaceEnabled) { + if (type == PluginType.PUMP && newState == State.ENABLED && newState == State.DISABLED && isProfileInterfaceEnabled) { setPluginEnabled(PluginType.PROFILE, false); NSProfilePlugin.getPlugin().setPluginEnabled(PluginType.PROFILE, true); NSProfilePlugin.getPlugin().setFragmentVisible(PluginType.PROFILE, true); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 0e118df96a..f90d529987 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -46,11 +46,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.05d; @@ -78,6 +73,22 @@ public class DanaRPlugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 94adcc6f82..44a805fadf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -26,6 +26,8 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -47,11 +49,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRKoreanPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRKoreanExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.1d; @@ -79,6 +76,22 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRKoreanExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 3f372de5db..74edcac728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -23,6 +23,8 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -44,11 +46,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRv2Plugin.class); useExtendedBoluses = false; - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRv2ExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.05d; @@ -78,6 +75,23 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRv2ExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) {