Merge pull request #648 from jotomo/do-not-loop-for-smb-treatment-change
Do not loop for SMB treatment change
This commit is contained in:
commit
0832ae9491
4 changed files with 42 additions and 20 deletions
|
@ -225,9 +225,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
VirtualPumpPlugin.setFakingStatus(true);
|
VirtualPumpPlugin.setFakingStatus(true);
|
||||||
scheduleBgChange(); // trigger refresh
|
scheduleBgChange(null); // trigger refresh
|
||||||
scheduleTemporaryBasalChange();
|
scheduleTemporaryBasalChange();
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(null);
|
||||||
scheduleExtendedBolusChange();
|
scheduleExtendedBolusChange();
|
||||||
scheduleTemporaryTargetChange();
|
scheduleTemporaryTargetChange();
|
||||||
scheduleCareportalEventChange();
|
scheduleCareportalEventChange();
|
||||||
|
@ -252,7 +252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTempTargets() {
|
public void resetTempTargets() {
|
||||||
|
@ -358,7 +358,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
if (old == null) {
|
if (old == null) {
|
||||||
getDaoBgReadings().create(bgReading);
|
getDaoBgReadings().create(bgReading);
|
||||||
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange(bgReading);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!old.isEqual(bgReading)) {
|
if (!old.isEqual(bgReading)) {
|
||||||
|
@ -366,7 +366,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
old.copyFrom(bgReading);
|
old.copyFrom(bgReading);
|
||||||
getDaoBgReadings().update(old);
|
getDaoBgReadings().update(old);
|
||||||
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange(bgReading);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -384,11 +384,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleBgChange() {
|
private static void scheduleBgChange(@Nullable final BgReading bgReading) {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
log.debug("Firing EventNewBg");
|
log.debug("Firing EventNewBg");
|
||||||
MainApp.bus().post(new EventNewBG());
|
MainApp.bus().post(new EventNewBG(bgReading));
|
||||||
scheduledBgPost = null;
|
scheduledBgPost = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,7 +563,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
getDaoTreatments().create(treatment);
|
getDaoTreatments().create(treatment);
|
||||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||||
updateEarliestDataChange(treatment.date);
|
updateEarliestDataChange(treatment.date);
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (treatment.source == Source.NIGHTSCOUT) {
|
if (treatment.source == Source.NIGHTSCOUT) {
|
||||||
|
@ -580,7 +580,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
updateEarliestDataChange(oldDate);
|
updateEarliestDataChange(oldDate);
|
||||||
updateEarliestDataChange(old.date);
|
updateEarliestDataChange(old.date);
|
||||||
}
|
}
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -605,7 +605,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
updateEarliestDataChange(oldDate);
|
updateEarliestDataChange(oldDate);
|
||||||
updateEarliestDataChange(old.date);
|
updateEarliestDataChange(old.date);
|
||||||
}
|
}
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,14 +613,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
getDaoTreatments().create(treatment);
|
getDaoTreatments().create(treatment);
|
||||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||||
updateEarliestDataChange(treatment.date);
|
updateEarliestDataChange(treatment.date);
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (treatment.source == Source.USER) {
|
if (treatment.source == Source.USER) {
|
||||||
getDaoTreatments().create(treatment);
|
getDaoTreatments().create(treatment);
|
||||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||||
updateEarliestDataChange(treatment.date);
|
updateEarliestDataChange(treatment.date);
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -636,7 +636,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(Treatment treatment) {
|
public void update(Treatment treatment) {
|
||||||
|
@ -646,7 +646,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(treatment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteTreatmentById(String _id) {
|
public void deleteTreatmentById(String _id) {
|
||||||
|
@ -655,12 +655,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
log.debug("TREATMENT: Removing Treatment record from database: " + stored.toString());
|
log.debug("TREATMENT: Removing Treatment record from database: " + stored.toString());
|
||||||
delete(stored);
|
delete(stored);
|
||||||
updateEarliestDataChange(stored.date);
|
updateEarliestDataChange(stored.date);
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Treatment findTreatmentById(String _id) {
|
private Treatment findTreatmentById(String _id) {
|
||||||
try {
|
try {
|
||||||
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
|
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
|
||||||
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
||||||
|
@ -692,11 +692,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleTreatmentChange() {
|
private static void scheduleTreatmentChange(@Nullable final Treatment treatment) {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
log.debug("Firing EventTreatmentChange");
|
log.debug("Firing EventTreatmentChange");
|
||||||
MainApp.bus().post(new EventReloadTreatmentData(new EventTreatmentChange()));
|
MainApp.bus().post(new EventReloadTreatmentData(new EventTreatmentChange(treatment)));
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
|
@ -1742,4 +1742,4 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------- Food handling ---------------
|
// ---------------- Food handling ---------------
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
package info.nightscout.androidaps.events;
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.06.2016.
|
* Created by mike on 05.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventNewBG extends EventLoop {
|
public class EventNewBG extends EventLoop {
|
||||||
|
@Nullable
|
||||||
|
public final BgReading bgReading;
|
||||||
|
|
||||||
|
public EventNewBG(BgReading bgReading) {
|
||||||
|
this.bgReading = bgReading;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
package info.nightscout.androidaps.events;
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 04.06.2016.
|
* Created by mike on 04.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventTreatmentChange extends EventLoop {
|
public class EventTreatmentChange extends EventLoop {
|
||||||
|
@Nullable
|
||||||
|
public final Treatment treatment;
|
||||||
|
|
||||||
|
public EventTreatmentChange(Treatment treatment) {
|
||||||
|
this.treatment = treatment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,9 @@ public class LoopPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTreatmentChange ev) {
|
public void onStatusEvent(final EventTreatmentChange ev) {
|
||||||
invoke("EventTreatmentChange", true);
|
if (ev.treatment == null || !ev.treatment.isSMB){
|
||||||
|
invoke("EventTreatmentChange", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
Loading…
Reference in a new issue