bolus progress dialog during connection
This commit is contained in:
parent
25aa5094a4
commit
c7faf2a5e7
|
@ -78,14 +78,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
private static ArrayList<PluginBase> pluginList;
|
private static ArrayList<PluginBase> pluginList;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
|
|
||||||
private static CommandQueue commandQueue = new CommandQueue();
|
private static CommandQueue commandQueue = new CommandQueue();
|
||||||
|
|
||||||
public ConfigBuilderPlugin() {
|
public ConfigBuilderPlugin() {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -479,33 +475,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
mWakeLock.acquire();
|
|
||||||
PumpEnactResult result;
|
|
||||||
detailedBolusInfo.insulin = applyBolusConstraints(detailedBolusInfo.insulin);
|
|
||||||
detailedBolusInfo.carbs = applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
|
||||||
|
|
||||||
BolusProgressDialog bolusProgressDialog = null;
|
|
||||||
if (detailedBolusInfo.context != null) {
|
|
||||||
bolusProgressDialog = new BolusProgressDialog();
|
|
||||||
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
|
||||||
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
|
||||||
} else {
|
|
||||||
Intent i = new Intent();
|
|
||||||
i.putExtra("insulin", detailedBolusInfo.insulin);
|
|
||||||
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
|
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
MainApp.instance().startActivity(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
||||||
|
|
||||||
result = activePump.deliverTreatment(detailedBolusInfo);
|
PumpEnactResult result = activePump.deliverTreatment(detailedBolusInfo);
|
||||||
|
|
||||||
BolusProgressDialog.bolusEnded = true;
|
BolusProgressDialog.bolusEnded = true;
|
||||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
|
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
|
||||||
|
|
||||||
mWakeLock.release();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
@ -13,6 +15,8 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity;
|
||||||
import info.nightscout.androidaps.queue.commands.Command;
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandBolus;
|
import info.nightscout.androidaps.queue.commands.CommandBolus;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
||||||
|
@ -144,6 +148,23 @@ public class CommandQueue {
|
||||||
|
|
||||||
notifyAboutNewCommand();
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
// Bring up bolus progress dialog
|
||||||
|
detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
|
detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
||||||
|
|
||||||
|
BolusProgressDialog bolusProgressDialog = null;
|
||||||
|
if (detailedBolusInfo.context != null) {
|
||||||
|
bolusProgressDialog = new BolusProgressDialog();
|
||||||
|
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
||||||
|
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
||||||
|
} else {
|
||||||
|
Intent i = new Intent();
|
||||||
|
i.putExtra("insulin", detailedBolusInfo.insulin);
|
||||||
|
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -8,9 +10,11 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
||||||
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,18 +28,24 @@ public class QueueThread extends Thread {
|
||||||
|
|
||||||
private long connectionStartTime = 0;
|
private long connectionStartTime = 0;
|
||||||
|
|
||||||
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
public QueueThread(CommandQueue queue) {
|
public QueueThread(CommandQueue queue) {
|
||||||
super(QueueThread.class.toString());
|
super(QueueThread.class.toString());
|
||||||
|
|
||||||
this.queue = queue;
|
this.queue = queue;
|
||||||
|
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "QueueThread");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run() {
|
public final void run() {
|
||||||
|
mWakeLock.acquire();
|
||||||
MainApp.bus().post(new EventQueueChanged());
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
connectionStartTime = System.currentTimeMillis();
|
connectionStartTime = System.currentTimeMillis();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
log.debug("Looping ...");
|
log.debug("Looping ...");
|
||||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||||
|
@ -48,6 +58,7 @@ public class QueueThread extends Thread {
|
||||||
|
|
||||||
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
||||||
log.debug("State: timed out");
|
log.debug("State: timed out");
|
||||||
|
MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult()));
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
||||||
pump.stopConnecting();
|
pump.stopConnecting();
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
@ -84,6 +95,9 @@ public class QueueThread extends Thread {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue