From 6fca923275cfc7310852ecc02cb3022aecf3e41c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 12 Jun 2017 13:11:16 +0200 Subject: [PATCH] fix profileswitch reloads --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 10 ++++++---- .../info/nightscout/androidaps/db/ProfileSwitch.java | 2 +- .../events/EventReloadProfileSwitchData.java | 8 ++++++++ .../Careportal/Dialogs/NewNSTreatmentDialog.java | 8 ++++---- .../androidaps/plugins/Overview/OverviewFragment.java | 2 +- .../plugins/Treatments/TreatmentsPlugin.java | 5 ++--- 6 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 849f259443..b3972f623f 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -37,6 +37,7 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.events.EventReloadProfileSwitchData; import info.nightscout.androidaps.events.EventReloadTempBasalData; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempBasalChange; @@ -1507,7 +1508,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(profileSwitch); getDaoProfileSwitch().create(old); log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString()); - scheduleTemporaryTargetChange(); + scheduleProfileSwitchChange(); return true; } return false; @@ -1526,20 +1527,20 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(profileSwitch); getDaoProfileSwitch().create(old); log.debug("PROFILESWITCH: Updating record by _id from: " + Source.getString(profileSwitch.source) + " " + old.toString()); - scheduleTemporaryTargetChange(); + scheduleProfileSwitchChange(); return true; } } } getDaoProfileSwitch().create(profileSwitch); log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); - scheduleTemporaryTargetChange(); + scheduleProfileSwitchChange(); return true; } if (profileSwitch.source == Source.USER) { getDaoProfileSwitch().create(profileSwitch); log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); - scheduleTemporaryTargetChange(); + scheduleProfileSwitchChange(); return true; } } catch (SQLException e) { @@ -1561,6 +1562,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { class PostRunnable implements Runnable { public void run() { log.debug("Firing EventProfileSwitchChange"); + MainApp.bus().post(new EventReloadProfileSwitchData()); MainApp.bus().post(new EventProfileSwitchChange()); scheduledProfileSwitchEventPost = null; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 448f6cdd51..25ba1cb051 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -187,7 +187,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { return Color.CYAN; } - public String log() { + public String toString() { return "ProfileSwitch{" + "date=" + date + "date=" + DateUtil.dateAndTimeString(date) + diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java b/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java new file mode 100644 index 0000000000..20073a7cf0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.events; + +/** + * Created by mike on 12.06.2017. + */ + +public class EventReloadProfileSwitchData { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index f1e5f09ebd..dad922a5c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -619,13 +619,13 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick String profileName = data.getString("profile"); ProfileSwitch profileSwitch = new ProfileSwitch(); profileSwitch.date = new Date().getTime(); - profileSwitch.source = Source.PUMP; + profileSwitch.source = Source.USER; profileSwitch.profileName = profileName; - profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).toString(); - profileSwitch.profilePlugin = MainApp.getConfigBuilder().getActiveProfileInterface().getClass().getName(); + profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString(); + profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName(); profileSwitch.durationInMinutes = data.getInt("duration"); if (ConfigBuilderPlugin.getActiveProfileInterface() instanceof CircadianPercentageProfilePlugin) { - CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getConfigBuilder().getActiveProfileInterface(); + CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfileInterface(); profileSwitch.isCPP = true; profileSwitch.timeshift = cpp.timeshift; profileSwitch.percentage = cpp.percentage; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 7d9c84a33d..7ebdcc60f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -1018,7 +1018,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(new Date().getTime()); String extendedBolusText = ""; - if (extendedBolus != null) { + if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) { extendedBolusText = extendedBolus.toString(); } if (extendedBolusView != null) // must not exists in all layouts diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 50bb0c7892..d211a0eca4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -24,11 +24,10 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileIntervals; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; -import info.nightscout.androidaps.events.EventProfileSwitchChange; +import info.nightscout.androidaps.events.EventReloadProfileSwitchData; import info.nightscout.androidaps.events.EventReloadTempBasalData; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempTargetChange; @@ -445,7 +444,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { // Profile Switch @Subscribe - public void onStatusEvent(final EventProfileSwitchChange ev) { + public void onStatusEvent(final EventReloadProfileSwitchData ev) { initializeProfileSwitchData(); }