From 06f8af82d830e5edf0bc437a76f0b2b6e724cc08 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 15 Oct 2019 00:54:30 +0200 Subject: [PATCH] Events to RxBus --- .../overview/dialogs/BolusProgressDialog.java | 54 +++++++---------- .../EventDismissBolusprogressIfRunning.java | 16 ----- .../EventDismissBolusprogressIfRunning.kt | 6 ++ .../events/EventOverviewBolusProgress.java | 27 --------- .../events/EventOverviewBolusProgress.kt | 12 ++++ .../plugins/general/wear/WearPlugin.java | 60 +++++++++---------- .../plugins/pump/combo/ComboPlugin.java | 28 ++++----- .../pump/common/PumpPluginAbstract.java | 10 ++-- .../pump/danaR/comm/MsgBolusProgress.java | 11 ++-- .../plugins/pump/danaR/comm/MsgBolusStop.java | 11 ++-- .../plugins/pump/danaR/comm/MsgError.java | 7 ++- .../danaR/services/DanaRExecutionService.java | 10 ++-- ...naRS_Packet_Bolus_Set_Step_Bolus_Stop.java | 11 ++-- ...anaRS_Packet_Notify_Delivery_Complete.java | 11 ++-- ...S_Packet_Notify_Delivery_Rate_Display.java | 13 ++-- .../pump/danaRS/services/DanaRSService.java | 12 ++-- .../services/DanaRv2ExecutionService.java | 12 ++-- .../pump/insight/LocalInsightPlugin.java | 26 ++++---- .../pump/virtual/VirtualPumpPlugin.java | 16 ++--- .../androidaps/queue/CommandQueue.java | 2 +- .../androidaps/queue/QueueThread.java | 2 +- .../queue/commands/CommandBolus.java | 3 +- 22 files changed, 166 insertions(+), 194 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java index 35c8edd656..0ac9cbdafd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java @@ -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"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java deleted file mode 100644 index 2022a4d74b..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.kt new file mode 100644 index 0000000000..94482729b6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.kt @@ -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() \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java deleted file mode 100644 index 3a7c50faac..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java +++ /dev/null @@ -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; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt new file mode 100644 index 0000000000..52b62790da --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt @@ -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 +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java index cf3cc6b783..f60484cb80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java @@ -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); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index e867189a80..aeb5b0224c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 496859f38f..6544b1b0b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -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."); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java index 6fb1993237..362b72c929 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java @@ -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); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java index 39531b8b10..2ea50297fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java @@ -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); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java index f697894778..a6fdaa8d0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java @@ -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)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index f9029ca9aa..cc458eb3f8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -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); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java index 5e3fe3fbcd..7cb0a11f9b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java @@ -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 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java index 3c916dc399..00b6483fbb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java @@ -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)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java index 290e9743ef..1d650cb779 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java @@ -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)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index 5e6de8f5cf..50dd9fef1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -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))); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 3dd68f1af3..7c2cc7ede5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -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))); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 99118549a2..de857b77ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -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; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index bedd330f51..447367c510 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -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); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index cd0b666119..18e98dc4f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -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); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 7016c217dc..2c6bd0f64c 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -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"); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java index 4dc132e128..f49a37612a 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java @@ -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);