Events to RxBus
This commit is contained in:
parent
837cb0d4a2
commit
06f8af82d8
22 changed files with 166 additions and 194 deletions
|
@ -14,8 +14,6 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -102,7 +100,29 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
||||
);
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventDismissBolusprogressIfRunning.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.UI)) log.debug("EventDismissBolusprogressIfRunning");
|
||||
if (BolusProgressDialog.running) dismiss();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventOverviewBolusProgress.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.UI))
|
||||
log.debug("Status: " + event.getStatus() + " Percent: " + event.getPercent());
|
||||
statusView.setText(event.getStatus());
|
||||
progressBar.setProgress(event.getPercent());
|
||||
if (event.getPercent() == 100) {
|
||||
stopButton.setVisibility(View.INVISIBLE);
|
||||
scheduleDismiss();
|
||||
}
|
||||
state = event.getStatus();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +148,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
|||
log.debug("onPause");
|
||||
running = false;
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
|
@ -153,33 +172,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(() -> {
|
||||
if (L.isEnabled(L.UI))
|
||||
log.debug("Status: " + ev.status + " Percent: " + ev.percent);
|
||||
statusView.setText(ev.status);
|
||||
progressBar.setProgress(ev.percent);
|
||||
if (ev.percent == 100) {
|
||||
stopButton.setVisibility(View.INVISIBLE);
|
||||
scheduleDismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
state = ev.status;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
||||
if (L.isEnabled(L.UI))
|
||||
log.debug("EventDismissBolusprogressIfRunning");
|
||||
if (BolusProgressDialog.running) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleDismiss() {
|
||||
if (L.isEnabled(L.UI))
|
||||
log.debug("scheduleDismiss");
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events;
|
||||
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
/**
|
||||
* Created by adrian on 20/02/17.
|
||||
*/
|
||||
|
||||
public class EventDismissBolusprogressIfRunning extends Event {
|
||||
public final PumpEnactResult result;
|
||||
|
||||
public EventDismissBolusprogressIfRunning(PumpEnactResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events
|
||||
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.events.Event
|
||||
|
||||
class EventDismissBolusprogressIfRunning(val result: PumpEnactResult) : Event()
|
|
@ -1,27 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events;
|
||||
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
public class EventOverviewBolusProgress extends Event {
|
||||
public String status = "";
|
||||
public Treatment t = null;
|
||||
public int percent = 0;
|
||||
public int bolusId;
|
||||
private static EventOverviewBolusProgress eventOverviewBolusProgress = null;
|
||||
|
||||
public EventOverviewBolusProgress() {
|
||||
}
|
||||
|
||||
public boolean isSMB(){
|
||||
return (t != null) && t.isSMB;
|
||||
}
|
||||
|
||||
public static EventOverviewBolusProgress getInstance() {
|
||||
if(eventOverviewBolusProgress == null) {
|
||||
eventOverviewBolusProgress = new EventOverviewBolusProgress();
|
||||
}
|
||||
return eventOverviewBolusProgress;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events
|
||||
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.events.Event
|
||||
|
||||
object EventOverviewBolusProgress : Event() {
|
||||
var status = ""
|
||||
var t: Treatment? = null
|
||||
var percent = 0
|
||||
|
||||
fun isSMB(): Boolean = t?.isSMB ?: false
|
||||
}
|
|
@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.general.wear;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
||||
|
@ -70,7 +68,6 @@ public class WearPlugin extends PluginBase {
|
|||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
if (watchUS != null) {
|
||||
watchUS.setSettings();
|
||||
}
|
||||
|
@ -141,12 +138,40 @@ public class WearPlugin extends PluginBase {
|
|||
ctx.startService(intent);
|
||||
}, FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventDismissBolusprogressIfRunning.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (event.getResult() == null) return;
|
||||
String status;
|
||||
if (event.getResult().success) {
|
||||
status = MainApp.gs(R.string.success);
|
||||
} else {
|
||||
status = MainApp.gs(R.string.nosuccess);
|
||||
}
|
||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||
intent.putExtra("progresspercent", 100);
|
||||
intent.putExtra("progressstatus", status);
|
||||
ctx.startService(intent);
|
||||
}, FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventOverviewBolusProgress.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (!event.isSMB() || SP.getBoolean("wear_notifySMB", true)) {
|
||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||
intent.putExtra("progresspercent", event.getPercent());
|
||||
intent.putExtra("progressstatus", event.getStatus());
|
||||
ctx.startService(intent);
|
||||
}
|
||||
}, FabricPrivacy::logException
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
@ -190,33 +215,6 @@ public class WearPlugin extends PluginBase {
|
|||
ctx.startService(intent);
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||
if (!ev.isSMB() || SP.getBoolean("wear_notifySMB", true)) {
|
||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||
intent.putExtra("progresspercent", ev.percent);
|
||||
intent.putExtra("progressstatus", ev.status);
|
||||
ctx.startService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
||||
if (ev.result == null) return;
|
||||
|
||||
String status;
|
||||
if (ev.result.success) {
|
||||
status = MainApp.gs(R.string.success);
|
||||
} else {
|
||||
status = MainApp.gs(R.string.nosuccess);
|
||||
}
|
||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||
intent.putExtra("progresspercent", 100);
|
||||
intent.putExtra("progressstatus", status);
|
||||
ctx.startService(intent);
|
||||
}
|
||||
|
||||
public void requestActionConfirmation(String title, String message, String actionstring) {
|
||||
|
||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST);
|
||||
|
|
|
@ -433,26 +433,26 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
}
|
||||
|
||||
private static BolusProgressReporter bolusProgressReporter = (state, percent, delivered) -> {
|
||||
EventOverviewBolusProgress event = EventOverviewBolusProgress.getInstance();
|
||||
EventOverviewBolusProgress event = EventOverviewBolusProgress.INSTANCE;
|
||||
switch (state) {
|
||||
case PROGRAMMING:
|
||||
event.status = MainApp.gs(R.string.combo_programming_bolus);
|
||||
event.setStatus(MainApp.gs(R.string.combo_programming_bolus));
|
||||
break;
|
||||
case DELIVERING:
|
||||
event.status = MainApp.gs(R.string.bolusdelivering, delivered);
|
||||
event.setStatus(MainApp.gs(R.string.bolusdelivering, delivered));
|
||||
break;
|
||||
case DELIVERED:
|
||||
event.status = MainApp.gs(R.string.bolusdelivered, delivered);
|
||||
event.setStatus(MainApp.gs(R.string.bolusdelivered, delivered));
|
||||
break;
|
||||
case STOPPING:
|
||||
event.status = MainApp.gs(R.string.bolusstopping);
|
||||
event.setStatus(MainApp.gs(R.string.bolusstopping));
|
||||
break;
|
||||
case STOPPED:
|
||||
event.status = MainApp.gs(R.string.bolusstopped);
|
||||
event.setStatus(MainApp.gs(R.string.bolusstopped));
|
||||
break;
|
||||
}
|
||||
event.percent = percent;
|
||||
MainApp.bus().post(event);
|
||||
event.setPercent(percent);
|
||||
RxBus.INSTANCE.send(event);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -474,11 +474,11 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
// no bolus required, carb only treatment
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = new Treatment();
|
||||
bolusingEvent.t.isSMB = detailedBolusInfo.isSMB;
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(new Treatment());
|
||||
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
|
||||
|
@ -558,7 +558,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
|
||||
Treatment treatment = new Treatment();
|
||||
treatment.isSMB = detailedBolusInfo.isSMB;
|
||||
EventOverviewBolusProgress.getInstance().t = treatment;
|
||||
EventOverviewBolusProgress.INSTANCE.setT(treatment);
|
||||
|
||||
// start bolus delivery
|
||||
scripterIsBolusing = true;
|
||||
|
|
|
@ -418,11 +418,11 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// no bolus required, carb only treatment
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = new Treatment();
|
||||
bolusingEvent.t.isSMB = detailedBolusInfo.isSMB;
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(new Treatment());
|
||||
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
|
||||
if (isLoggingEnabled())
|
||||
LOG.debug("deliverTreatment: Carb only treatment.");
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
|
||||
|
@ -37,15 +38,15 @@ public class MsgBolusProgress extends MessageBase {
|
|||
lastReceive = System.currentTimeMillis();
|
||||
Double done = (amount * 100 - progress) / 100d;
|
||||
t.insulin = done;
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), done);
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = Math.min((int) (done / amount * 100), 100);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), done));
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(Math.min((int) (done / amount * 100), 100));
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM)) {
|
||||
log.debug("Bolus remaining: " + progress + " delivered: " + done);
|
||||
}
|
||||
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
|
||||
|
@ -35,15 +36,15 @@ public class MsgBolusStop extends MessageBase {
|
|||
public void handleMessage(byte[] bytes) {
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Messsage received");
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
stopped = true;
|
||||
if (!forced) {
|
||||
t.insulin = amount;
|
||||
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_delivered);
|
||||
bolusingEvent.percent = 100;
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_delivered));
|
||||
bolusingEvent.setPercent(100);
|
||||
} else {
|
||||
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_stoped);
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_stoped));
|
||||
}
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
|
||||
|
@ -44,10 +45,10 @@ public class MsgError extends MessageBase {
|
|||
}
|
||||
|
||||
if (errorCode < 8) { // bolus delivering stopped
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
MsgBolusStop.stopped = true;
|
||||
bolusingEvent.status = errorString;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
bolusingEvent.setStatus(errorString);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
failed=true;
|
||||
}
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
|
|
@ -334,9 +334,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
SystemClock.sleep(300);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(99);
|
||||
|
||||
mBolusingTreatment = null;
|
||||
|
||||
|
@ -360,8 +360,8 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.R;
|
|||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
|
||||
|
@ -47,16 +48,16 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet {
|
|||
}
|
||||
}
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
stopped = true;
|
||||
if (!forced) {
|
||||
t.insulin = amount;
|
||||
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_delivered);
|
||||
bolusingEvent.percent = 100;
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_delivered));
|
||||
bolusingEvent.setPercent(100);
|
||||
} else {
|
||||
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_stoped);
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_stoped));
|
||||
}
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
|
||||
|
@ -39,12 +40,12 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
|
|||
|
||||
if (t != null) {
|
||||
t.insulin = deliveredInsulin;
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin);
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin));
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(Math.min((int) (deliveredInsulin / amount * 100), 100));
|
||||
done = true;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
|
||||
|
@ -40,12 +41,12 @@ public class DanaRS_Packet_Notify_Delivery_Rate_Display extends DanaRS_Packet {
|
|||
if (t != null) {
|
||||
lastReceive = System.currentTimeMillis();
|
||||
t.insulin = deliveredInsulin;
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin);
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100);
|
||||
failed = bolusingEvent.percent < 100? true: false;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin));
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(Math.min((int) (deliveredInsulin / amount * 100), 100));
|
||||
failed = bolusingEvent.getPercent() < 100? true: false;
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
|
|
@ -335,9 +335,9 @@ public class DanaRSService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(99);
|
||||
|
||||
bolusingTreatment = null;
|
||||
int speed = 12;
|
||||
|
@ -356,8 +356,8 @@ public class DanaRSService extends Service {
|
|||
long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
// do not call loadEvents() directly, reconnection may be needed
|
||||
|
@ -367,7 +367,7 @@ public class DanaRSService extends Service {
|
|||
// reread bolus status
|
||||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
|
||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
||||
bolusingEvent.percent = 100;
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.disconnecting)));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -403,9 +403,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setPercent(99);
|
||||
|
||||
mBolusingTreatment = null;
|
||||
int speed = 12;
|
||||
|
@ -424,8 +424,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
// do not call loadEvents() directly, reconnection may be needed
|
||||
|
@ -435,7 +435,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
// load last bolus status
|
||||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
|
||||
mSerialIOThread.sendMessage(new MsgStatus());
|
||||
bolusingEvent.percent = 100;
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.disconnecting)));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -555,11 +555,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
|||
result.enacted = true;
|
||||
Treatment t = new Treatment();
|
||||
t.isSMB = detailedBolusInfo.isSMB;
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, insulin);
|
||||
bolusingEvent.percent = 0;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setT(t);
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, 0d, insulin));
|
||||
bolusingEvent.setPercent(0);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
int trials = 0;
|
||||
InsightBolusID insightBolusID = new InsightBolusID();
|
||||
insightBolusID.bolusID = bolusID;
|
||||
|
@ -586,18 +586,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
|||
}
|
||||
if (activeBolus != null) {
|
||||
trials = -1;
|
||||
int percentBefore = bolusingEvent.percent;
|
||||
bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount()));
|
||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
|
||||
if (percentBefore != bolusingEvent.percent)
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
int percentBefore = bolusingEvent.getPercent();
|
||||
bolusingEvent.setPercent((int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount())));
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()));
|
||||
if (percentBefore != bolusingEvent.getPercent())
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
} else {
|
||||
synchronized ($bolusLock) {
|
||||
if (bolusCancelled || trials == -1 || trials++ >= 5) {
|
||||
if (!bolusCancelled) {
|
||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, insulin, insulin);
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, insulin, insulin));
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -271,17 +271,17 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
|
||||
while (delivering < detailedBolusInfo.insulin) {
|
||||
SystemClock.sleep(200);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), delivering);
|
||||
bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), delivering));
|
||||
bolusingEvent.setPercent(Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100));
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
delivering += 0.1d;
|
||||
}
|
||||
SystemClock.sleep(200);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivered), detailedBolusInfo.insulin);
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivered), detailedBolusInfo.insulin));
|
||||
bolusingEvent.setPercent(100);
|
||||
RxBus.INSTANCE.send(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
|
||||
|
|
|
@ -275,7 +275,7 @@ public class CommandQueue {
|
|||
|
||||
public synchronized void cancelAllBoluses() {
|
||||
if (!isRunning(Command.CommandType.BOLUS)) {
|
||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult().success(true).enacted(false)));
|
||||
RxBus.INSTANCE.send(new EventDismissBolusprogressIfRunning(new PumpEnactResult().success(true).enacted(false)));
|
||||
}
|
||||
removeAll(Command.CommandType.BOLUS);
|
||||
removeAll(Command.CommandType.SMB_BOLUS);
|
||||
|
|
|
@ -68,7 +68,7 @@ public class QueueThread extends Thread {
|
|||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||
|
||||
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(null));
|
||||
RxBus.INSTANCE.send(new EventDismissBolusprogressIfRunning(null));
|
||||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.connectiontimedout)));
|
||||
if (L.isEnabled(L.PUMPQUEUE))
|
||||
log.debug("timed out");
|
||||
|
|
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning;
|
||||
|
@ -33,7 +34,7 @@ public class CommandBolus extends Command {
|
|||
PumpEnactResult r = ConfigBuilderPlugin.getPlugin().getActivePump().deliverTreatment(detailedBolusInfo);
|
||||
|
||||
BolusProgressDialog.bolusEnded = true;
|
||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(r));
|
||||
RxBus.INSTANCE.send(new EventDismissBolusprogressIfRunning(r));
|
||||
if (L.isEnabled(L.PUMPQUEUE))
|
||||
log.debug("Result success: " + r.success + " enacted: " + r.enacted);
|
||||
|
||||
|
|
Loading…
Reference in a new issue