fire immediatelly TreatmentChange if not from NS

This commit is contained in:
Milos Kozak 2020-03-06 20:27:39 +01:00
parent 4cca305e1b
commit 1e02773b71

View file

@ -160,7 +160,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
scheduleTreatmentChange(null);
scheduleTreatmentChange(null, true);
}
@ -208,18 +208,30 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
/**
* Schedule a foodChange Event.
*/
public void scheduleTreatmentChange(@Nullable final Treatment treatment) {
this.scheduleEvent(new EventReloadTreatmentData(new EventTreatmentChange(treatment)), treatmentEventWorker, new ICallback() {
@Override
public void setPost(ScheduledFuture<?> post) {
scheduledTreatmentEventPost = post;
public void scheduleTreatmentChange(@Nullable final Treatment treatment, boolean runImmediately) {
if (runImmediately) {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("Firing EventReloadTreatmentData");
RxBus.INSTANCE.send(new EventReloadTreatmentData(new EventTreatmentChange(treatment)));
if (DatabaseHelper.earliestDataChange != null) {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("Firing EventNewHistoryData");
RxBus.INSTANCE.send(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
}
DatabaseHelper.earliestDataChange = null;
} else {
this.scheduleEvent(new EventReloadTreatmentData(new EventTreatmentChange(treatment)), treatmentEventWorker, new ICallback() {
@Override
public void setPost(ScheduledFuture<?> post) {
scheduledTreatmentEventPost = post;
}
@Override
public ScheduledFuture<?> getPost() {
return scheduledTreatmentEventPost;
}
});
@Override
public ScheduledFuture<?> getPost() {
return scheduledTreatmentEventPost;
}
});
}
}
public List<Treatment> getTreatmentData() {
@ -294,7 +306,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
getDao().create(existingTreatment);
DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(sameSource, false); //updating a pump treatment with another one from the pump is not counted as clash
}
return new UpdateReturn(equalRePumpHistory, false);
@ -318,14 +330,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
getDao().create(existingTreatment);
DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(equalRePumpHistory || sameSource, false);
}
getDao().create(treatment);
if (L.isEnabled(L.DATATREATMENTS))
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
DatabaseHelper.updateEarliestDataChange(treatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(true, true);
}
if (treatment.source == Source.NIGHTSCOUT) {
@ -343,7 +355,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(old.date);
}
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, false);
return new UpdateReturn(true, true);
}
if (L.isEnabled(L.DATATREATMENTS))
@ -366,7 +378,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(old.date);
}
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, false);
return new UpdateReturn(true, true);
}
if (L.isEnabled(L.DATATREATMENTS))
@ -378,7 +390,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
DatabaseHelper.updateEarliestDataChange(treatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, false);
return new UpdateReturn(true, true);
}
if (treatment.source == Source.USER) {
@ -386,7 +398,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
DatabaseHelper.updateEarliestDataChange(treatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(true, true);
}
} catch (SQLException e) {
@ -414,7 +426,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
DatabaseHelper.updateEarliestDataChange(treatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(true, true);
} else {
@ -428,7 +440,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
}
getDao().update(existingTreatment);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(true, false);
} else {
if (MedtronicHistoryData.doubleBolusDebug)
@ -439,7 +451,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
optionalTreatmentCopy(existingTreatment, treatment, fromNightScout);
getDao().create(existingTreatment);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
return new UpdateReturn(true, false); //updating a pump treatment with another one from the pump is not counted as clash
}
}
@ -626,9 +638,13 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (stored != null) {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("Removing Treatment record from database: " + stored.toString());
delete(stored);
try {
getDao().delete(stored);
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
DatabaseHelper.updateEarliestDataChange(stored.date);
scheduleTreatmentChange(null);
this.scheduleTreatmentChange(stored, false);
}
}
@ -643,7 +659,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
try {
getDao().delete(treatment);
DatabaseHelper.updateEarliestDataChange(treatment.date);
this.scheduleTreatmentChange(treatment);
this.scheduleTreatmentChange(treatment, true);
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
@ -656,7 +672,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
scheduleTreatmentChange(treatment);
scheduleTreatmentChange(treatment, true);
}
/**