From a284f2fc38b1218656264c4dd04fe9ccfad1d623 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 9 Aug 2016 15:09:51 +0200 Subject: [PATCH] accept single devicestatus, dynamic basal scale --- app/src/main/AndroidManifest.xml | 3 +-- .../androidaps/Services/DataService.java | 12 ++++++++++ .../plugins/Overview/OverviewFragment.java | 22 +++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index afa81834c0..9adfbc8bc6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,16 +41,15 @@ + - - diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index f0f8e849e2..5ec8cf34ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -217,6 +217,18 @@ public class DataService extends IntentService { if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) { if (nsClientEnabled) { try { + if (bundles.containsKey("devicestatus")) { + String devicestatusesstring = bundles.getString("devicestatus"); + JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus")); + if (devicestatusJson.has("pump")) { + // Objectives 0 + ObjectivesPlugin objectivesPlugin = (ObjectivesPlugin) MainApp.getSpecificPlugin(ObjectivesPlugin.class); + if (objectivesPlugin != null) { + objectivesPlugin.pumpStatusIsAvailableInNS = true; + objectivesPlugin.saveProgress(); + } + } + } if (bundles.containsKey("devicestatuses")) { String devicestatusesstring = bundles.getString("devicestatuses"); JSONArray jsonArray = new JSONArray(devicestatusesstring); 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 ae06f2d58e..10ed20797d 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 @@ -458,15 +458,18 @@ public class OverviewFragment extends Fragment { } Double maxAllowedBasal = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit); + Double maxBasalValueFound = 0d; long now = new Date().getTime(); List basalArray = new ArrayList(); for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time)); + Double basal = 0d; if (tb != null) - basalArray.add(new BarDataPoint(time, tb.tempBasalConvertedToAbsolute(new Date(time)), true)); + basalArray.add(new BarDataPoint(time, basal = tb.tempBasalConvertedToAbsolute(new Date(time)), true)); else - basalArray.add(new BarDataPoint(time, profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false)); + basalArray.add(new BarDataPoint(time, basal = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false)); + maxBasalValueFound = Math.max(maxBasalValueFound, basal); } BarDataPoint[] basal = new BarDataPoint[basalArray.size()]; basal = basalArray.toArray(basal); @@ -480,13 +483,6 @@ public class OverviewFragment extends Fragment { } }); - // set second scale - bgGraph.getSecondScale().addSeries(basalsSeries); - bgGraph.getSecondScale().setMinY(0); - bgGraph.getSecondScale().setMaxY(maxAllowedBasal * 4); - bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide - - // **** BG graph **** List bgReadingsArray = MainApp.getDbHelper().getDataFromTime(fromTime); List inRangeArray = new ArrayList(); @@ -578,6 +574,14 @@ public class OverviewFragment extends Fragment { bgGraph.getViewport().setMinY(0); bgGraph.getViewport().setYAxisBoundsManual(true); bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines); + + // set second scale + bgGraph.getSecondScale().addSeries(basalsSeries); + bgGraph.getSecondScale().setMinY(0); + bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); + bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide + + } }