Merge pull request #1887 from jotomo/pump-activation-warning

Pump activation warning
This commit is contained in:
Milos Kozak 2019-07-25 23:59:11 +02:00 committed by GitHub
commit bd22bddd2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 115 deletions

View file

@ -1,8 +1,11 @@
package info.nightscout.androidaps.interfaces; package info.nightscout.androidaps.interfaces;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.SP;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -42,6 +45,28 @@ public abstract class PluginBase {
pluginSwitcher.invoke(); pluginSwitcher.invoke();
} }
protected void confirmPumpPluginActivation(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false);
if (allowHardwarePump || activity == null) {
pluginSwitcher.invoke();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
}
}
// public PluginType getType() { // public PluginType getType() {
// return mainType; // return mainType;
// } // }

View file

@ -164,32 +164,9 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
} }
@Override @Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); confirmPumpPluginActivation(pluginSwitcher, activity);
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);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
} }
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
}
});
builder.create().show();
}
}
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.common;
import java.util.Date; import java.util.Date;
import androidx.fragment.app.FragmentActivity;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -105,6 +107,10 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
*/ */
public abstract void onStartCustomActions(); public abstract void onStartCustomActions();
@Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
confirmPumpPluginActivation(pluginSwitcher, activity);
}
/** /**
* Service class (same one you did serviceConnection for) * Service class (same one you did serviceConnection for)

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.danaR;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -77,6 +79,11 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
} }
} }
@Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
confirmPumpPluginActivation(pluginSwitcher, activity);
}
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return DanaRPump.getInstance().pumpSuspended; return DanaRPump.getInstance().pumpSuspended;

View file

@ -50,29 +50,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
pumpDescription.setPumpDescription(PumpType.DanaR); pumpDescription.setPumpDescription(PumpType.DanaR);
} }
@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, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
}
}
@Override @Override
protected void onStart() { protected void onStart() {
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();

View file

@ -53,30 +53,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
pumpDescription.setPumpDescription(PumpType.DanaRKorean); pumpDescription.setPumpDescription(PumpType.DanaRKorean);
} }
@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, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
}
}
@Override @Override
protected void onStart() { protected void onStart() {
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();

View file

@ -127,26 +127,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
@Override @Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); confirmPumpPluginActivation(pluginSwitcher, activity);
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, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
}
} }
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {

View file

@ -126,29 +126,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
sExecutionService.finishHandshaking(); sExecutionService.finishHandshaking();
} }
@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, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
}
}
// Pump interface // Pump interface
@Override @Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {

View file

@ -8,7 +8,9 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import androidx.fragment.app.FragmentActivity;
import info.nightscout.androidaps.plugins.common.ManufacturerType; import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.*; import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.*;
@ -229,6 +231,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
MainApp.instance().unbindService(serviceConnection); MainApp.instance().unbindService(serviceConnection);
} }
@Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
confirmPumpPluginActivation(pluginSwitcher, activity);
}
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return connectionService != null && alertService != null && connectionService.isPaired(); return connectionService != null && alertService != null && connectionService.isPaired();