From af0140f6b926aa5fccabc313e04561169cc0f585 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 4 Apr 2018 12:11:29 +0300 Subject: [PATCH 01/16] Get thresholds from NS --- .../Careportal/CareportalFragment.java | 266 +++++++++++------- 1 file changed, 166 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java index 2353fa6645..3c6d80df8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java @@ -3,9 +3,7 @@ package info.nightscout.androidaps.plugins.Careportal; import android.app.Activity; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,22 +12,27 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.Overview.OverviewFragment; +import info.nightscout.utils.FabricPrivacy; public class CareportalFragment extends SubscriberFragment implements View.OnClickListener { - - static CareportalPlugin careportalPlugin; - + private static Logger log = LoggerFactory.getLogger(CareportalFragment.class); TextView iage; TextView cage; TextView sage; @@ -39,85 +42,85 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli LinearLayout butonsLayout; View noProfileView; - static public CareportalPlugin getPlugin() { - if (careportalPlugin == null) { - careportalPlugin = new CareportalPlugin(); - } - return careportalPlugin; - } - - // bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget - public static final OptionsToShow bgcheck = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck, true, true, true, false, false, false, false, false, false, false); - public static final OptionsToShow snackbolus = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow mealbolus = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow correctionbolus = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow carbcorrection = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection, true, false, true, false, false, false, false, false, false, false); - public static final OptionsToShow combobolus = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus, true, true, true, true, true, false, false, false, true, false); - public static final OptionsToShow announcement = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow note = new OptionsToShow(R.id.careportal_note, R.string.careportal_note, true, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow question = new OptionsToShow(R.id.careportal_question, R.string.careportal_question, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow exercise = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise, false, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow sitechange = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange, true, true, false, false, false, false, false, false, false, false); - public static final OptionsToShow sensorstart = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow sensorchange = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow insulinchange = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow pumpbatterychange = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow tempbasalstart = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart, true, false, false, false, true, true, true, false, false, false); - public static final OptionsToShow tempbasalend = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, true, false, false, true, false, false); - public static final OptionsToShow openapsoffline = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline, false, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow temptarget = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget, false, false, false, false, true, false, false, false, false, true); + // date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget + public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg(); + public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow MEALBOLUS = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow CORRECTIONBOLUS = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow CARBCORRECTION = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection).date().bg().carbs(); + public static final OptionsToShow COMBOBOLUS = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus).date().bg().insulin().carbs().prebolus().duration().split(); + public static final OptionsToShow ANNOUNCEMENT = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement).date().bg(); + public static final OptionsToShow NOTE = new OptionsToShow(R.id.careportal_note, R.string.careportal_note).date().bg().duration(); + public static final OptionsToShow QUESTION = new OptionsToShow(R.id.careportal_question, R.string.careportal_question).date().bg(); + public static final OptionsToShow EXERCISE = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise).date().duration(); + public static final OptionsToShow SITECHANGE = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange).date().bg(); + public static final OptionsToShow SENSORSTART = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart).date().bg(); + public static final OptionsToShow SENSORCHANGE = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert).date().bg(); + public static final OptionsToShow INSULINCHANGE = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange).date().bg(); + public static final OptionsToShow PUMPBATTERYCHANGE = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange).date().bg(); + public static final OptionsToShow TEMPBASALSTART = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart).date().bg().duration().percent().absolute(); + public static final OptionsToShow TEMPBASALEND = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend).date().bg(); + public static final OptionsToShow PROFILESWITCH = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).date().duration().profile(); + public static final OptionsToShow PROFILESWITCHDIRECT = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).duration().profile(); + public static final OptionsToShow OPENAPSOFFLINE = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline).date().duration(); + public static final OptionsToShow TEMPTARGET = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget).date().duration().tempTarget(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.careportal_fragment, container, false); + try { + View view = inflater.inflate(R.layout.careportal_fragment, container, false); - view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); - view.findViewById(R.id.careportal_announcement).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); - view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); - view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); - view.findViewById(R.id.careportal_exercise).setOnClickListener(this); - view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); - view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_note).setOnClickListener(this); - view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); - view.findViewById(R.id.careportal_question).setOnClickListener(this); - view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); - view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); - view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); + view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); + view.findViewById(R.id.careportal_announcement).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); + view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); + view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); + view.findViewById(R.id.careportal_exercise).setOnClickListener(this); + view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); + view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_note).setOnClickListener(this); + view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); + view.findViewById(R.id.careportal_question).setOnClickListener(this); + view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); + view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); + view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); - iage = (TextView) view.findViewById(R.id.careportal_insulinage); - cage = (TextView) view.findViewById(R.id.careportal_canulaage); - sage = (TextView) view.findViewById(R.id.careportal_sensorage); - pbage = (TextView) view.findViewById(R.id.careportal_pbage); + iage = (TextView) view.findViewById(R.id.careportal_insulinage); + cage = (TextView) view.findViewById(R.id.careportal_canulaage); + sage = (TextView) view.findViewById(R.id.careportal_sensorage); + pbage = (TextView) view.findViewById(R.id.careportal_pbage); - statsLayout = (View) view.findViewById(R.id.careportal_stats); + statsLayout = view.findViewById(R.id.careportal_stats); - noProfileView = (View) view.findViewById(R.id.profileview_noprofile); - butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); + noProfileView = view.findViewById(R.id.profileview_noprofile); + butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); - ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); - if (profileStore == null) { - noProfileView.setVisibility(View.VISIBLE); - butonsLayout.setVisibility(View.GONE); - } else { - noProfileView.setVisibility(View.GONE); - butonsLayout.setVisibility(View.VISIBLE); + ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); + if (profileStore == null) { + noProfileView.setVisibility(View.VISIBLE); + butonsLayout.setVisibility(View.GONE); + } else { + noProfileView.setVisibility(View.GONE); + butonsLayout.setVisibility(View.VISIBLE); + } + + if (Config.NSCLIENT || Config.G5UPLOADER) + statsLayout.setVisibility(View.GONE); // visible on overview + + updateGUI(); + return view; + } catch (Exception e) { + FabricPrivacy.logException(e); } - if (BuildConfig.NSCLIENTOLNY) - statsLayout.setVisibility(View.GONE); // visible on overview - - updateGUI(); - return view; + return null; } @Override @@ -129,66 +132,66 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); switch (id) { case R.id.careportal_bgcheck: - newDialog.setOptions(bgcheck, R.string.careportal_bgcheck); + newDialog.setOptions(BGCHECK, R.string.careportal_bgcheck); break; case R.id.careportal_announcement: - newDialog.setOptions(announcement, R.string.careportal_announcement); + newDialog.setOptions(ANNOUNCEMENT, R.string.careportal_announcement); break; case R.id.careportal_cgmsensorinsert: - newDialog.setOptions(sensorchange, R.string.careportal_cgmsensorinsert); + newDialog.setOptions(SENSORCHANGE, R.string.careportal_cgmsensorinsert); break; case R.id.careportal_cgmsensorstart: - newDialog.setOptions(sensorstart, R.string.careportal_cgmsensorstart); + newDialog.setOptions(SENSORSTART, R.string.careportal_cgmsensorstart); break; case R.id.careportal_combobolus: - newDialog.setOptions(combobolus, R.string.careportal_combobolus); + newDialog.setOptions(COMBOBOLUS, R.string.careportal_combobolus); break; case R.id.careportal_correctionbolus: - newDialog.setOptions(correctionbolus, R.string.careportal_correctionbolus); + newDialog.setOptions(CORRECTIONBOLUS, R.string.careportal_correctionbolus); break; case R.id.careportal_carbscorrection: - newDialog.setOptions(carbcorrection, R.string.careportal_carbscorrection); + newDialog.setOptions(CARBCORRECTION, R.string.careportal_carbscorrection); break; case R.id.careportal_exercise: - newDialog.setOptions(exercise, R.string.careportal_exercise); + newDialog.setOptions(EXERCISE, R.string.careportal_exercise); break; case R.id.careportal_insulincartridgechange: - newDialog.setOptions(insulinchange, R.string.careportal_insulincartridgechange); + newDialog.setOptions(INSULINCHANGE, R.string.careportal_insulincartridgechange); break; case R.id.careportal_pumpbatterychange: - newDialog.setOptions(pumpbatterychange, R.string.careportal_pumpbatterychange); + newDialog.setOptions(PUMPBATTERYCHANGE, R.string.careportal_pumpbatterychange); break; case R.id.careportal_mealbolus: - newDialog.setOptions(mealbolus, R.string.careportal_mealbolus); + newDialog.setOptions(MEALBOLUS, R.string.careportal_mealbolus); break; case R.id.careportal_note: - newDialog.setOptions(note, R.string.careportal_note); + newDialog.setOptions(NOTE, R.string.careportal_note); break; case R.id.careportal_profileswitch: - profileswitch.executeProfileSwitch = false; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); + PROFILESWITCH.executeProfileSwitch = false; + newDialog.setOptions(PROFILESWITCH, R.string.careportal_profileswitch); break; case R.id.careportal_pumpsitechange: - newDialog.setOptions(sitechange, R.string.careportal_pumpsitechange); + newDialog.setOptions(SITECHANGE, R.string.careportal_pumpsitechange); break; case R.id.careportal_question: - newDialog.setOptions(question, R.string.careportal_question); + newDialog.setOptions(QUESTION, R.string.careportal_question); break; case R.id.careportal_snackbolus: - newDialog.setOptions(snackbolus, R.string.careportal_snackbolus); + newDialog.setOptions(SNACKBOLUS, R.string.careportal_snackbolus); break; case R.id.careportal_tempbasalstart: - newDialog.setOptions(tempbasalstart, R.string.careportal_tempbasalstart); + newDialog.setOptions(TEMPBASALSTART, R.string.careportal_tempbasalstart); break; case R.id.careportal_tempbasalend: - newDialog.setOptions(tempbasalend, R.string.careportal_tempbasalend); + newDialog.setOptions(TEMPBASALEND, R.string.careportal_tempbasalend); break; case R.id.careportal_openapsoffline: - newDialog.setOptions(openapsoffline, R.string.careportal_openapsoffline); + newDialog.setOptions(OPENAPSOFFLINE, R.string.careportal_openapsoffline); break; case R.id.careportal_temporarytarget: - temptarget.executeTempTarget = false; - newDialog.setOptions(temptarget, R.string.careportal_temporarytarget); + TEMPTARGET.executeTempTarget = false; + newDialog.setOptions(TEMPTARGET, R.string.careportal_temporarytarget); break; default: newDialog = null; @@ -215,22 +218,84 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli @Override public void run() { CareportalEvent careportalEvent; + NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + JSONObject extendedSettings = nsSettings.getExtendedSettings(); + // Thresholds in NS are in hours + double iageThreshold = 7*24; + double cageThreshold = 3*24; + double sageThreshold = 7*24; + double pbageThreshold = 15*24; + log.debug("NSExtendedSettings are "+extendedSettings.toString()); +// try { + JSONObject iageSettings = extendedSettings.optJSONObject("iage"); + if(iageSettings != null) + iageThreshold = iageSettings.optDouble("urgent", 7*24); + JSONObject cageSettings = extendedSettings.optJSONObject("cage"); + if(cageSettings != null) + cageThreshold = cageSettings.optDouble("urgent", 3*24); + log.debug("cageThreshold is "+cageThreshold); + JSONObject sageSettings = extendedSettings.optJSONObject("sage"); + if(sageSettings != null) + sageThreshold = sageSettings.optDouble("urgent", 7*24); +// } catch (JSONException e) { +// log.error("Unhandled exception", e); +// } String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable); if (sage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); - sage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan( sageThreshold/24)){ + sage.setTextColor(MainApp.sResources.getColor(R.color.low)); + sage.setText(careportalEvent.age()); + } else { + sage.setText(careportalEvent.age()); + } + + } else { + sage.setText(notavailable); + } } if (iage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); - iage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan(iageThreshold/24)){ + iage.setTextColor(MainApp.sResources.getColor(R.color.low)); + iage.setText(careportalEvent.age()); + } else { + iage.setText(careportalEvent.age()); + } + + } else { + iage.setText(notavailable); + } } if (cage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); - cage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if (careportalEvent != null) { + if(careportalEvent.isOlderThan(cageThreshold/24)){ + cage.setTextColor(MainApp.sResources.getColor(R.color.low)); + cage.setText(careportalEvent.age()); + } else { + cage.setText(careportalEvent.age()); + } + + } else { + cage.setText(notavailable); + } } if (pbage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE); - pbage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan(pbageThreshold/24)){ + pbage.setTextColor(MainApp.sResources.getColor(R.color.low)); + pbage.setText(careportalEvent.age()); + } else { + pbage.setText(careportalEvent.age()); + } + + } else { + pbage.setText(notavailable); + } } } } @@ -239,3 +304,4 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli } } + From 2eca7f0a026b35d2c8685291a6eefb2eaf190da4 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 4 Apr 2018 12:13:07 +0300 Subject: [PATCH 02/16] int to double in the isOlderThan() --- .../androidaps/db/CareportalEvent.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index b80f4f932e..643b5d066c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -5,6 +5,7 @@ import android.graphics.Color; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import org.apache.commons.lang3.StringUtils; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -97,6 +98,14 @@ public class CareportalEvent implements DataPointWithLabelInterface { return diff.get(TimeUnit.DAYS) + " " + MainApp.sResources.getString(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.sResources.getString(R.string.hours); } + public boolean isOlderThan(double threshold) { + Map diff = computeDiff(date, System.currentTimeMillis()); + if(diff.get(TimeUnit.DAYS) > threshold) + return true; + else + return false; + } + public String log() { return "CareportalEvent{" + "date= " + date + @@ -184,13 +193,24 @@ public class CareportalEvent implements DataPointWithLabelInterface { try { JSONObject object = new JSONObject(json); if (object.has("notes")) - return object.getString("notes"); + return StringUtils.abbreviate(object.getString("notes"), 40); } catch (JSONException e) { log.error("Unhandled exception", e); } return Translator.translate(eventType); } + public String getNotes() { + try { + JSONObject object = new JSONObject(json); + if (object.has("notes")) + return object.getString("notes"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return ""; + } + @Override public long getDuration() { try { @@ -242,4 +262,10 @@ public class CareportalEvent implements DataPointWithLabelInterface { return Color.GRAY; return Color.GRAY; } + + @Override + public int getSecondColor() { + return 0; + } + } From 80be7fb586cf179e3d77b9e29b7ef58c3fc1eecf Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 10 Apr 2018 12:06:26 +0200 Subject: [PATCH 03/16] Fix re-enabling the loop plugin from overview. Fixes #861. Note that enabling a loop plugin is hardcoded against the only impl currently available LoopPlugin. Support for multiple loop plugins is incomplete (and not needed at this point), since there's no LoopInterface, but immediately LoopPlugin (as compared to APSInterface with OpenAPS* impls). When adding support, the last activated loop plugin must be remembered so the correct one is re-enabled. --- .../ConfigBuilder/ConfigBuilderPlugin.java | 1 + .../plugins/Overview/OverviewFragment.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index c6b2e3ce96..4ffec6aef3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -264,6 +264,7 @@ public class ConfigBuilderPlugin extends PluginBase { return activeAPS; } + @Nullable public static LoopPlugin getActiveLoop() { return activeLoop; } 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 d6c9c70c4e..a05df99efd 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 @@ -459,10 +459,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (v == apsModeView) { final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) + if (!MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) return; menu.setHeaderTitle(MainApp.gs(R.string.loop)); - if (activeloop.isEnabled(PluginType.LOOP)) { + if (activeloop == null) { + menu.add(MainApp.gs(R.string.enableloop)); + } else { menu.add(MainApp.gs(R.string.disableloop)); if (!activeloop.isSuspended()) { menu.add(MainApp.gs(R.string.suspendloopfor1h)); @@ -480,8 +482,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, menu.add(MainApp.gs(R.string.resume)); } } - if (!activeloop.isEnabled(PluginType.LOOP)) - menu.add(MainApp.gs(R.string.enableloop)); } else if (v == activeProfileView) { menu.setHeaderTitle(MainApp.gs(R.string.profile)); menu.add(MainApp.gs(R.string.danar_viewprofile)); @@ -496,13 +496,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) return true; - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); if (item.getTitle().equals(MainApp.gs(R.string.disableloop))) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.setPluginEnabled(PluginType.LOOP, false); activeloop.setFragmentVisible(PluginType.LOOP, false); MainApp.getConfigBuilder().storeSettings("DisablingLoop"); updateGUI("suspendmenu"); - MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { if (!result.success) { @@ -513,16 +513,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration return true; } else if (item.getTitle().equals(MainApp.gs(R.string.enableloop))) { - activeloop.setPluginEnabled(PluginType.LOOP, true); - activeloop.setFragmentVisible(PluginType.LOOP, true); + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + loopPlugin.setPluginEnabled(PluginType.LOOP, true); + loopPlugin.setFragmentVisible(PluginType.LOOP, true); MainApp.getConfigBuilder().storeSettings("EnablingLoop"); updateGUI("suspendmenu"); NSUpload.uploadOpenAPSOffline(0); return true; } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.suspendTo(0L); updateGUI("suspendmenu"); - MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { if (!result.success) { From 2972138d2a78a1f4c98a5d6313cb2302b463e3d7 Mon Sep 17 00:00:00 2001 From: swissalpine Date: Tue, 10 Apr 2018 22:14:52 +0200 Subject: [PATCH 04/16] Fix for black number and labels on black background (aaps wear) --- .../res/layout/action_editplusminus_item.xml | 45 ++++++++++--------- .../action_editplusminus_item_below.xml | 10 +++-- .../action_editplusminus_item_quicklefty.xml | 45 ++++++++++--------- .../action_editplusminus_item_quickrighty.xml | 45 ++++++++++--------- .../action_editplusminus_item_viktoria.xml | 2 + .../main/res/layout/action_toggle_item.xml | 4 +- 6 files changed, 83 insertions(+), 68 deletions(-) diff --git a/wear/src/main/res/layout/action_editplusminus_item.xml b/wear/src/main/res/layout/action_editplusminus_item.xml index 38336ff903..8ea1826e77 100644 --- a/wear/src/main/res/layout/action_editplusminus_item.xml +++ b/wear/src/main/res/layout/action_editplusminus_item.xml @@ -26,28 +26,31 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> - - + + + + android:textColor="@color/white" + android:textSize="45sp" /> - - + + + - - + + + + + android:textColor="@color/white" /> Date: Tue, 10 Apr 2018 22:53:27 +0200 Subject: [PATCH 05/16] dummy-edit to re-trigger travis --- .../main/res/layout/action_editplusminus_item_viktoria.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wear/src/main/res/layout/action_editplusminus_item_viktoria.xml b/wear/src/main/res/layout/action_editplusminus_item_viktoria.xml index 24bdd2d0d3..357fa7c4f2 100644 --- a/wear/src/main/res/layout/action_editplusminus_item_viktoria.xml +++ b/wear/src/main/res/layout/action_editplusminus_item_viktoria.xml @@ -22,7 +22,7 @@ android:layout_gravity="left|center_vertical" android:gravity="center" android:rotation="90" - android:text="label" + android:text="labelx" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/white" android:textSize="25sp" /> @@ -68,4 +68,4 @@ - \ No newline at end of file + From 564e87d782af9515581d32207ee85b09ab578c25 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 11 Apr 2018 15:44:53 +0300 Subject: [PATCH 06/16] added phone Manufacturer and model note to NS --- .../java/info/nightscout/utils/NSUpload.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 9b9b940ef9..ad6cc45ab8 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -476,6 +476,32 @@ public class NSUpload { intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); + // now adding another note with the device running AndroidAPS + uploadDeviceNote(); + } + } + + public static void uploadDeviceNote(){ + if (SP.getBoolean(R.string.key_ns_logappstartedevent, true)) { + Context context = MainApp.instance().getApplicationContext(); + Bundle bundle = new Bundle(); + bundle.putString("action", "dbAdd"); + bundle.putString("collection", "treatments"); + JSONObject data = new JSONObject(); + try { + data.put("eventType", "Note"); + data.put("created_at", DateUtil.toISOString(new Date())); + data.put("notes", "Started on "+ Build.MANUFACTURER + " "+ Build.MODEL); +// log.debug("Running on: "+Build.MANUFACTURER + " "+ Build.MODEL); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + bundle.putString("data", data.toString()); + Intent intent = new Intent(Intents.ACTION_DATABASE); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + DbLogger.dbAdd(intent, data.toString()); } } From d0edd89b5b81c2f3ec0c3d1cc77c2f86715ea0f3 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 11 Apr 2018 15:42:51 +0200 Subject: [PATCH 07/16] Remove CB.getActiveLoop(), use LoopPlugin.getPlugin(). --- .../androidaps/data/QuickWizardEntry.java | 5 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 9 +- .../androidaps/plugins/Loop/LoopPlugin.java | 2 + .../Overview/Dialogs/WizardDialog.java | 7 +- .../plugins/Overview/OverviewFragment.java | 158 +++++++++--------- .../SmsCommunicatorPlugin.java | 6 +- .../plugins/Wear/ActionStringHandler.java | 18 +- .../androidaps/plugins/Wear/WearPlugin.java | 6 +- .../wearintegration/WatchUpdaterService.java | 6 +- .../XDripStatusline/StatuslinePlugin.java | 13 +- .../nightscout/utils/LocalAlertUtils.java | 3 +- 11 files changed, 107 insertions(+), 126 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java index 4a94db0a44..e4cd50c490 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java @@ -11,7 +11,6 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -119,8 +118,8 @@ public class QuickWizardEntry { if (useSuperBolus() == YES && SP.getBoolean(R.string.key_usesuperbolus, false)) { superBolus = true; } - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.isEnabled(loopPlugin.getType()) && loopPlugin.isSuperBolus()) superBolus = false; // Trend diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 4ffec6aef3..06ddbef86f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -264,11 +264,6 @@ public class ConfigBuilderPlugin extends PluginBase { return activeAPS; } - @Nullable - public static LoopPlugin getActiveLoop() { - return activeLoop; - } - public static PumpInterface getActivePump() { return activePump; } @@ -622,7 +617,7 @@ public class ConfigBuilderPlugin extends PluginBase { } public void disconnectPump(int durationInMinutes, Profile profile) { - getActiveLoop().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L); + LoopPlugin.getPlugin().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L); getCommandQueue().tempBasalPercent(0, durationInMinutes, true, profile, new Callback() { @Override public void run() { @@ -645,7 +640,7 @@ public class ConfigBuilderPlugin extends PluginBase { } public void suspendLoop(int durationInMinutes) { - getActiveLoop().suspendTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000); + LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000); getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index e29eda04dc..e5510aae00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -9,6 +9,7 @@ import android.app.TaskStackBuilder; import android.content.Context; import android.content.Intent; import android.os.Build; +import android.support.annotation.NonNull; import android.support.v4.app.NotificationCompat; import com.crashlytics.android.answers.CustomEvent; @@ -56,6 +57,7 @@ public class LoopPlugin extends PluginBase { protected static LoopPlugin loopPlugin; + @NonNull public static LoopPlugin getPlugin() { if (loopPlugin == null) { loopPlugin = new LoopPlugin(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index f44e570774..962254e503 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -53,6 +53,7 @@ import info.nightscout.androidaps.events.EventFeatureRunning; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -334,9 +335,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com accepted = true; if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { if (useSuperBolus) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop != null) { - activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() { 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 a05df99efd..93d5b81724 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 @@ -457,16 +457,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); if (v == apsModeView) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - if (!MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) + if (loopPlugin == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) return; menu.setHeaderTitle(MainApp.gs(R.string.loop)); - if (activeloop == null) { - menu.add(MainApp.gs(R.string.enableloop)); - } else { + if (loopPlugin.isEnabled(PluginType.LOOP)) { menu.add(MainApp.gs(R.string.disableloop)); - if (!activeloop.isSuspended()) { + if (!loopPlugin.isSuspended()) { menu.add(MainApp.gs(R.string.suspendloopfor1h)); menu.add(MainApp.gs(R.string.suspendloopfor2h)); menu.add(MainApp.gs(R.string.suspendloopfor3h)); @@ -482,6 +480,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, menu.add(MainApp.gs(R.string.resume)); } } + if (!loopPlugin.isEnabled(PluginType.LOOP)) + menu.add(MainApp.gs(R.string.enableloop)); } else if (v == activeProfileView) { menu.setHeaderTitle(MainApp.gs(R.string.profile)); menu.add(MainApp.gs(R.string.danar_viewprofile)); @@ -496,10 +496,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) return true; + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (item.getTitle().equals(MainApp.gs(R.string.disableloop))) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - activeloop.setPluginEnabled(PluginType.LOOP, false); - activeloop.setFragmentVisible(PluginType.LOOP, false); + loopPlugin.setPluginEnabled(PluginType.LOOP, false); + loopPlugin.setFragmentVisible(PluginType.LOOP, false); MainApp.getConfigBuilder().storeSettings("DisablingLoop"); updateGUI("suspendmenu"); ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @@ -513,7 +513,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration return true; } else if (item.getTitle().equals(MainApp.gs(R.string.enableloop))) { - final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); loopPlugin.setPluginEnabled(PluginType.LOOP, true); loopPlugin.setFragmentVisible(PluginType.LOOP, true); MainApp.getConfigBuilder().storeSettings("EnablingLoop"); @@ -521,8 +520,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NSUpload.uploadOpenAPSOffline(0); return true; } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - activeloop.suspendTo(0L); + loopPlugin.suspendTo(0L); updateGUI("suspendmenu"); ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override @@ -675,36 +673,34 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, private void onClickAcceptTemp() { Profile profile = MainApp.getConfigBuilder().getProfile(); - if (ConfigBuilderPlugin.getActiveLoop() != null && profile != null) { - ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false); + if (LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && profile != null) { + LoopPlugin.getPlugin().invoke("Accept temp button", false); final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(getContext().getString(R.string.confirmation)); builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); - builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - hideTempRecommendation(); - clearNotification(); - MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() { - @Override - public void run() { - if (result.enacted) { - finalLastRun.tbrSetByPump = result; - finalLastRun.lastEnact = new Date(); - finalLastRun.lastOpenModeAccept = new Date(); - NSUpload.uploadDeviceStatus(); - ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class); - if (objectivesPlugin != null) { - ObjectivesPlugin.manualEnacts++; - ObjectivesPlugin.saveProgress(); - } + builder.setPositiveButton(getContext().getString(R.string.ok), (dialog, id) -> { + hideTempRecommendation(); + clearNotification(); + MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() { + @Override + public void run() { + if (result.enacted) { + finalLastRun.tbrSetByPump = result; + finalLastRun.lastEnact = new Date(); + finalLastRun.lastOpenModeAccept = new Date(); + NSUpload.uploadDeviceStatus(); + ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class); + if (objectivesPlugin != null) { + ObjectivesPlugin.manualEnacts++; + ObjectivesPlugin.saveProgress(); } - scheduleUpdateGUI("onClickAcceptTemp"); } - }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); - } + scheduleUpdateGUI("onClickAcceptTemp"); + } + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp")); }); builder.setNegativeButton(getContext().getString(R.string.cancel), null); builder.show(); @@ -770,57 +766,55 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, accepted = false; builder.setTitle(MainApp.gs(R.string.confirmation)); builder.setMessage(confirmMessage); - builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - synchronized (builder) { - if (accepted) { - log.debug("guarding: already accepted"); - return; - } - accepted = true; - if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { - if (wizard.superBolus) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop != null) { - activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); - MainApp.bus().post(new EventRefreshOverview("WizardDialog")); - } - ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() { - @Override - public void run() { - if (!result.success) { - Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", result.comment); - i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); - } - } - }); + builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> { + synchronized (builder) { + if (accepted) { + log.debug("guarding: already accepted"); + return; + } + accepted = true; + if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { + if (wizard.superBolus) { + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); + MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD; - detailedBolusInfo.insulin = finalInsulinAfterConstraints; - detailedBolusInfo.carbs = finalCarbsAfterConstraints; - detailedBolusInfo.context = context; - detailedBolusInfo.boluscalc = boluscalcJSON; - detailedBolusInfo.source = Source.USER; - ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() { @Override public void run() { if (!result.success) { Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); i.putExtra("soundid", R.raw.boluserror); i.putExtra("status", result.comment); - i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); + i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror)); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MainApp.instance().startActivity(i); } } }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard")); } + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD; + detailedBolusInfo.insulin = finalInsulinAfterConstraints; + detailedBolusInfo.carbs = finalCarbsAfterConstraints; + detailedBolusInfo.context = context; + detailedBolusInfo.boluscalc = boluscalcJSON; + detailedBolusInfo.source = Source.USER; + ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } + } + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard")); } } }); @@ -1026,24 +1020,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, apsModeView.setVisibility(View.VISIBLE); apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled)); apsModeView.setTextColor(Color.BLACK); - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) { + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuperBolus()) { apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); - apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), activeloop.minutesToEndOfSuspend())); + apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend())); apsModeView.setTextColor(Color.WHITE); - } else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isDisconnected()) { + } else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isDisconnected()) { apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); - apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), activeloop.minutesToEndOfSuspend())); + apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend())); apsModeView.setTextColor(Color.WHITE); - } else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuspended()) { + } else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuspended()) { apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); - apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), activeloop.minutesToEndOfSuspend())); + apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend())); apsModeView.setTextColor(Color.WHITE); } else if (pump.isSuspended()) { apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); apsModeView.setText(MainApp.gs(R.string.pumpsuspended)); apsModeView.setTextColor(Color.WHITE); - } else if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { + } else if (loopPlugin.isEnabled(PluginType.LOOP)) { if (closedLoopEnabled.value()) { apsModeView.setText(MainApp.gs(R.string.closedloop)); } else { @@ -1079,7 +1073,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.isChangeRequested(); // change is requested - if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && ConfigBuilderPlugin.getActiveLoop() != null) { + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) { acceptTempLayout.setVisibility(View.VISIBLE); acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 8308a2eb92..a0192a528c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -279,8 +279,7 @@ public class SmsCommunicatorPlugin extends PluginBase { FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status")); break; case "RESUME": - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - activeloop.suspendTo(0); + LoopPlugin.getPlugin().suspendTo(0); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME")); NSUpload.uploadOpenAPSOffline(0); reply = MainApp.sResources.getString(R.string.smscommunicator_loopresumed); @@ -517,8 +516,7 @@ public class SmsCommunicatorPlugin extends PluginBase { @Override public void run() { if (result.success) { - final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); + LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); String reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 48969d3dce..13d60a991d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -441,21 +441,21 @@ public class ActionStringHandler { private static String getLoopStatus() { String ret = ""; // decide if enabled/disabled closed/open; what Plugin as APS? - final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); - if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { + final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.isEnabled(loopPlugin.getType())) { if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { ret += "CLOSED LOOP\n"; } else { ret += "OPEN LOOP\n"; } - final APSInterface aps = MainApp.getConfigBuilder().getActiveAPS(); + final APSInterface aps = ConfigBuilderPlugin.getActiveAPS(); ret += "APS: " + ((aps == null) ? "NO APS SELECTED!" : ((PluginBase) aps).getName()); - if (activeloop.lastRun != null) { - if (activeloop.lastRun.lastAPSRun != null) - ret += "\nLast Run: " + DateUtil.timeString(activeloop.lastRun.lastAPSRun); + if (LoopPlugin.lastRun != null) { + if (LoopPlugin.lastRun.lastAPSRun != null) + ret += "\nLast Run: " + DateUtil.timeString(LoopPlugin.lastRun.lastAPSRun); - if (activeloop.lastRun.lastEnact != null) - ret += "\nLast Enact: " + DateUtil.timeString(activeloop.lastRun.lastEnact); + if (LoopPlugin.lastRun.lastEnact != null) + ret += "\nLast Enact: " + DateUtil.timeString(LoopPlugin.lastRun.lastEnact); } @@ -502,7 +502,7 @@ public class ActionStringHandler { return "No profile set :("; } - APSInterface usedAPS = MainApp.getConfigBuilder().getActiveAPS(); + APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); if (usedAPS == null) { return "No active APS :(!"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 668ec3f829..dcda0bc0aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -140,11 +140,7 @@ public class WearPlugin extends PluginBase { @Subscribe public void onStatusEvent(final EventRefreshOverview ev) { - - LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); - if (activeloop == null) return; - - if (WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginType.LOOP))) { + if (WatchUpdaterService.shouldReportLoopStatus(LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) { sendDataToWatch(true, false, false); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index bde197b45f..a92738d336 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -666,12 +666,12 @@ public class WatchUpdaterService extends WearableListenerService implements return status; } - LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + LoopPlugin activeloop = LoopPlugin.getPlugin(); - if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) { + if (!activeloop.isEnabled(PluginType.LOOP)) { status += getString(R.string.disabledloop) + "\n"; lastLoopStatus = false; - } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) { + } else { lastLoopStatus = true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index b6b3c07e34..5ce277e399 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -108,12 +108,12 @@ public class StatuslinePlugin extends PluginBase { @NonNull private String buildStatusString(Profile profile) { String status = ""; - LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + LoopPlugin loopPlugin = LoopPlugin.getPlugin(); - if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) { + if (!loopPlugin.isEnabled(PluginType.LOOP)) { status += ctx.getString(R.string.disabledloop) + "\n"; lastLoopStatus = false; - } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) { + } else if (loopPlugin.isEnabled(PluginType.LOOP)) { lastLoopStatus = true; } @@ -179,13 +179,8 @@ public class StatuslinePlugin extends PluginBase { @Subscribe public void onStatusEvent(final EventRefreshOverview ev) { - //Filter events where loop is (de)activated - - LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); - if (activeloop == null) return; - - if ((lastLoopStatus != activeloop.isEnabled(PluginType.LOOP))) { + if ((lastLoopStatus != LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) { sendStatus(); } } diff --git a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java index 58814ceddb..24b0d2ff05 100644 --- a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java @@ -13,6 +13,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -38,7 +39,7 @@ public class LocalAlertUtils { boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis(); if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true) - && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !ConfigBuilderPlugin.getActiveLoop().isDisconnected()) { + && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !LoopPlugin.getPlugin().isDisconnected()) { log.debug("Generating pump unreachable alarm. lastConnection: " + DateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated); Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT); n.soundId = R.raw.alarm; From e6ec114eb74f702229bc435a4bfb6888ac61e1f4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 11 Apr 2018 16:11:12 +0200 Subject: [PATCH 08/16] gradle 3.1.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b958e8ab96..9693b3a9c5 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0' + classpath 'com.android.tools.build:gradle:3.1.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 83421c7266d1921ce20ea9f42bd470871dd548f7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 11 Apr 2018 16:23:35 +0200 Subject: [PATCH 09/16] show tests in travis --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 15015ca255..72b483c9fe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,7 +50,7 @@ def generateGitBuild = { -> } tasks.matching {it instanceof Test}.all { - testLogging.events = ["failed", "skipped"] + testLogging.events = ["failed", "skipped", "started"] testLogging.exceptionFormat = "full" } From 1acefaea3c822cbb0b44de3694cb54eda1ab5b1c Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 11 Apr 2018 18:09:08 +0300 Subject: [PATCH 10/16] adding device name to AndroidAPS started note --- .../java/info/nightscout/utils/NSUpload.java | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index ad6cc45ab8..6cb110abde 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -466,7 +466,7 @@ public class NSUpload { try { data.put("eventType", "Note"); data.put("created_at", DateUtil.toISOString(new Date())); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_start)); + data.put("notes", MainApp.sResources.getString(R.string.androidaps_start)+" - "+ Build.MANUFACTURER + " "+ Build.MODEL); } catch (JSONException e) { log.error("Unhandled exception", e); } @@ -476,33 +476,7 @@ public class NSUpload { intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); - // now adding another note with the device running AndroidAPS - uploadDeviceNote(); - } - } - - public static void uploadDeviceNote(){ - if (SP.getBoolean(R.string.key_ns_logappstartedevent, true)) { - Context context = MainApp.instance().getApplicationContext(); - Bundle bundle = new Bundle(); - bundle.putString("action", "dbAdd"); - bundle.putString("collection", "treatments"); - JSONObject data = new JSONObject(); - try { - data.put("eventType", "Note"); - data.put("created_at", DateUtil.toISOString(new Date())); - data.put("notes", "Started on "+ Build.MANUFACTURER + " "+ Build.MODEL); -// log.debug("Running on: "+Build.MANUFACTURER + " "+ Build.MODEL); - } catch (JSONException e) { - log.error("Unhandled exception", e); } - bundle.putString("data", data.toString()); - Intent intent = new Intent(Intents.ACTION_DATABASE); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - DbLogger.dbAdd(intent, data.toString()); - } } public static void uploadEvent(String careportalEvent, long time) { From 613b8a2f30f9c47d8ca68cbf27bd58bdbae008bc Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Apr 2018 09:40:12 +0200 Subject: [PATCH 11/16] log profile conditional --- app/src/main/java/info/nightscout/androidaps/Config.java | 1 + app/src/main/java/info/nightscout/androidaps/data/Profile.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index ff7b935355..afb40421df 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -37,6 +37,7 @@ public class Config { public static final boolean logCongigBuilderActions = true; public static final boolean logAutosensData = false; public static final boolean logEvents = false; + public static final boolean logProfile = false; // DanaR specific public static final boolean logDanaBTComm = true; diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index e966c4d11d..783124168f 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -12,6 +12,7 @@ import java.text.DecimalFormat; import java.util.Calendar; import java.util.TimeZone; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -275,7 +276,7 @@ public class Profile { Integer getShitfTimeSecs(Integer originalTime) { Integer shiftedTime = originalTime + timeshift * 60 * 60; shiftedTime = (shiftedTime + 24 * 60 * 60) % (24 * 60 * 60); - if (timeshift != 0) + if (timeshift != 0 && Config.logProfile) log.debug("(Sec) Original time: " + originalTime + " ShiftedTime: " + shiftedTime); return shiftedTime; } From 80e81b1c25152bfae43fdf3d6b2e4ceb97ffaaed Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Apr 2018 09:53:14 +0200 Subject: [PATCH 12/16] fix NPE --- .../java/info/nightscout/androidaps/queue/QueueThread.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 f9e0739b45..8ec61932c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -53,6 +53,12 @@ public class QueueThread extends Thread { try { while (true) { PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + if (pump == null) { + log.debug("QUEUE: pump == null"); + MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.pumpNotInitialized))); + SystemClock.sleep(1000); + continue; + } long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000; if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { From dfc869ba2bdbd0726989206c0afd4f234938ac47 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Apr 2018 10:17:59 +0200 Subject: [PATCH 13/16] upload temptargets to NS properly --- .../interfaces/TreatmentsInterface.java | 1 + .../Dialogs/NewNSTreatmentDialog.java | 3 +-- .../Overview/Dialogs/NewCarbsDialog.java | 6 +++--- .../Overview/Dialogs/NewInsulinDialog.java | 2 +- .../plugins/Treatments/TreatmentsPlugin.java | 7 +++++++ .../plugins/Wear/ActionStringHandler.java | 5 +---- .../java/info/nightscout/utils/NSUpload.java | 17 +++++++++++++++++ 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 30610ca2f6..27a6a0846b 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -55,6 +55,7 @@ public interface TreatmentsInterface { TempTarget getTempTargetFromHistory(); TempTarget getTempTargetFromHistory(long time); Intervals getTempTargetsFromHistory(); + void addToHistoryTempTarget(TempTarget tempTarget); ProfileSwitch getProfileSwitchFromHistory(long time); ProfileIntervals getProfileSwitchesFromHistory(); 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 61122fb0c2..ab332dbe10 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 @@ -707,8 +707,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } else { tempTarget.low(0).high(0); } - log.debug("Creating new TempTarget db record: " + tempTarget.toString()); - MainApp.getDbHelper().createOrUpdate(tempTarget); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); NSUpload.uploadCareportalEntryToNS(data); FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java index 19119450df..08f74773f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java @@ -388,7 +388,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D .source(Source.USER) .low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())) .high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (startEatingSoonTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget() .date(System.currentTimeMillis()) @@ -397,7 +397,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D .source(Source.USER) .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (startHypoTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget() .date(System.currentTimeMillis()) @@ -406,7 +406,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D .source(Source.USER) .low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())) .high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } if (finalCarbsAfterConstraints > 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java index ce19009cf8..58971e3d80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java @@ -288,7 +288,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, .source(Source.USER) .low((int) finalTT) .high((int) finalTT); - MainApp.getDbHelper().createOrUpdate(tempTarget); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } if (finalInsulinAfterConstraints <= 0.01) { 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 36fac67834..2f5135c0cb 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 @@ -505,6 +505,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } } + @Override + public void addToHistoryTempTarget(TempTarget tempTarget) { + //log.debug("Adding new TemporaryBasal record" + profileSwitch.log()); + MainApp.getDbHelper().createOrUpdate(tempTarget); + NSUpload.uploadTempTarget(tempTarget); + } + // Profile Switch @Subscribe @SuppressWarnings("unused") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 13d60a991d..fdc14f32d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -622,10 +622,7 @@ public class ActionStringHandler { } else { tempTarget.low(0).high(0); } - MainApp.getDbHelper().createOrUpdate(tempTarget); - - //TODO: Nightscout-Treatment for Temp-Target! - //ConfigBuilderPlugin.uploadCareportalEntryToNS(data); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } private static void doFillBolus(final Double amount) { diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 6cb110abde..f78e32f15d 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; @@ -302,6 +303,22 @@ public class NSUpload { } } + public static void uploadTempTarget(TempTarget tempTarget) { + try { + JSONObject data = new JSONObject(); + data.put("eventType", CareportalEvent.TEMPORARYTARGET); + data.put("duration", tempTarget.durationInMinutes); + data.put("reason", tempTarget.reason); + data.put("targetBottom", tempTarget.low); + data.put("targetTop", tempTarget.high); + data.put("created_at", DateUtil.toISOString(tempTarget.date)); + data.put("enteredBy", MainApp.instance().getString(R.string.app_name)); + uploadCareportalEntryToNS(data); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + public static void updateProfileSwitch(ProfileSwitch profileSwitch) { try { JSONObject data = new JSONObject(); From 5eee8054c45f2ebb6b586f95edad3fabd4b7bc0f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Apr 2018 10:21:38 +0200 Subject: [PATCH 14/16] remove duplicate upload --- .../plugins/Careportal/Dialogs/NewNSTreatmentDialog.java | 1 - 1 file changed, 1 deletion(-) 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 ab332dbe10..a79e139a32 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 @@ -708,7 +708,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick tempTarget.low(0).high(0); } TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); - NSUpload.uploadCareportalEntryToNS(data); FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); } } catch (JSONException e) { From 0a377eb98e53914d136bc557b785fa15c19a668b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Apr 2018 10:32:52 +0200 Subject: [PATCH 15/16] cleanup --- .../Dialogs/NewNSTreatmentDialog.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) 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 a79e139a32..b0c74eb390 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 @@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.HardLimits; +import info.nightscout.utils.JsonHelper; import info.nightscout.utils.NSUpload; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; @@ -694,24 +695,24 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } } } else if (options.executeTempTarget) { - try { - if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) { - TempTarget tempTarget = new TempTarget() - .date(eventTime.getTime()) - .duration(data.getInt("duration")) - .reason(data.getString("reason")) - .source(Source.USER); - if (tempTarget.durationInMinutes != 0) { - tempTarget.low(Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits())) - .high(Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits())); - } else { - tempTarget.low(0).high(0); - } - TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); - FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); + final int duration = JsonHelper.safeGetInt(data, "duration"); + final double targetBottom = JsonHelper.safeGetDouble(data, "targetBottom"); + final double targetTop = JsonHelper.safeGetDouble(data, "targetTop"); + final String reason = JsonHelper.safeGetString(data, "reason", ""); + if ((targetBottom != 0d && targetTop != 0d) || duration == 0) { + TempTarget tempTarget = new TempTarget() + .date(eventTime.getTime()) + .duration(duration) + .reason(reason) + .source(Source.USER); + if (tempTarget.durationInMinutes != 0) { + tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits())) + .high(Profile.toMgdl(targetTop, profile.getUnits())); + } else { + tempTarget.low(0).high(0); } - } catch (JSONException e) { - log.error("Unhandled exception", e); + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); + FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); } } else { NSUpload.uploadCareportalEntryToNS(data); From b04eee0b52e822680bdae8bc6dc359f3e19d4488 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 12 Apr 2018 20:55:45 +0200 Subject: [PATCH 16/16] Overview: fix rendering zero-temp covering entire displayed range. (cherry picked from commit 525eaef) --- .../androidaps/plugins/Overview/graphData/GraphData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index 1a8816d0b3..9921d236a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -172,7 +172,7 @@ public class GraphData { lastAbsoluteLineBasal = absoluteLineValue; lastLineBasal = baseBasalValue; lastTempBasal = tempBasalValue; - maxBasalValueFound = Math.max(maxBasalValueFound, basal); + maxBasalValueFound = Math.max(maxBasalValueFound, Math.max(tempBasalValue, baseBasalValue)); } basalLineArray.add(new ScaledDataPoint(toTime, lastLineBasal, basalScale));