Events to RxBus

This commit is contained in:
Milos Kozak 2019-10-15 00:54:30 +02:00
parent 837cb0d4a2
commit 06f8af82d8
22 changed files with 166 additions and 194 deletions

View file

@ -14,8 +14,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -102,7 +100,29 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException) .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 @Override
@ -128,7 +148,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
log.debug("onPause"); log.debug("onPause");
running = false; running = false;
super.onPause(); super.onPause();
MainApp.bus().unregister(this);
disposable.clear(); 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() { private void scheduleDismiss() {
if (L.isEnabled(L.UI)) if (L.isEnabled(L.UI))
log.debug("scheduleDismiss"); log.debug("scheduleDismiss");

View file

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

View file

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

View file

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

View file

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

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.general.wear;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventBolusRequested;
@ -70,7 +68,6 @@ public class WearPlugin extends PluginBase {
@Override @Override
protected void onStart() { protected void onStart() {
MainApp.bus().register(this);
if (watchUS != null) { if (watchUS != null) {
watchUS.setSettings(); watchUS.setSettings();
} }
@ -141,12 +138,40 @@ public class WearPlugin extends PluginBase {
ctx.startService(intent); ctx.startService(intent);
}, FabricPrivacy::logException }, 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 @Override
protected void onStop() { protected void onStop() {
MainApp.bus().unregister(this);
disposable.clear(); disposable.clear();
super.onStop(); super.onStop();
} }
@ -190,33 +215,6 @@ public class WearPlugin extends PluginBase {
ctx.startService(intent); 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) { public void requestActionConfirmation(String title, String message, String actionstring) {
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST); Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST);

View file

@ -433,26 +433,26 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
} }
private static BolusProgressReporter bolusProgressReporter = (state, percent, delivered) -> { private static BolusProgressReporter bolusProgressReporter = (state, percent, delivered) -> {
EventOverviewBolusProgress event = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress event = EventOverviewBolusProgress.INSTANCE;
switch (state) { switch (state) {
case PROGRAMMING: case PROGRAMMING:
event.status = MainApp.gs(R.string.combo_programming_bolus); event.setStatus(MainApp.gs(R.string.combo_programming_bolus));
break; break;
case DELIVERING: case DELIVERING:
event.status = MainApp.gs(R.string.bolusdelivering, delivered); event.setStatus(MainApp.gs(R.string.bolusdelivering, delivered));
break; break;
case DELIVERED: case DELIVERED:
event.status = MainApp.gs(R.string.bolusdelivered, delivered); event.setStatus(MainApp.gs(R.string.bolusdelivered, delivered));
break; break;
case STOPPING: case STOPPING:
event.status = MainApp.gs(R.string.bolusstopping); event.setStatus(MainApp.gs(R.string.bolusstopping));
break; break;
case STOPPED: case STOPPED:
event.status = MainApp.gs(R.string.bolusstopped); event.setStatus(MainApp.gs(R.string.bolusstopped));
break; break;
} }
event.percent = percent; event.setPercent(percent);
MainApp.bus().post(event); RxBus.INSTANCE.send(event);
}; };
/** /**
@ -474,11 +474,11 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
// no bolus required, carb only treatment // no bolus required, carb only treatment
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = new Treatment(); bolusingEvent.setT(new Treatment());
bolusingEvent.t.isSMB = detailedBolusInfo.isSMB; bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
return new PumpEnactResult().success(true).enacted(true) return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs) .bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
@ -558,7 +558,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
Treatment treatment = new Treatment(); Treatment treatment = new Treatment();
treatment.isSMB = detailedBolusInfo.isSMB; treatment.isSMB = detailedBolusInfo.isSMB;
EventOverviewBolusProgress.getInstance().t = treatment; EventOverviewBolusProgress.INSTANCE.setT(treatment);
// start bolus delivery // start bolus delivery
scripterIsBolusing = true; scripterIsBolusing = true;

View file

@ -418,11 +418,11 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
// no bolus required, carb only treatment // no bolus required, carb only treatment
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = new Treatment(); bolusingEvent.setT(new Treatment());
bolusingEvent.t.isSMB = detailedBolusInfo.isSMB; bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
if (isLoggingEnabled()) if (isLoggingEnabled())
LOG.debug("deliverTreatment: Carb only treatment."); LOG.debug("deliverTreatment: Carb only treatment.");

View file

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; 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.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
@ -37,15 +38,15 @@ public class MsgBolusProgress extends MessageBase {
lastReceive = System.currentTimeMillis(); lastReceive = System.currentTimeMillis();
Double done = (amount * 100 - progress) / 100d; Double done = (amount * 100 - progress) / 100d;
t.insulin = done; t.insulin = done;
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), done); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), done));
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = Math.min((int) (done / amount * 100), 100); bolusingEvent.setPercent(Math.min((int) (done / amount * 100), 100));
if (L.isEnabled(L.PUMPCOMM)) { if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Bolus remaining: " + progress + " delivered: " + done); log.debug("Bolus remaining: " + progress + " delivered: " + done);
} }
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
} }
} }

View file

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; 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.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
@ -35,15 +36,15 @@ public class MsgBolusStop extends MessageBase {
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Messsage received"); log.debug("Messsage received");
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
stopped = true; stopped = true;
if (!forced) { if (!forced) {
t.insulin = amount; t.insulin = amount;
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_delivered); bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_delivered));
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
} else { } 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);
} }
} }

View file

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; 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.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
@ -44,10 +45,10 @@ public class MsgError extends MessageBase {
} }
if (errorCode < 8) { // bolus delivering stopped if (errorCode < 8) { // bolus delivering stopped
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
MsgBolusStop.stopped = true; MsgBolusStop.stopped = true;
bolusingEvent.status = errorString; bolusingEvent.setStatus(errorString);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
failed=true; failed=true;
} }
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -334,9 +334,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
} }
SystemClock.sleep(300); SystemClock.sleep(300);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = 99; bolusingEvent.setPercent(99);
mBolusingTreatment = null; mBolusingTreatment = null;
@ -360,8 +360,8 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
while (System.currentTimeMillis() < expectedEnd) { while (System.currentTimeMillis() < expectedEnd) {
long waitTime = expectedEnd - System.currentTimeMillis(); long waitTime = expectedEnd - System.currentTimeMillis();
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
SystemClock.sleep(1000); SystemClock.sleep(1000);
} }

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.R;
import com.cozmo.danar.util.BleCommandUtil; import com.cozmo.danar.util.BleCommandUtil;
import info.nightscout.androidaps.logging.L; 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.treatments.Treatment;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; 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; stopped = true;
if (!forced) { if (!forced) {
t.insulin = amount; t.insulin = amount;
bolusingEvent.status = MainApp.gs(R.string.overview_bolusprogress_delivered); bolusingEvent.setStatus(MainApp.gs(R.string.overview_bolusprogress_delivered));
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
} else { } 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 @Override

View file

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; 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.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
@ -39,12 +40,12 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
if (t != null) { if (t != null) {
t.insulin = deliveredInsulin; t.insulin = deliveredInsulin;
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin));
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); bolusingEvent.setPercent(Math.min((int) (deliveredInsulin / amount * 100), 100));
done = true; done = true;
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
} }
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; 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.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.treatments.Treatment; 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) { if (t != null) {
lastReceive = System.currentTimeMillis(); lastReceive = System.currentTimeMillis();
t.insulin = deliveredInsulin; t.insulin = deliveredInsulin;
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), deliveredInsulin));
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); bolusingEvent.setPercent(Math.min((int) (deliveredInsulin / amount * 100), 100));
failed = bolusingEvent.percent < 100? true: false; failed = bolusingEvent.getPercent() < 100? true: false;
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
} }
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -335,9 +335,9 @@ public class DanaRSService extends Service {
} }
} }
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = 99; bolusingEvent.setPercent(99);
bolusingTreatment = null; bolusingTreatment = null;
int speed = 12; int speed = 12;
@ -356,8 +356,8 @@ public class DanaRSService extends Service {
long expectedEnd = bolusStart + bolusDurationInMSec + 2000; long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
while (System.currentTimeMillis() < expectedEnd) { while (System.currentTimeMillis() < expectedEnd) {
long waitTime = expectedEnd - System.currentTimeMillis(); long waitTime = expectedEnd - System.currentTimeMillis();
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
SystemClock.sleep(1000); SystemClock.sleep(1000);
} }
// do not call loadEvents() directly, reconnection may be needed // do not call loadEvents() directly, reconnection may be needed
@ -367,7 +367,7 @@ public class DanaRSService extends Service {
// reread bolus status // reread bolus status
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus))); RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus 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))); RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.disconnecting)));
} }
}); });

View file

@ -403,9 +403,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
} }
} }
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.percent = 99; bolusingEvent.setPercent(99);
mBolusingTreatment = null; mBolusingTreatment = null;
int speed = 12; int speed = 12;
@ -424,8 +424,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
long expectedEnd = bolusStart + bolusDurationInMSec + 2000; long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
while (System.currentTimeMillis() < expectedEnd) { while (System.currentTimeMillis() < expectedEnd) {
long waitTime = expectedEnd - System.currentTimeMillis(); long waitTime = expectedEnd - System.currentTimeMillis();
bolusingEvent.status = String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
SystemClock.sleep(1000); SystemClock.sleep(1000);
} }
// do not call loadEvents() directly, reconnection may be needed // do not call loadEvents() directly, reconnection may be needed
@ -435,7 +435,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
// load last bolus status // load last bolus status
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus))); RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
mSerialIOThread.sendMessage(new MsgStatus()); mSerialIOThread.sendMessage(new MsgStatus());
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.disconnecting))); RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.disconnecting)));
} }
}); });

View file

@ -555,11 +555,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
result.enacted = true; result.enacted = true;
Treatment t = new Treatment(); Treatment t = new Treatment();
t.isSMB = detailedBolusInfo.isSMB; t.isSMB = detailedBolusInfo.isSMB;
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.t = t; bolusingEvent.setT(t);
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, insulin); bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, 0d, insulin));
bolusingEvent.percent = 0; bolusingEvent.setPercent(0);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
int trials = 0; int trials = 0;
InsightBolusID insightBolusID = new InsightBolusID(); InsightBolusID insightBolusID = new InsightBolusID();
insightBolusID.bolusID = bolusID; insightBolusID.bolusID = bolusID;
@ -586,18 +586,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
} }
if (activeBolus != null) { if (activeBolus != null) {
trials = -1; trials = -1;
int percentBefore = bolusingEvent.percent; int percentBefore = bolusingEvent.getPercent();
bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount())); bolusingEvent.setPercent((int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount())));
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()); bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()));
if (percentBefore != bolusingEvent.percent) if (percentBefore != bolusingEvent.getPercent())
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
} else { } else {
synchronized ($bolusLock) { synchronized ($bolusLock) {
if (bolusCancelled || trials == -1 || trials++ >= 5) { if (bolusCancelled || trials == -1 || trials++ >= 5) {
if (!bolusCancelled) { if (!bolusCancelled) {
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, insulin, insulin); bolusingEvent.setStatus(MainApp.gs(R.string.insight_delivered, insulin, insulin));
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
} }
break; break;
} }

View file

@ -271,17 +271,17 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
while (delivering < detailedBolusInfo.insulin) { while (delivering < detailedBolusInfo.insulin) {
SystemClock.sleep(200); SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), delivering); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), delivering));
bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100); bolusingEvent.setPercent(Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100));
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
delivering += 0.1d; delivering += 0.1d;
} }
SystemClock.sleep(200); SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivered), detailedBolusInfo.insulin); bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivered), detailedBolusInfo.insulin));
bolusingEvent.percent = 100; bolusingEvent.setPercent(100);
MainApp.bus().post(bolusingEvent); RxBus.INSTANCE.send(bolusingEvent);
SystemClock.sleep(1000); SystemClock.sleep(1000);
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);

View file

@ -275,7 +275,7 @@ public class CommandQueue {
public synchronized void cancelAllBoluses() { public synchronized void cancelAllBoluses() {
if (!isRunning(Command.CommandType.BOLUS)) { 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.BOLUS);
removeAll(Command.CommandType.SMB_BOLUS); removeAll(Command.CommandType.SMB_BOLUS);

View file

@ -68,7 +68,7 @@ public class QueueThread extends Thread {
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000; long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { 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))); RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.connectiontimedout)));
if (L.isEnabled(L.PUMPQUEUE)) if (L.isEnabled(L.PUMPQUEUE))
log.debug("timed out"); log.debug("timed out");

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L; 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.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; 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); PumpEnactResult r = ConfigBuilderPlugin.getPlugin().getActivePump().deliverTreatment(detailedBolusInfo);
BolusProgressDialog.bolusEnded = true; BolusProgressDialog.bolusEnded = true;
MainApp.bus().post(new EventDismissBolusprogressIfRunning(r)); RxBus.INSTANCE.send(new EventDismissBolusprogressIfRunning(r));
if (L.isEnabled(L.PUMPQUEUE)) if (L.isEnabled(L.PUMPQUEUE))
log.debug("Result success: " + r.success + " enacted: " + r.enacted); log.debug("Result success: " + r.success + " enacted: " + r.enacted);