diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index ed9b5672a2..9f3e4fe5c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -1,11 +1,13 @@ package info.nightscout.androidaps.interfaces; import android.os.SystemClock; +import android.support.v4.app.FragmentActivity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; /** @@ -32,6 +34,12 @@ public abstract class PluginBase { this.pluginDescription = pluginDescription; } + // Default always calls invoke + // Plugins that have special constraints if they get switched to may override this method + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) { + pluginSwitcher.invoke(); + } + // public PluginType getType() { // return mainType; // } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index c2ab2bdfdb..3e60ca2b77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -187,7 +187,7 @@ public class ConfigBuilderFragment extends SubscriberFragment { } } - class PluginViewHolder { + public class PluginViewHolder { private Unbinder unbinder; private PluginType pluginType; @@ -248,16 +248,7 @@ public class ConfigBuilderFragment extends SubscriberFragment { @OnClick({R.id.plugin_enabled_exclusive, R.id.plugin_enabled_inclusive}) void onEnabledChanged() { - boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked(); - plugin.setPluginEnabled(pluginType, enabled); - plugin.setFragmentVisible(pluginType, enabled); - processOnEnabledCategoryChanged(plugin, pluginType); - updateGUI(); - ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); - MainApp.bus().post(new EventRefreshGui()); - MainApp.bus().post(new EventConfigBuilderChange()); - ConfigBuilderPlugin.getPlugin().logPluginStatus(); - FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange")); + plugin.switchAllowed(new PluginSwitcher(), getActivity()); } @OnClick(R.id.plugin_preferences) @@ -273,6 +264,23 @@ public class ConfigBuilderFragment extends SubscriberFragment { unbinder.unbind(); } - } + public class PluginSwitcher { + public void invoke() { + boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked(); + plugin.setPluginEnabled(pluginType, enabled); + plugin.setFragmentVisible(pluginType, enabled); + processOnEnabledCategoryChanged(plugin, pluginType); + updateGUI(); + ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); + MainApp.bus().post(new EventRefreshGui()); + MainApp.bus().post(new EventConfigBuilderChange()); + ConfigBuilderPlugin.getPlugin().logPluginStatus(); + FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange")); + } + public void cancel(){ + updateGUI(); + } + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 442e7bdd9f..016fbf6732 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1,8 +1,11 @@ package info.nightscout.androidaps.plugins.PumpCombo; +import android.content.DialogInterface; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; import com.crashlytics.android.answers.CustomEvent; @@ -28,6 +31,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -194,6 +198,32 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return MainApp.gs(R.string.combo_pump_state_running); } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + + @Override public boolean isInitialized() { return pump.initialized; 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 b1b0f3d9ce..77146738d9 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 @@ -2,9 +2,12 @@ package info.nightscout.androidaps.plugins.PumpDanaR; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; import com.squareup.otto.Subscribe; @@ -18,6 +21,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; @@ -78,6 +82,31 @@ public class DanaRPlugin extends AbstractDanaRPlugin { pumpDescription.needsManualTDDLoad = true; } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + @Override protected void onStart() { Context context = MainApp.instance().getApplicationContext(); 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 4ae239cab9..9ce1a6409a 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 @@ -2,9 +2,12 @@ package info.nightscout.androidaps.plugins.PumpDanaRKorean; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; import com.squareup.otto.Subscribe; @@ -23,6 +26,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; @@ -80,6 +84,32 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { pumpDescription.needsManualTDDLoad = true; } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + + @Override protected void onStart() { Context context = MainApp.instance().getApplicationContext(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 8b1e51d8dd..037abd8c23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -2,10 +2,13 @@ package info.nightscout.androidaps.plugins.PumpDanaRS; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; import com.squareup.otto.Subscribe; @@ -36,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -147,6 +151,31 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte MainApp.bus().unregister(this); } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + 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 abd8a08f0b..c88d62ecc7 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 @@ -2,9 +2,12 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; import com.squareup.otto.Subscribe; @@ -20,6 +23,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; @@ -140,6 +144,31 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { return pump.lastConnection > 0 && pump.maxBasal > 0; } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + // Pump interface @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index 9fb98d3175..bf2c9ec09b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -1,5 +1,9 @@ package info.nightscout.androidaps.plugins.PumpInsight; +import android.content.DialogInterface; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; + import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -27,6 +31,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -203,6 +208,31 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai return result; } + @Override + public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { + boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); + if (allowHardwarePump || context == null){ + pluginSwitcher.invoke(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(R.string.allow_hardware_pump_text) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.invoke(); + SP.putBoolean("allow_hardware_pump", true); + log.debug("First time HW pump allowed!"); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pluginSwitcher.cancel(); + log.debug("User does not allow switching to HW pump!"); + } + }); + builder.create().show(); + } + } + @Override public boolean isInitialized() { return initialized; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b940b328a1..70d5c05e58 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1178,6 +1178,7 @@ keep_screen_on Clean AndroidAPS started Stored settings found + Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time. %d day