ask user if he switches to a HW pump for the first time

This commit is contained in:
AdrianLxM 2018-06-29 03:52:58 +02:00
parent d8603f07be
commit 5a1d696ab1
9 changed files with 206 additions and 12 deletions

View file

@ -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;
// }

View file

@ -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();
}
}
}
}

View file

@ -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;

View file

@ -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();

View file

@ -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();

View file

@ -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) {

View file

@ -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) {

View file

@ -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;

View file

@ -1178,6 +1178,7 @@
<string name="key_keep_screen_on" translatable="false">keep_screen_on</string>
<string name="careportal_removestartedevents">Clean AndroidAPS started</string>
<string name="storedsettingsfound">Stored settings found</string>
<string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will be synchronizing the basal settings with the pump and overwrite them. 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.</string>
<plurals name="objective_days">
<item quantity="one">%d day</item>