Dedup pump activation confirmation.
This commit is contained in:
parent
efb44331b0
commit
cf1bcf9943
|
@ -1,8 +1,11 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -42,6 +45,28 @@ public abstract class PluginBase {
|
|||
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() {
|
||||
// return mainType;
|
||||
// }
|
||||
|
|
|
@ -164,33 +164,10 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
}
|
||||
|
||||
@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);
|
||||
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();
|
||||
}
|
||||
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
|
||||
confirmPumpPluginActivation(pluginSwitcher, activity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return pump.initialized;
|
||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.danaR;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
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
|
||||
public boolean isSuspended() {
|
||||
return DanaRPump.getInstance().pumpSuspended;
|
||||
|
|
|
@ -50,29 +50,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
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
|
||||
protected void onStart() {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
|
|
|
@ -53,30 +53,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
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
|
||||
protected void onStart() {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
|
|
|
@ -127,26 +127,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity activity) {
|
||||
confirmPumpPluginActivation(pluginSwitcher, activity);
|
||||
}
|
||||
|
||||
private ServiceConnection mConnection = new ServiceConnection() {
|
||||
|
|
|
@ -126,29 +126,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
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
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
|
|
Loading…
Reference in a new issue