fix BolusProgressDialog closing

This commit is contained in:
Milos Kozak 2022-06-21 18:51:55 +02:00
parent be201f0177
commit bbcbf3f905
25 changed files with 55 additions and 50 deletions

View file

@ -321,9 +321,9 @@ class CommandQueueImplementation @Inject constructor(
}
@Synchronized
override fun cancelAllBoluses(timestamp: Long) {
override fun cancelAllBoluses(id: Long) {
if (!isRunning(CommandType.BOLUS)) {
rxBus.send(EventDismissBolusProgressIfRunning(PumpEnactResult(injector).success(true).enacted(false), timestamp))
rxBus.send(EventDismissBolusProgressIfRunning(PumpEnactResult(injector).success(true).enacted(false), id))
}
removeAll(CommandType.BOLUS)
removeAll(CommandType.SMB_BOLUS)
@ -598,12 +598,12 @@ class CommandQueueImplementation @Inject constructor(
if (detailedBolusInfo.context != null) {
val bolusProgressDialog = BolusProgressDialog()
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin)
bolusProgressDialog.setTimestamp(detailedBolusInfo.timestamp)
bolusProgressDialog.setId(detailedBolusInfo.id)
bolusProgressDialog.show((detailedBolusInfo.context as AppCompatActivity).supportFragmentManager, "BolusProgress")
} else {
val i = Intent()
i.putExtra("insulin", detailedBolusInfo.insulin)
i.putExtra("timestamp", detailedBolusInfo.timestamp)
i.putExtra("id", detailedBolusInfo.id)
i.setClass(context, BolusProgressHelperActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(i)

View file

@ -26,7 +26,7 @@ class CommandBolus(
val r = activePlugin.activePump.deliverTreatment(detailedBolusInfo)
if (r.success) carbsRunnable.run()
BolusProgressDialog.bolusEnded = true
rxBus.send(EventDismissBolusProgressIfRunning(r, detailedBolusInfo.timestamp))
rxBus.send(EventDismissBolusProgressIfRunning(r, detailedBolusInfo.id))
aapsLogger.debug(LTag.PUMPQUEUE, "Result success: ${r.success} enacted: ${r.enacted}")
callback?.result(r)?.run()
}

View file

@ -566,7 +566,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
return new PumpEnactResult(getInjector()).success(true).enacted(false);
}
EventOverviewBolusProgress.Treatment treatment = new EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
EventOverviewBolusProgress.Treatment treatment = new EventOverviewBolusProgress.Treatment(0.0, 0,detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
EventOverviewBolusProgress.INSTANCE.setT(treatment);
// start bolus delivery

View file

@ -9,7 +9,7 @@ class BolusProgressHelperActivity : DialogAppCompatActivity() {
BolusProgressDialog()
.setHelperActivity(this)
.setInsulin(intent.getDoubleExtra("insulin", 0.0))
.setTimestamp(intent.getLongExtra("timestamp", 0L))
.setId(intent.getLongExtra("id", 0L))
.show(supportFragmentManager, "BolusProgress")
}
}

View file

@ -14,6 +14,8 @@ import info.nightscout.androidaps.utils.T
class DetailedBolusInfo {
val id = System.currentTimeMillis()
// Requesting parameters for driver
@JvmField var insulin = 0.0
@JvmField var carbs = 0.0

View file

@ -48,12 +48,12 @@ class BolusProgressDialog : DaggerDialogFragment() {
private var running = true
private var amount = 0.0
var timestamp: Long = 0L
var id: Long = 0L
private var state: String? = null
private var helpActivity: BolusProgressHelperActivity? = null
fun setTimestamp(timestamp: Long): BolusProgressDialog {
this.timestamp = timestamp
fun setId(id: Long): BolusProgressDialog {
this.id = id
return this
}
@ -88,7 +88,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
savedInstanceState?.let {
amount = it.getDouble("amount")
timestamp = it.getLong("timestamp")
id = it.getLong("id")
state = it.getString("state") ?: rh.gs(R.string.waitingforpump)
}
binding.title.text = rh.gs(R.string.goingtodeliver, amount)
@ -98,7 +98,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
binding.stoppressed.visibility = View.VISIBLE
binding.stop.visibility = View.INVISIBLE
uel.log(Action.CANCEL_BOLUS, Sources.Overview, state)
commandQueue.cancelAllBoluses(timestamp)
commandQueue.cancelAllBoluses(id)
}
binding.progressbar.max = 100
binding.status.text = state
@ -127,14 +127,15 @@ class BolusProgressDialog : DaggerDialogFragment() {
.toObservable(EventDismissBolusProgressIfRunning::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({
aapsLogger.debug(LTag.PUMP, "Running timestamp $timestamp. Close request timestamp ${it.bolusTimestamp}")
if (it.bolusTimestamp == null || it.bolusTimestamp == timestamp)
aapsLogger.debug(LTag.PUMP, "Running id $id. Close request id ${it.id}")
if (it.id == null || it.id == id)
if (running) dismiss()
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventOverviewBolusProgress::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({
if (it.t?.id == id) {
aapsLogger.debug(LTag.UI, "Status: ${it.status} Percent: ${it.percent}")
binding.status.text = it.status
binding.progressbar.progress = it.percent
@ -143,6 +144,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
scheduleDismiss()
}
state = it.status
}
}, fabricPrivacy::logException)
}
@ -170,7 +172,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
super.onSaveInstanceState(outState)
outState.putString("state", state)
outState.putDouble("amount", amount)
outState.putLong("timestamp", timestamp)
outState.putLong("id", id)
}
override fun onDestroyView() {

View file

@ -17,7 +17,7 @@ interface CommandQueue {
fun independentConnect(reason: String, callback: Callback?)
fun bolusInQueue(): Boolean
fun bolus(detailedBolusInfo: DetailedBolusInfo, callback: Callback?): Boolean
fun cancelAllBoluses(running: Long)
fun cancelAllBoluses(id: Long)
fun stopPump(callback: Callback?)
fun startPump(callback: Callback?)
fun setTBROverNotification(callback: Callback?, enable: Boolean)

View file

@ -3,4 +3,4 @@ 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?, val bolusTimestamp: Long?) : Event()
class EventDismissBolusProgressIfRunning(val result: PumpEnactResult?, val id: Long?) : Event()

View file

@ -4,7 +4,7 @@ import info.nightscout.androidaps.events.Event
object EventOverviewBolusProgress : Event() {
data class Treatment constructor(@JvmField var insulin: Double = 0.0, @JvmField var carbs: Int = 0, @JvmField var isSMB: Boolean)
data class Treatment constructor(var insulin: Double = 0.0, var carbs: Int = 0, var isSMB: Boolean, var id: Long)
var status = ""
var t: Treatment? = null

View file

@ -122,7 +122,7 @@ class DanaRKoreanPlugin @Inject constructor(
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(Constraint(detailedBolusInfo.insulin)).value()
if (detailedBolusInfo.carbs > 0) throw IllegalArgumentException()
return if (detailedBolusInfo.insulin > 0) {
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
var connectionOK = false
if (detailedBolusInfo.insulin > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.carbsTimestamp

View file

@ -278,7 +278,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (!danaPump.getBolusStopped()) {
mSerialIOThread.sendMessage(start);
} else {
t.insulin = 0d;
t.setInsulin(0d);
return false;
}
while (!danaPump.getBolusStopped() && !start.getFailed()) {

View file

@ -185,16 +185,17 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, carbTimeStamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep())
.bolusDelivered(t.insulin)
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.getInsulin()) < pumpDescription.getBolusStep())
.bolusDelivered(t.getInsulin())
.carbsDelivered(detailedBolusInfo.carbs);
if (!result.getSuccess())
result.comment(rh.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode()));
result.comment(rh.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.getInsulin(),
danaPump.getBolusStartErrorCode()));
else
result.comment(R.string.ok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());

View file

@ -362,7 +362,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!danaPump.getBolusStopped()) {
mSerialIOThread.sendMessage(start);
} else {
t.insulin = 0d;
t.setInsulin(0d);
return false;
}
while (!danaPump.getBolusStopped() && !start.getFailed()) {

View file

@ -161,20 +161,20 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep())
.bolusDelivered(t.insulin)
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.getInsulin()) < pumpDescription.getBolusStep())
.bolusDelivered(t.getInsulin())
.carbsDelivered(detailedBolusInfo.carbs);
if (!result.getSuccess())
result.comment(rh.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode()));
result.comment(rh.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.getInsulin(), danaPump.getBolusStartErrorCode()));
else
result.comment(R.string.ok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.insulin = t.getInsulin();
detailedBolusInfo.timestamp = System.currentTimeMillis();
if (detailedBolusInfo.insulin > 0)
pumpSync.syncBolusWithPumpId(

View file

@ -219,7 +219,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
}
public void bolusStop() {
aapsLogger.debug(LTag.PUMP, "bolusStop >>>>> @ " + (danaPump.getBolusingTreatment() == null ? "" : danaPump.getBolusingTreatment().insulin));
aapsLogger.debug(LTag.PUMP, "bolusStop >>>>> @ " + (danaPump.getBolusingTreatment() == null ? "" : danaPump.getBolusingTreatment().getInsulin()));
MsgBolusStop stop = new MsgBolusStop(injector);
danaPump.setBolusStopForced(true);
if (isConnected()) {

View file

@ -290,7 +290,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
if (!danaPump.getBolusStopped()) {
mSerialIOThread.sendMessage(start);
} else {
t.insulin = 0d;
t.setInsulin(0d);
return false;
}
while (!danaPump.getBolusStopped() && !start.getFailed()) {
@ -322,7 +322,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
break;
}
// try to find real amount if bolusing was interrupted or comm failed
if (t.insulin != amount) {
if (t.getInsulin() != amount) {
disconnect("bolusingInterrupted");
long bolusDurationInMSec = (long) (amount * speed * 1000);
long expectedEnd = bolusStart + bolusDurationInMSec + 3000;
@ -340,7 +340,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
@Override
public void run() {
if (danaPump.getLastBolusTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
t.insulin = danaPump.getLastBolusAmount();
t.setInsulin(danaPump.getLastBolusAmount());
aapsLogger.debug(LTag.PUMP, "Used bolus amount from history: " + danaPump.getLastBolusAmount());
} else {
aapsLogger.debug(LTag.PUMP, "Bolus amount in history too old: " + dateUtil.dateAndTimeString(danaPump.getLastBolusTime()));

View file

@ -12,7 +12,7 @@ class MsgBolusProgressTest : DanaRTestBase() {
@Test fun runTest() {
`when`(rh.gs(ArgumentMatchers.eq(R.string.bolusdelivering), ArgumentMatchers.anyDouble())).thenReturn("Delivering %1\$.2fU")
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true, 0)
danaPump.bolusAmountToBeDelivered = 3.0
val packet = MsgBolusProgress(injector)

View file

@ -11,7 +11,7 @@ class MsgBolusStopTest : DanaRTestBase() {
@Test fun runTest() {
`when`(rh.gs(R.string.overview_bolusprogress_delivered)).thenReturn("Delivered")
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true, 0)
val packet = MsgBolusStop(injector)
// test message decoding

View file

@ -286,7 +286,7 @@ class DanaRSPlugin @Inject constructor(
var carbTimeStamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp
if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs() // better set 1 min back to prevents clash with insulin
detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
var connectionOK = false
if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = danaRSService?.bolus(detailedBolusInfo.insulin, carbs.toInt(), carbTimeStamp, t)
?: false

View file

@ -30,7 +30,7 @@ class DanaRSPacketNotifyDeliveryCompleteTest : DanaRSTestBase() {
@Test fun runTest() {
`when`(rh.gs(anyInt(), anyDouble())).thenReturn("SomeString")
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true, 0)
val packet = DanaRSPacketNotifyDeliveryComplete(packetInjector)
// test params
Assert.assertEquals(0, packet.getRequestParams().size)

View file

@ -29,7 +29,7 @@ class DanaRsPacketBolusSetStepBolusStopTest : DanaRSTestBase() {
@Test fun runTest() {
`when`(rh.gs(Mockito.anyInt())).thenReturn("SomeString")
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true, 0)
val testPacket = DanaRSPacketBolusSetStepBolusStop(packetInjector)
// test message decoding
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))

View file

@ -61,6 +61,6 @@ class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() {
@Before
fun mock() {
danaRSPlugin = DanaRSPlugin(packetInjector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, profileFunction, sp, commandQueue, danaPump, pumpSync, detailedBolusInfoStorage, temporaryBasalStorage, fabricPrivacy, dateUtil)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true)
danaPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, true, 0)
}
}

View file

@ -256,7 +256,7 @@ class DiaconnG8Plugin @Inject constructor(
var carbTimeStamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp
if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs() // better set 1 min back to prevents clash with insulin
detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
var connectionOK = false
if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = diaconnG8Service?.bolus(detailedBolusInfo.insulin, carbs.toInt(), carbTimeStamp, t)
?: false

View file

@ -587,7 +587,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
bolusCancelled = false;
}
result.success(true).enacted(true);
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.setT(t);
bolusingEvent.setStatus(rh.gs(R.string.insight_delivered, 0d, insulin));

View file

@ -329,7 +329,7 @@ abstract class PumpPluginAbstract protected constructor(
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(detailedBolusInfo, this))
val bolusingEvent = EventOverviewBolusProgress
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB)
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
bolusingEvent.percent = 100
rxBus.send(bolusingEvent)
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.")