From e90812634bd0d3a9dd0e4606d9202c373af97dd2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 16 Jun 2017 14:37:43 +0200 Subject: [PATCH 01/21] work from old autosens branch --- .../IobCobCalculator/AutosensData.java | 7 +- .../IobCobCalculatorPlugin.java | 232 +++++++++++------- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 7 +- .../plugins/Overview/OverviewFragment.java | 128 ++++++---- app/src/main/res/layout/overview_fragment.xml | 16 ++ .../layout/overview_fragment_smallheight.xml | 16 ++ .../res/layout/overview_fragment_tablet.xml | 16 ++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/pref_openapsama.xml | 18 +- 10 files changed, 291 insertions(+), 154 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index edf16f36fc..8f15653135 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -10,15 +10,18 @@ public class AutosensData { long time = 0L; public String pastSensitivity = ""; public double deviation = 0d; - boolean calculateWithDeviation = false; + boolean nonCarbsDeviation = false; + boolean nonEqualDeviation = false; double absorbed = 0d; public double carbsFromBolus = 0d; public double cob = 0; public double bgi = 0d; public double delta = 0d; + public double autosensRatio = 1d; + public String log(long time) { - return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob; + return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio; } public int minOld() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 26bfd6741c..7b124ac762 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -19,6 +19,7 @@ import java.util.List; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; @@ -26,6 +27,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; +import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; @@ -304,6 +306,8 @@ public class IobCobCalculatorPlugin implements PluginBase { if (MainApp.getConfigBuilder() == null) return; // app still initializing //log.debug("Locking calculateSensitivityData"); + long oldestTimeWithData = oldestDataAvailable(); + synchronized (dataLock) { if (bucketed_data == null || bucketed_data.size() < 3) { @@ -371,12 +375,14 @@ public class IobCobCalculatorPlugin implements PluginBase { if (autosensData.cob <= 0) { if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) { autosensData.pastSensitivity += "="; + autosensData.nonEqualDeviation = true; } else if (deviation > 0) { autosensData.pastSensitivity += "+"; + autosensData.nonEqualDeviation = true; } else { autosensData.pastSensitivity += "-"; } - autosensData.calculateWithDeviation = true; + autosensData.nonCarbsDeviation = true; } else { autosensData.pastSensitivity += "C"; } @@ -384,6 +390,7 @@ public class IobCobCalculatorPlugin implements PluginBase { previous = autosensData; autosensDataTable.put(bgTime, autosensData); + autosensData.autosensRatio = detectSensitivity(oldestTimeWithData, bgTime).ratio; if (Config.logAutosensData) log.debug(autosensData.log(bgTime)); } @@ -392,6 +399,15 @@ public class IobCobCalculatorPlugin implements PluginBase { //log.debug("Releasing calculateSensitivityData"); } + public static long oldestDataAvailable() { + long now = System.currentTimeMillis(); + + long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); + long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - 60 * 60 * 1000L * (24 + MainApp.getConfigBuilder().getProfile().getDia()))); + log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); + return getBGDataFrom; + } + public static IobTotal calulateFromTreatmentsAndTemps(long time) { long now = System.currentTimeMillis(); time = roundUpTime(time); @@ -493,102 +509,109 @@ public class IobCobCalculatorPlugin implements PluginBase { return array; } - public static AutosensResult detectSensitivity(long fromTime) { - //log.debug("Locking detectSensitivity"); + public static AutosensResult detectSensitivityWithLock(long fromTime, long toTime) { synchronized (dataLock) { - if (autosensDataTable == null || autosensDataTable.size() < 4) { - log.debug("No autosens data available"); - return new AutosensResult(); - } - - AutosensData current = getLastAutosensData(); - if (current == null) { - log.debug("No current autosens data available"); - return new AutosensResult(); - } - - - List deviationsArray = new ArrayList<>(); - String pastSensitivity = ""; - int index = 0; - while (index < autosensDataTable.size()) { - AutosensData autosensData = autosensDataTable.valueAt(index); - - if (autosensData.time < fromTime) { - index++; - continue; - } - - if (autosensData.calculateWithDeviation) - deviationsArray.add(autosensData.deviation); - - pastSensitivity += autosensData.pastSensitivity; - int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); - if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { - pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; - } - index++; - } - - Double[] deviations = new Double[deviationsArray.size()]; - deviations = deviationsArray.toArray(deviations); - - Profile profile = MainApp.getConfigBuilder().getProfile(); - - double sens = profile.getIsf(); - - double ratio = 1; - String ratioLimit = ""; - String sensResult = ""; - - log.debug("Records: " + index + " " + pastSensitivity); - Arrays.sort(deviations); - - for (double i = 0.9; i > 0.1; i = i - 0.02) { - if (percentile(deviations, (i + 0.02)) >= 0 && percentile(deviations, i) < 0) { - log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)"); - } - } - double pSensitive = percentile(deviations, 0.50); - double pResistant = percentile(deviations, 0.45); - - double basalOff = 0; - - if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); - sensResult = "Excess insulin sensitivity detected"; - } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); - sensResult = "Excess insulin resistance detected"; - } else { - sensResult = "Sensitivity normal"; - } - log.debug(sensResult); - ratio = 1 + (basalOff / profile.getMaxDailyBasal()); - - double rawRatio = ratio; - ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); - ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); - - if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; - log.debug(ratioLimit); - } - - double newisf = Math.round(Profile.toMgdl(sens, profile.getUnits()) / ratio); - if (ratio != 1) { - log.debug("ISF adjusted from " + Profile.toMgdl(sens, profile.getUnits()) + " to " + newisf); - } - - AutosensResult output = new AutosensResult(); - output.ratio = Round.roundTo(ratio, 0.01); - output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); - output.pastSensitivity = pastSensitivity; - output.ratioLimit = ratioLimit; - output.sensResult = sensResult; - return output; + return detectSensitivity(fromTime, toTime); } - //log.debug("Releasing detectSensitivity"); + } + + public static AutosensResult detectSensitivity(long fromTime, long toTime) { + String age = SP.getString(R.string.key_age, ""); + int defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; + if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; + int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); + + long now = System.currentTimeMillis(); + + if (autosensDataTable == null || autosensDataTable.size() < 4) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + AutosensData current = getAutosensData(toTime); + if (current == null) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + + List deviationsArray = new ArrayList<>(); + String pastSensitivity = ""; + int index = 0; + while (index < autosensDataTable.size()) { + AutosensData autosensData = autosensDataTable.valueAt(index); + + if (autosensData.time < fromTime) { + index++; + continue; + } + + if (autosensData.time > toTime) { + index++; + continue; + } + + if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L) + deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d); + if (deviationsArray.size() > hoursForDetection * 60 / 5) + deviationsArray.remove(0); + + + pastSensitivity += autosensData.pastSensitivity; + int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); + if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { + pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; + } + index++; + } + + Double[] deviations = new Double[deviationsArray.size()]; + deviations = deviationsArray.toArray(deviations); + + Profile profile = MainApp.getConfigBuilder().getProfile(); + + double sens = profile.getIsf(); + + String ratioLimit = ""; + String sensResult = ""; + + log.debug("Records: " + index + " " + pastSensitivity); + Arrays.sort(deviations); + + double percentile = percentile(deviations, 0.50); + double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); + + if (percentile < 0) { // sensitive + sensResult = "Excess insulin sensitivity detected"; + } else if (percentile > 0) { // resistant + sensResult = "Excess insulin resistance detected"; + } else { + sensResult = "Sensitivity normal"; + } + + log.debug(sensResult); + + double rawRatio = ratio; + ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); + ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); + + if (ratio != rawRatio) { + ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + log.debug(ratioLimit); + } + + log.error("Sensitivity to: " + new Date(toTime).toLocaleString() + " percentile: " + percentile); + + AutosensResult output = new AutosensResult(); + output.ratio = Round.roundTo(ratio, 0.01); + output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); + output.pastSensitivity = pastSensitivity; + output.ratioLimit = ratioLimit; + output.sensResult = sensResult; + return output; } @@ -634,6 +657,25 @@ public class IobCobCalculatorPlugin implements PluginBase { }); } + @Subscribe + public void onStatusEvent(EventPreferenceChange ev) { + if (ev.isChanged(R.string.key_openapsama_autosens_period) || + ev.isChanged(R.string.key_age) + ) { + synchronized (dataLock) { + log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); + iobTable = new LongSparseArray<>(); + autosensDataTable = new LongSparseArray<>(); + } + sHandler.post(new Runnable() { + @Override + public void run() { + calculateSensitivityData(); + } + }); + } + } + // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated @Subscribe public void onNewHistoryData(EventNewHistoryData ev) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index df0c293d80..88ab7d71eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -207,14 +207,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; - long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); - long getBGDataFrom = Math.max(oldestDataAvailable, (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + profile.getDia()))); - log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); - startPart = new Date(); if (MainApp.getConfigBuilder().isAMAModeEnabled()) { - //lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(getBGDataFrom, null); - lastAutosensResult = IobCobCalculatorPlugin.detectSensitivity(getBGDataFrom); + lastAutosensResult = IobCobCalculatorPlugin.detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); } else { lastAutosensResult = new AutosensResult(); } 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 3b0ba86782..1739c4aa2c 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 @@ -164,6 +164,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, CheckBox showIobView; CheckBox showCobView; CheckBox showDeviationsView; + CheckBox showRatiosView; RecyclerView notificationsView; LinearLayoutManager llm; @@ -275,36 +276,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, showIobView = (CheckBox) view.findViewById(R.id.overview_showiob); showCobView = (CheckBox) view.findViewById(R.id.overview_showcob); showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations); + showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios); showPredictionView.setChecked(SP.getBoolean("showprediction", false)); showBasalsView.setChecked(SP.getBoolean("showbasals", true)); showIobView.setChecked(SP.getBoolean("showiob", false)); showCobView.setChecked(SP.getBoolean("showcob", false)); showDeviationsView.setChecked(SP.getBoolean("showdeviations", false)); + showRatiosView.setChecked(SP.getBoolean("showratios", false)); showPredictionView.setOnCheckedChangeListener(this); showBasalsView.setOnCheckedChangeListener(this); showIobView.setOnCheckedChangeListener(this); showCobView.setOnCheckedChangeListener(this); showDeviationsView.setOnCheckedChangeListener(this); + showRatiosView.setOnCheckedChangeListener(this); notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); notificationsView.setHasFixedSize(true); llm = new LinearLayoutManager(view.getContext()); notificationsView.setLayoutManager(llm); -/* - final LinearLayout graphs = (LinearLayout)view.findViewById(R.id.overview_graphs_layout); - ViewTreeObserver observer = graphs.getViewTreeObserver(); - observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - log.debug("Height: " + graphs.getHeight()); - graphs.getViewTreeObserver().removeGlobalOnLayoutListener( - this); - int heightNeeded = Math.max(320, graphs.getHeight() - 200); - if (heightNeeded != bgGraph.getHeight()) - bgGraph.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, heightNeeded)); - } - }); -*/ + bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); bgGraph.getGridLabelRenderer().reloadStyles(); iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); @@ -358,34 +348,29 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.overview_showprediction: - SP.putBoolean("showprediction", showPredictionView.isChecked()); - updateGUI("onPredictionCheckedChanged"); - break; case R.id.overview_showbasals: - SP.putBoolean("showbasals", showBasalsView.isChecked()); - updateGUI("onBasalsCheckedChanged"); - break; case R.id.overview_showiob: - SP.putBoolean("showiob", showIobView.isChecked()); - updateGUI("onIobCheckedChanged"); break; case R.id.overview_showcob: showDeviationsView.setOnCheckedChangeListener(null); showDeviationsView.setChecked(false); showDeviationsView.setOnCheckedChangeListener(this); - SP.putBoolean("showcob", showCobView.isChecked()); - SP.putBoolean("showdeviations", showDeviationsView.isChecked()); - updateGUI("onCobCheckedChanged"); break; case R.id.overview_showdeviations: showCobView.setOnCheckedChangeListener(null); showCobView.setChecked(false); showCobView.setOnCheckedChangeListener(this); - SP.putBoolean("showcob", showCobView.isChecked()); - SP.putBoolean("showdeviations", showDeviationsView.isChecked()); - updateGUI("onDeviationsCheckedChanged"); + break; + case R.id.overview_showratios: break; } + SP.putBoolean("showiob", showIobView.isChecked()); + SP.putBoolean("showprediction", showPredictionView.isChecked()); + SP.putBoolean("showbasals", showBasalsView.isChecked()); + SP.putBoolean("showcob", showCobView.isChecked()); + SP.putBoolean("showdeviations", showDeviationsView.isChecked()); + SP.putBoolean("showratios", showRatiosView.isChecked()); + scheduleUpdateGUI("onGraphCheckboxesCheckedChanged"); } @Override @@ -1289,15 +1274,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, FixedLineGraphSeries iobSeries; FixedLineGraphSeries cobSeries; BarGraphSeries devSeries; + LineGraphSeries ratioSeries; Double maxIobValueFound = 0d; Double maxCobValueFound = 0d; Double maxDevValueFound = 0d; + Double maxRatioValueFound = 0d; - if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) { + if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { //Date start = new Date(); List iobArray = new ArrayList<>(); List cobArray = new ArrayList<>(); List devArray = new ArrayList<>(); + List ratioArray = new ArrayList<>(); double lastIob = 0; int lastCob = 0; for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) { @@ -1311,7 +1299,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, lastIob = iob; } } - if (showCobView.isChecked() || showDeviationsView.isChecked()) { + if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); if (autosensData != null && showCobView.isChecked()) { int cob = (int) autosensData.cob; @@ -1331,6 +1319,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, devArray.add(new DeviationDataPoint(time, autosensData.deviation, color)); maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation)); } + if (autosensData != null && showRatiosView.isChecked()) { + ratioArray.add(new DataPoint(time, autosensData.autosensRatio)); + maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio)); + } } } //Profiler.log(log, "IOB processed", start); @@ -1343,18 +1335,49 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, iobSeries.setThickness(3); - if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) { - List cobArrayRescaled = new ArrayList<>(); - List devArrayRescaled = new ArrayList<>(); - for (int ci = 0; ci < cobArray.size(); ci++) { - cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2)); - } - for (int ci = 0; ci < devArray.size(); ci++) { - devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound, devArray.get(ci).color)); - } - cobArray = cobArrayRescaled; - devArray = devArrayRescaled; + Double maxByScale = null; + int graphsToShow = 0; + if (showIobView.isChecked()) { + if (maxByScale == null) maxByScale = maxIobValueFound; + graphsToShow++; } + if (showCobView.isChecked()) { + if (maxByScale == null) maxByScale = maxCobValueFound; + graphsToShow++; + } + if (showDeviationsView.isChecked()) { + if (maxByScale == null) maxByScale = maxDevValueFound; + graphsToShow++; + } + if (showRatiosView.isChecked()) { + if (maxByScale == null) maxByScale = maxRatioValueFound; + graphsToShow++; + } + + if (graphsToShow > 1) { + if (!maxByScale.equals(maxCobValueFound)) { + List cobArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < cobArray.size(); ci++) { + cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2)); + } + cobArray = cobArrayRescaled; + } + if (!maxByScale.equals(maxDevValueFound)) { + List devArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < devArray.size(); ci++) { + devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color)); + } + devArray = devArrayRescaled; + } + if (!maxByScale.equals(maxRatioValueFound)) { + List ratioArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < ratioArray.size(); ci++) { + ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound)); + } + ratioArray = ratioArrayRescaled; + } + } + // COB DataPoint[] cobData = new DataPoint[cobArray.size()]; cobData = cobArray.toArray(cobData); @@ -1374,9 +1397,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return data.color; } }); - //devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50% - //devSeries.setColor(MainApp.sResources.getColor(R.color.cob)); - //devSeries.setThickness(3); + + // RATIOS + DataPoint[] ratioData = new DataPoint[ratioArray.size()]; + ratioData = ratioArray.toArray(ratioData); + ratioSeries = new LineGraphSeries<>(ratioData); + ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio)); + ratioSeries.setThickness(3); iobGraph.getSeries().clear(); @@ -1389,6 +1416,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (showDeviationsView.isChecked() && devData.length > 0) { addSeriesWithoutInvalidate(devSeries, iobGraph); } + if (showRatiosView.isChecked() && ratioData.length > 0) { + addSeriesWithoutInvalidate(ratioSeries, iobGraph); + } iobGraph.setVisibility(View.VISIBLE); } else { iobGraph.setVisibility(View.GONE); @@ -1591,20 +1621,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, //Notifications - public static class RecyclerViewAdapter extends RecyclerView.Adapter { + static class RecyclerViewAdapter extends RecyclerView.Adapter { List notificationsList; RecyclerViewAdapter(List notificationsList) { this.notificationsList = notificationsList; - log.debug("RecyclerViewAdapter"); } @Override public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false); - NotificationsViewHolder notificationsViewHolder = new NotificationsViewHolder(v); - return notificationsViewHolder; + return new NotificationsViewHolder(v); } @Override @@ -1635,7 +1663,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, super.onAttachedToRecyclerView(recyclerView); } - public static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { CardView cv; TextView time; TextView text; diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index ef846a73ba..8ecf3ae128 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -287,6 +287,22 @@ android:layout_marginBottom="-5dp" android:layout_marginTop="-9dp" app:buttonTint="@color/deviations" /> + + + + + + + + + + + + + + + #00ffff #FFFB8C00 #8BC34A + #FFFFFF #00FF00 #FF0000 #FFFF00 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afe574c1ab..8787b618b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -646,4 +646,8 @@ Urgent stale data Stale data threshold [min] Urgent stale data threshold [min] + Interval for autosens [h] + Amount of hours in the past for sensitivity detection (carbs absorption time is excluded) + openapsama_autosens_period + RAT diff --git a/app/src/main/res/xml/pref_openapsama.xml b/app/src/main/res/xml/pref_openapsama.xml index 0dce8b7d8a..b9576242dc 100644 --- a/app/src/main/res/xml/pref_openapsama.xml +++ b/app/src/main/res/xml/pref_openapsama.xml @@ -1,5 +1,6 @@ - + @@ -9,6 +10,21 @@ android:key="openapsama_useautosens" android:title="@string/openapsama_useautosens" /> + + \ No newline at end of file From 4b1263e2e0b2ab456db52eca3f6e5a3e12bd93ef Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 19 Jun 2017 16:28:36 +0200 Subject: [PATCH 02/21] small simplify --- .../androidaps/plugins/Overview/OverviewFragment.java | 4 ++-- .../Overview/graphExtensions/TimeAsXAxisLabelFormatter.java | 4 +--- .../androidaps/plugins/Treatments/TreatmentsPlugin.java | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) 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 1739c4aa2c..1123d5f7a7 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 @@ -1480,7 +1480,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; if (highLine > maxBgValue) maxBgValue = highLine; - Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); + Integer numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()]; bg = bgListArray.toArray(bg); @@ -1548,7 +1548,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, bgGraph.getViewport().setMaxY(maxBgValue); bgGraph.getViewport().setMinY(0); bgGraph.getViewport().setYAxisBoundsManual(true); - bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines); + bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines); // set second scale if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java index c8ba40369d..881e472a1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java @@ -23,10 +23,8 @@ public class TimeAsXAxisLabelFormatter extends DefaultLabelFormatter { public String formatLabel(double value, boolean isValueX) { if (isValueX) { // format as date - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis((long) value); DateFormat dateFormat = new SimpleDateFormat(mFormat); - return dateFormat.format(calendar.getTimeInMillis()); + return dateFormat.format((long) value); } else { return super.formatLabel(value, isValueX); } 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 97fe9070dd..d449a7f312 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 @@ -242,7 +242,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { List in5minback = new ArrayList<>(); for (Integer pos = 0; pos < treatments.size(); pos++) { Treatment t = treatments.get(pos); - if (t.date <= time && t.date > time - 5 * 60 * 1000) + if (t.date <= time && t.date > time - 5 * 60 * 1000 && t.carbs > 0) in5minback.add(t); } return in5minback; From 80962e33d774a57652b49d27e69f288823564bed Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 20 Jun 2017 19:52:46 +0200 Subject: [PATCH 03/21] allow to ignore profileswitch events --- .../androidaps/PreferencesActivity.java | 2 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 26 +++++++++++-------- app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/pref_advanced.xml | 8 ++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index fa19e9b596..43bfb53c79 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -134,8 +134,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_smscommunicator); if (Config.ALLPREFERENCES) { addPreferencesFromResource(R.xml.pref_others); - addPreferencesFromResource(R.xml.pref_advanced); } + addPreferencesFromResource(R.xml.pref_advanced); if (Config.WEAR) { WearPlugin wearPlugin = (WearPlugin) MainApp.getSpecificPlugin(WearPlugin.class); 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 6a18084b5e..ef33baf910 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 @@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.NSUpload; +import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. @@ -1014,19 +1015,22 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain public Profile getProfile(long time) { //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); - ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); - if (profileSwitch != null) { - if (profileSwitch.profileJson != null) { - return profileSwitch.getProfileObject(); - } else if (activeProfile.getProfile() != null){ - Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName); - if (profile != null) - return profile; + boolean ignoreProfileSwitchEvents = SP.getBoolean(R.string.key_do_not_track_profile_switch, false); + if (!ignoreProfileSwitchEvents) { + ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); + if (profileSwitch != null) { + if (profileSwitch.profileJson != null) { + return profileSwitch.getProfileObject(); + } else if (activeProfile.getProfile() != null) { + Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName); + if (profile != null) + return profile; + } } + // Unable to determine profile, failover to default + if (activeProfile.getProfile() == null) + return null; //app not initialized } - // Unable to determine profile, failover to default - if (activeProfile.getProfile() == null) - return null; //app not initialized Profile defaultProfile = activeProfile.getProfile().getDefaultProfile(); if (defaultProfile != null) return defaultProfile; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8787b618b4..abacb4c18b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -650,4 +650,7 @@ Amount of hours in the past for sensitivity detection (carbs absorption time is excluded) openapsama_autosens_period RAT + do_not_track_profile_switch + Ignore profile switch events + All profile switch events are ignoreg and active profile is always used diff --git a/app/src/main/res/xml/pref_advanced.xml b/app/src/main/res/xml/pref_advanced.xml index 05898654fe..a511327577 100644 --- a/app/src/main/res/xml/pref_advanced.xml +++ b/app/src/main/res/xml/pref_advanced.xml @@ -128,6 +128,14 @@ android:dialogMessage="@string/openapsama_min_5m_carbimpact_summary" android:key="openapsama_min_5m_carbimpact" /> + + + From 5360129e5fb47b36c2bcea0a39ca92271a428a7d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Jun 2017 11:04:09 +0200 Subject: [PATCH 04/21] sensitivity plugins --- .../info/nightscout/androidaps/MainApp.java | 5 +- .../androidaps/interfaces/PluginBase.java | 2 +- .../interfaces/SensitivityInterface.java | 11 ++ .../ConfigBuilder/ConfigBuilderFragment.java | 15 ++- .../ConfigBuilder/ConfigBuilderPlugin.java | 101 +++--------------- .../SensitivityMK/SensitivityMKPlugin.java | 85 +++++++++++++++ .../SensitivityOref0Plugin.java | 85 +++++++++++++++ .../res/layout/configbuilder_fragment.xml | 16 ++- app/src/main/res/values/strings.xml | 4 + 9 files changed, 233 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 1e49b03d73..a18e995d2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -47,8 +47,9 @@ import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanEx import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Fragment; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.PumpMDI.MDIFragment; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin; +import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment; import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment; import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; @@ -98,6 +99,8 @@ public class MainApp extends Application { if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin()); pluginsList.add(InsulinFastactingFragment.getPlugin()); pluginsList.add(InsulinFastactingProlongedFragment.getPlugin()); + pluginsList.add(SensitivityOref0Plugin.getPlugin()); + pluginsList.add(SensitivityMKPlugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRKoreanFragment.getPlugin()); if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index ba4faf4ba6..bf5e66f2a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -8,7 +8,7 @@ import java.util.Date; public interface PluginBase { int GENERAL = 1; int TREATMENT = 2; - //int TEMPBASAL = 3; + int SENSITIVITY = 3; int PROFILE = 4; int APS = 5; int PUMP = 6; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java new file mode 100644 index 0000000000..deb649c21f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.interfaces; + +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; + +/** + * Created by mike on 24.06.2017. + */ + +public interface SensitivityInterface { + AutosensResult detectSensitivity(long fromTime, long toTime); +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index 8aa43831f5..bd269e7c66 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -34,9 +34,11 @@ import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingPlugin; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.utils.PasswordProtection; @@ -49,6 +51,7 @@ public class ConfigBuilderFragment extends Fragment { } ListView insulinListView; + ListView sensitivityListView; ListView bgsourceListView; TextView bgsourceLabel; ListView pumpListView; @@ -71,6 +74,7 @@ public class ConfigBuilderFragment extends Fragment { Button unlock; PluginCustomAdapter insulinDataAdapter = null; + PluginCustomAdapter sensivityDataAdapter = null; PluginCustomAdapter bgsourceDataAdapter = null; PluginCustomAdapter pumpDataAdapter = null; PluginCustomAdapter loopDataAdapter = null; @@ -96,6 +100,7 @@ public class ConfigBuilderFragment extends Fragment { smallWidth = screen_width < Constants.SMALL_WIDTH; insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview); + sensitivityListView = (ListView) view.findViewById(R.id.configbuilder_sensitivitylistview); bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview); bgsourceLabel = (TextView) view.findViewById(R.id.configbuilder_bgsourcelabel); pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview); @@ -178,6 +183,9 @@ public class ConfigBuilderFragment extends Fragment { setListViewHeightBasedOnChildren(apsListView); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.APS).size() == 0) apsLabel.setVisibility(View.GONE); + sensivityDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginBase.SENSITIVITY), PluginBase.SENSITIVITY); + sensitivityListView.setAdapter(sensivityDataAdapter); + setListViewHeightBasedOnChildren(sensitivityListView); constraintsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginBase.BGSOURCE), PluginBase.CONSTRAINTS); constraintsListView.setAdapter(constraintsDataAdapter); setListViewHeightBasedOnChildren(constraintsListView); @@ -277,7 +285,7 @@ public class ConfigBuilderFragment extends Fragment { } // Hide enabled control and force enabled plugin if there is only one plugin available - if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.PROFILE) + if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.PROFILE || type == PluginBase.SENSITIVITY) if (pluginList.size() < 2) { holder.checkboxEnabled.setEnabled(false); plugin.setFragmentEnabled(type, true); @@ -326,6 +334,9 @@ public class ConfigBuilderFragment extends Fragment { case PluginBase.INSULIN: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class); break; + case PluginBase.SENSITIVITY: + pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class); + break; case PluginBase.APS: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class); break; @@ -356,6 +367,8 @@ public class ConfigBuilderFragment extends Fragment { MainApp.getSpecificPlugin(VirtualPumpPlugin.class).setFragmentEnabled(type, true); else if (type == PluginBase.INSULIN) MainApp.getSpecificPlugin(InsulinFastactingPlugin.class).setFragmentEnabled(type, true); + else if (type == PluginBase.SENSITIVITY) + MainApp.getSpecificPlugin(SensitivityOref0Plugin.class).setFragmentEnabled(type, true); else if (type == PluginBase.PROFILE) MainApp.getSpecificPlugin(NSProfilePlugin.class).setFragmentEnabled(type, true); else 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 ef33baf910..f8c7e844f7 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 @@ -40,6 +40,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -65,6 +66,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain private static APSInterface activeAPS; private static LoopPlugin activeLoop; private static InsulinInterface activeInsulin; + private static SensitivityInterface activeSensitivity; static public String nightscoutVersionName = ""; static public Integer nightscoutVersionCode = 0; @@ -218,6 +220,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain log.debug(p.getName() + ":" + (p.isEnabled(1) ? " GENERAL" : "") + (p.isEnabled(2) ? " TREATMENT" : "") + + (p.isEnabled(3) ? " SENSITIVITY" : "") + (p.isEnabled(4) ? " PROFILE" : "") + (p.isEnabled(5) ? " APS" : "") + (p.isEnabled(6) ? " PUMP" : "") + @@ -256,6 +259,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } } + // PluginBase.SENSITIVITY + pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class); + activeSensitivity = (SensitivityInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.SENSITIVITY); + if (Config.logConfigBuilder) + log.debug("Selected sensitivity interface: " + ((PluginBase) activeSensitivity).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activeSensitivity).getName())) { + p.setFragmentVisible(PluginBase.SENSITIVITY, false); + } + } + // PluginBase.PROFILE pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class); activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PROFILE); @@ -411,43 +425,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return 0d; } - /* - public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { - mWakeLock.acquire(); - PumpEnactResult result; - insulin = applyBolusConstraints(insulin); - carbs = applyCarbsConstraints(carbs); - - BolusProgressDialog bolusProgressDialog = null; - if (context != null) { - bolusProgressDialog = new BolusProgressDialog(); - bolusProgressDialog.setInsulin(insulin); - bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); - } - - MainApp.bus().post(new EventBolusRequested(insulin)); - - result = activePump.deliverTreatment(insulinType, insulin, carbs, context); - - BolusProgressDialog.bolusEnded = true; - - MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); - - if (result.success) { - Treatment t = new Treatment(insulinType); - t.insulin = result.bolusDelivered; - if (carbTime == 0) - t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout - t.date = System.currentTimeMillis(); - t.mealBolus = result.carbsDelivered > 0; - addToHistoryTreatment(t); - t.carbs = (double) result.carbsDelivered; - NSUpload.uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc); - } - mWakeLock.release(); - return result; - } - */ @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { mWakeLock.acquire(); @@ -473,56 +450,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return result; } - /* - @Override - public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { - return deliverTreatment(insulinType, insulin, carbs, context, true); - } - - public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context, boolean createTreatment) { - mWakeLock.acquire(); - PumpEnactResult result; - insulin = applyBolusConstraints(insulin); - carbs = applyCarbsConstraints(carbs); - - BolusProgressDialog bolusProgressDialog = null; - if (context != null) { - bolusProgressDialog = new BolusProgressDialog(); - bolusProgressDialog.setInsulin(insulin); - bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); - } else { - Intent i = new Intent(); - i.putExtra("insulin", insulin.doubleValue()); - i.setClass(MainApp.instance(), BolusProgressHelperActivity.class); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); - } - - MainApp.bus().post(new EventBolusRequested(insulin)); - - result = activePump.deliverTreatment(insulinType, insulin, carbs, context); - - BolusProgressDialog.bolusEnded = true; - - MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); - - if (Config.logCongigBuilderActions) - log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); - - if (result.success && createTreatment) { - Treatment t = new Treatment(insulinType); - t.insulin = result.bolusDelivered; - t.carbs = (double) result.carbsDelivered; - t.date = System.currentTimeMillis(); - t.mealBolus = t.carbs > 0; - addToHistoryTreatment(t); - NSUpload.uploadTreatment(t); - } - mWakeLock.release(); - return result; - } - - */ @Override public void stopBolusDelivering() { activePump.stopBolusDelivering(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java new file mode 100644 index 0000000000..210614714f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java @@ -0,0 +1,85 @@ +package info.nightscout.androidaps.plugins.SensitivityMK; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.SensitivityInterface; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; + +/** + * Created by mike on 24.06.2017. + */ + +public class SensitivityMKPlugin implements PluginBase, SensitivityInterface{ + private static boolean fragmentEnabled = true; + private static boolean fragmentVisible = false; + + static SensitivityMKPlugin plugin = null; + + public static SensitivityMKPlugin getPlugin() { + if (plugin == null) + plugin = new SensitivityMKPlugin(); + return plugin; + } + + @Override + public int getType() { + return INSULIN; + } + + @Override + public String getFragmentClass() { + return null; + } + + @Override + public String getName() { + return MainApp.sResources.getString(R.string.sensitivitymk); + } + + @Override + public String getNameShort() { + return MainApp.sResources.getString(R.string.sensitivity_shortname); + } + + @Override + public boolean isEnabled(int type) { + return type == SENSITIVITY && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return type == SENSITIVITY && fragmentVisible; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return false; + } + + @Override + public boolean showInList(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == SENSITIVITY) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible; + } + + + @Override + public AutosensResult detectSensitivity(long fromTime, long toTime) { + return null; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java new file mode 100644 index 0000000000..672e878acb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java @@ -0,0 +1,85 @@ +package info.nightscout.androidaps.plugins.SensitivityOref0; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.SensitivityInterface; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; + +/** + * Created by mike on 24.06.2017. + */ + +public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface{ + private static boolean fragmentEnabled = true; + private static boolean fragmentVisible = false; + + static SensitivityOref0Plugin plugin = null; + + public static SensitivityOref0Plugin getPlugin() { + if (plugin == null) + plugin = new SensitivityOref0Plugin(); + return plugin; + } + + @Override + public int getType() { + return INSULIN; + } + + @Override + public String getFragmentClass() { + return null; + } + + @Override + public String getName() { + return MainApp.sResources.getString(R.string.sensitivityoref0); + } + + @Override + public String getNameShort() { + return MainApp.sResources.getString(R.string.sensitivity_shortname); + } + + @Override + public boolean isEnabled(int type) { + return type == SENSITIVITY && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return type == SENSITIVITY && fragmentVisible; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return false; + } + + @Override + public boolean showInList(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == SENSITIVITY) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible; + } + + + @Override + public AutosensResult detectSensitivity(long fromTime, long toTime) { + return null; + } +} diff --git a/app/src/main/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml index 64841fe593..e4de98b02e 100644 --- a/app/src/main/res/layout/configbuilder_fragment.xml +++ b/app/src/main/res/layout/configbuilder_fragment.xml @@ -41,7 +41,6 @@ android:layout_marginRight="10dp" android:background="@color/cardColorBackground" /> - + + + do_not_track_profile_switch Ignore profile switch events All profile switch events are ignoreg and active profile is always used + Sensitivity detection + SENS + Sensitivity Oref0 + Sensitivity MK From b39f59f59e46fa88f59a3e1000ffb8ecc0099547 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Jun 2017 13:22:50 +0200 Subject: [PATCH 05/21] remove unneeded fragments --- .../info/nightscout/androidaps/MainApp.java | 32 +++++++++---------- .../ConstraintsSafety/SafetyFragment.java | 17 ---------- .../ConstraintsSafety/SafetyPlugin.java | 10 +++++- .../IobCobCalculatorFragment.java | 16 ---------- .../IobCobCalculatorPlugin.java | 10 +++++- .../PersistentNotificationFragment.java | 12 ------- .../PersistentNotificationPlugin.java | 2 +- .../plugins/PumpMDI/MDIFragment.java | 12 ------- .../androidaps/plugins/PumpMDI/MDIPlugin.java | 12 +++++-- .../SourceGlimp/SourceGlimpFragment.java | 14 -------- .../SourceGlimp/SourceGlimpPlugin.java | 11 +++++-- .../SourceMM640g/SourceMM640gFragment.java | 14 -------- .../SourceMM640g/SourceMM640gPlugin.java | 12 +++++-- .../SourceNSClientFragment.java | 14 -------- .../SourceNSClient/SourceNSClientPlugin.java | 10 +++++- .../SourceXdrip/SourceXdripFragment.java | 13 -------- .../SourceXdrip/SourceXdripPlugin.java | 11 +++++-- .../XDripStatusline/StatuslineFragment.java | 29 ----------------- .../XDripStatusline/StatuslinePlugin.java | 13 +++++++- 19 files changed, 94 insertions(+), 170 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslineFragment.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index a18e995d2c..b820393c33 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -26,10 +26,10 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment; -import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyFragment; +import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment; import info.nightscout.androidaps.plugins.InsulinFastactingProlonged.InsulinFastactingProlongedFragment; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorFragment; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopFragment; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment; @@ -46,18 +46,18 @@ import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanFragment; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Fragment; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; -import info.nightscout.androidaps.plugins.PumpMDI.MDIFragment; +import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment; -import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment; -import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; -import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; -import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment; +import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; +import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; +import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; +import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.androidaps.plugins.Wear.WearFragment; -import info.nightscout.androidaps.plugins.XDripStatusline.StatuslineFragment; +import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.utils.NSUpload; import io.fabric.sdk.android.Fabric; @@ -95,7 +95,7 @@ public class MainApp extends Application { pluginsList = new ArrayList<>(); // Register all tabs in app here pluginsList.add(OverviewFragment.getPlugin()); - pluginsList.add(IobCobCalculatorFragment.getPlugin()); + pluginsList.add(IobCobCalculatorPlugin.getPlugin()); if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin()); pluginsList.add(InsulinFastactingFragment.getPlugin()); pluginsList.add(InsulinFastactingProlongedFragment.getPlugin()); @@ -105,7 +105,7 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRKoreanFragment.getPlugin()); if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin()); pluginsList.add(CareportalFragment.getPlugin()); - if (Config.MDI) pluginsList.add(MDIFragment.getPlugin()); + if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin()); @@ -116,19 +116,19 @@ public class MainApp extends Application { if (Config.OTHERPROFILES) pluginsList.add(CircadianPercentageProfileFragment.getPlugin()); pluginsList.add(TreatmentsFragment.getPlugin()); - if (Config.SAFETY) pluginsList.add(SafetyFragment.getPlugin()); + if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin()); if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin()); if (!Config.NSCLIENT) - pluginsList.add(SourceXdripFragment.getPlugin()); - pluginsList.add(SourceNSClientFragment.getPlugin()); + pluginsList.add(SourceXdripPlugin.getPlugin()); + pluginsList.add(SourceNSClientPlugin.getPlugin()); if (!Config.NSCLIENT) - pluginsList.add(SourceMM640gFragment.getPlugin()); + pluginsList.add(SourceMM640gPlugin.getPlugin()); if (!Config.NSCLIENT) - pluginsList.add(SourceGlimpFragment.getPlugin()); + pluginsList.add(SourceGlimpPlugin.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.getPlugin()); if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this)); - pluginsList.add(StatuslineFragment.getPlugin(this)); + pluginsList.add(StatuslinePlugin.getPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalFragment.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyFragment.java deleted file mode 100644 index 07583e7622..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyFragment.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.nightscout.androidaps.plugins.ConstraintsSafety; - - -import android.support.v4.app.Fragment; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SafetyFragment extends Fragment { - private static Logger log = LoggerFactory.getLogger(SafetyFragment.class); - - private static SafetyPlugin safetyPlugin = new SafetyPlugin(); - - public static SafetyPlugin getPlugin() { - return safetyPlugin; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index 213bba47fa..c685cd472d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -21,9 +21,17 @@ import info.nightscout.utils.SP; public class SafetyPlugin implements PluginBase, ConstraintsInterface { private static Logger log = LoggerFactory.getLogger(SafetyPlugin.class); + static SafetyPlugin plugin = null; + + public static SafetyPlugin getPlugin() { + if (plugin == null) + plugin = new SafetyPlugin(); + return plugin; + } + @Override public String getFragmentClass() { - return SafetyFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorFragment.java deleted file mode 100644 index db1db95998..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorFragment.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; - -import android.support.v4.app.Fragment; - -/** - * Created by adrian on 17/11/16. - */ - -public class IobCobCalculatorFragment extends Fragment { - - private static IobCobCalculatorPlugin iobCobCalculatorPlugin = new IobCobCalculatorPlugin(); - - public static IobCobCalculatorPlugin getPlugin() { - return iobCobCalculatorPlugin; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 7b124ac762..c6a58edf30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -57,6 +57,14 @@ public class IobCobCalculatorPlugin implements PluginBase { private static Object dataLock = new Object(); + static IobCobCalculatorPlugin plugin = null; + + public static IobCobCalculatorPlugin getPlugin() { + if (plugin == null) + plugin = new IobCobCalculatorPlugin(); + return plugin; + } + @Override public int getType() { return GENERAL; @@ -64,7 +72,7 @@ public class IobCobCalculatorPlugin implements PluginBase { @Override public String getFragmentClass() { - return IobCobCalculatorFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationFragment.java deleted file mode 100644 index 78e7791c2d..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationFragment.java +++ /dev/null @@ -1,12 +0,0 @@ -package info.nightscout.androidaps.plugins.Persistentnotification; - -import android.support.v4.app.Fragment; - -/** - * Created by adrian on 23/12/16. - */ - -public class PersistentNotificationFragment extends Fragment { - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index e64e3375e2..68d1ed487a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -54,7 +54,7 @@ public class PersistentNotificationPlugin implements PluginBase { @Override public String getFragmentClass() { - return PersistentNotificationFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIFragment.java deleted file mode 100644 index f6221d627e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIFragment.java +++ /dev/null @@ -1,12 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpMDI; - - -import android.support.v4.app.Fragment; - -public class MDIFragment extends Fragment { - private static MDIPlugin mdiPlugin = new MDIPlugin(); - - public static MDIPlugin getPlugin() { - return mdiPlugin; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index b0c55ba036..b51a0bb66e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -12,11 +12,11 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.data.Profile; import info.nightscout.utils.DateUtil; /** @@ -30,6 +30,14 @@ public class MDIPlugin implements PluginBase, PumpInterface { PumpDescription pumpDescription = new PumpDescription(); + static MDIPlugin plugin = null; + + public static MDIPlugin getPlugin() { + if (plugin == null) + plugin = new MDIPlugin(); + return plugin; + } + public MDIPlugin() { pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.5d; @@ -42,7 +50,7 @@ public class MDIPlugin implements PluginBase, PumpInterface { @Override public String getFragmentClass() { - return MDIFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java deleted file mode 100644 index 63ab27deee..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.SourceGlimp; - - -import android.support.v4.app.Fragment; - -public class SourceGlimpFragment extends Fragment { - - private static SourceGlimpPlugin sourceGlimpPlugin = new SourceGlimpPlugin(); - - public static SourceGlimpPlugin getPlugin() { - return sourceGlimpPlugin; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java index 3c1248c4de..0f914feddc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java @@ -4,7 +4,6 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; /** * Created by mike on 05.08.2016. @@ -12,9 +11,17 @@ import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; public class SourceGlimpPlugin implements PluginBase, BgSourceInterface { boolean fragmentEnabled = false; + static SourceGlimpPlugin plugin = null; + + public static SourceGlimpPlugin getPlugin() { + if (plugin == null) + plugin = new SourceGlimpPlugin(); + return plugin; + } + @Override public String getFragmentClass() { - return SourceGlimpFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java deleted file mode 100644 index 28bfabf813..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.SourceMM640g; - - -import android.support.v4.app.Fragment; - -public class SourceMM640gFragment extends Fragment { - - private static SourceMM640gPlugin sourceMM640gPlugin = new SourceMM640gPlugin(); - - public static SourceMM640gPlugin getPlugin() { - return sourceMM640gPlugin; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java index df8111b5cd..fcef6a565b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java @@ -4,7 +4,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; +import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; /** * Created by mike on 05.08.2016. @@ -12,9 +12,17 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; public class SourceMM640gPlugin implements PluginBase, BgSourceInterface { boolean fragmentEnabled = false; + static SourceGlimpPlugin plugin = null; + + public static SourceGlimpPlugin getPlugin() { + if (plugin == null) + plugin = new SourceGlimpPlugin(); + return plugin; + } + @Override public String getFragmentClass() { - return SourceMM640gFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java deleted file mode 100644 index b2eddc09fc..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.SourceNSClient; - - -import android.support.v4.app.Fragment; - -public class SourceNSClientFragment extends Fragment { - - private static SourceNSClientPlugin sourceNSClientPlugin = new SourceNSClientPlugin(); - - public static SourceNSClientPlugin getPlugin() { - return sourceNSClientPlugin; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java index 62ae6b93da..a10d0d1d1e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java @@ -12,9 +12,17 @@ import info.nightscout.androidaps.interfaces.PluginBase; public class SourceNSClientPlugin implements PluginBase, BgSourceInterface { boolean fragmentEnabled = true; + static SourceNSClientPlugin plugin = null; + + public static SourceNSClientPlugin getPlugin() { + if (plugin == null) + plugin = new SourceNSClientPlugin(); + return plugin; + } + @Override public String getFragmentClass() { - return SourceNSClientFragment.class.getName(); + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java deleted file mode 100644 index c9be1298d2..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.nightscout.androidaps.plugins.SourceXdrip; - - -import android.support.v4.app.Fragment; - -public class SourceXdripFragment extends Fragment { - - private static SourceXdripPlugin sourceXdripPlugin = new SourceXdripPlugin(); - - public static SourceXdripPlugin getPlugin() { - return sourceXdripPlugin; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java index b32040a2e8..6d214dc028 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java @@ -4,16 +4,23 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; /** * Created by mike on 05.08.2016. */ public class SourceXdripPlugin implements PluginBase, BgSourceInterface { + static SourceXdripPlugin plugin = null; + + public static SourceXdripPlugin getPlugin() { + if (plugin == null) + plugin = new SourceXdripPlugin(); + return plugin; + } + @Override public String getFragmentClass() { - return SourceNSClientFragment.class.getName(); + return null; } private static boolean fragmentEnabled = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslineFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslineFragment.java deleted file mode 100644 index ba2cbc0783..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslineFragment.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.nightscout.androidaps.plugins.XDripStatusline; - -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import info.nightscout.androidaps.R; - -/** - * Created by adrian on 17/11/16. - */ - -public class StatuslineFragment extends Fragment { - - private static StatuslinePlugin statuslinePlugin; - - public static StatuslinePlugin getPlugin(Context ctx) { - - if (statuslinePlugin == null) { - statuslinePlugin = new StatuslinePlugin(ctx); - } - - return statuslinePlugin; - } - -} 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 1d3e427f1b..3f35d2af42 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 @@ -44,6 +44,17 @@ public class StatuslinePlugin implements PluginBase { private final Context ctx; SharedPreferences mPrefs; + private static StatuslinePlugin statuslinePlugin; + + public static StatuslinePlugin getPlugin(Context ctx) { + + if (statuslinePlugin == null) { + statuslinePlugin = new StatuslinePlugin(ctx); + } + + return statuslinePlugin; + } + StatuslinePlugin(Context ctx) { this.ctx = ctx; this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); @@ -56,7 +67,7 @@ public class StatuslinePlugin implements PluginBase { @Override public String getFragmentClass() { - return StatuslineFragment.class.getName(); + return null; } @Override From 70aaafa616f9cff20b04d8bcaaad7bec3eb98ac7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Jun 2017 15:04:22 +0200 Subject: [PATCH 06/21] copy old oref0 sensitivity code --- .../ConfigBuilder/ConfigBuilderPlugin.java | 4 + .../IobCobCalculator/AutosensData.java | 4 +- .../IobCobCalculatorPlugin.java | 121 +++------------- .../SensitivityMK/SensitivityMKPlugin.java | 117 +++++++++++++++- .../SensitivityOref0Plugin.java | 129 +++++++++++++++++- 5 files changed, 266 insertions(+), 109 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 f8c7e844f7..ef77072a40 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 @@ -215,6 +215,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return activePump; } + public static SensitivityInterface getActiveSensitivity() { + return activeSensitivity; + } + void logPluginStatus() { for (PluginBase p : pluginList) { log.debug(p.getName() + ":" + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 8f15653135..9b0aa3749a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -7,11 +7,11 @@ import java.util.Date; */ public class AutosensData { - long time = 0L; + public long time = 0L; public String pastSensitivity = ""; public double deviation = 0d; boolean nonCarbsDeviation = false; - boolean nonEqualDeviation = false; + public boolean nonEqualDeviation = false; double absorbed = 0d; public double carbsFromBolus = 0d; public double cob = 0; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index c6a58edf30..12bdad5674 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; @@ -55,9 +56,9 @@ public class IobCobCalculatorPlugin implements PluginBase { private static Handler sHandler = null; private static HandlerThread sHandlerThread = null; - private static Object dataLock = new Object(); + private static final Object dataLock = new Object(); - static IobCobCalculatorPlugin plugin = null; + private static IobCobCalculatorPlugin plugin = null; public static IobCobCalculatorPlugin getPlugin() { if (plugin == null) @@ -65,6 +66,14 @@ public class IobCobCalculatorPlugin implements PluginBase { return plugin; } + public static LongSparseArray getAutosensDataTable() { + return autosensDataTable; + } + + public static List getBucketedData() { + return bucketed_data; + } + @Override public int getType() { return GENERAL; @@ -120,7 +129,7 @@ public class IobCobCalculatorPlugin implements PluginBase { } - public IobCobCalculatorPlugin() { + IobCobCalculatorPlugin() { MainApp.bus().register(this); if (sHandlerThread == null) { sHandlerThread = new HandlerThread(IobCobCalculatorPlugin.class.getSimpleName()); @@ -198,14 +207,14 @@ public class IobCobCalculatorPlugin implements PluginBase { } } - public void createBucketedData() { + private void createBucketedData() { if (isAbout5minData()) createBucketedData5min(); else createBucketedDataRecalculated(); } - public void createBucketedDataRecalculated() { + private void createBucketedDataRecalculated() { synchronized (dataLock) { if (bgReadings == null || bgReadings.size() < 3) { bucketed_data = null; @@ -310,7 +319,7 @@ public class IobCobCalculatorPlugin implements PluginBase { //log.debug("Releasing createBucketedData"); } - public void calculateSensitivityData() { + private void calculateSensitivityData() { if (MainApp.getConfigBuilder() == null) return; // app still initializing //log.debug("Locking calculateSensitivityData"); @@ -523,106 +532,10 @@ public class IobCobCalculatorPlugin implements PluginBase { } } - public static AutosensResult detectSensitivity(long fromTime, long toTime) { - String age = SP.getString(R.string.key_age, ""); - int defaultHours = 24; - if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; - if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; - if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; - int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); - - long now = System.currentTimeMillis(); - - if (autosensDataTable == null || autosensDataTable.size() < 4) { - log.debug("No autosens data available"); - return new AutosensResult(); - } - - AutosensData current = getAutosensData(toTime); - if (current == null) { - log.debug("No autosens data available"); - return new AutosensResult(); - } - - - List deviationsArray = new ArrayList<>(); - String pastSensitivity = ""; - int index = 0; - while (index < autosensDataTable.size()) { - AutosensData autosensData = autosensDataTable.valueAt(index); - - if (autosensData.time < fromTime) { - index++; - continue; - } - - if (autosensData.time > toTime) { - index++; - continue; - } - - if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L) - deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d); - if (deviationsArray.size() > hoursForDetection * 60 / 5) - deviationsArray.remove(0); - - - pastSensitivity += autosensData.pastSensitivity; - int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); - if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { - pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; - } - index++; - } - - Double[] deviations = new Double[deviationsArray.size()]; - deviations = deviationsArray.toArray(deviations); - - Profile profile = MainApp.getConfigBuilder().getProfile(); - - double sens = profile.getIsf(); - - String ratioLimit = ""; - String sensResult = ""; - - log.debug("Records: " + index + " " + pastSensitivity); - Arrays.sort(deviations); - - double percentile = percentile(deviations, 0.50); - double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); - double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); - - if (percentile < 0) { // sensitive - sensResult = "Excess insulin sensitivity detected"; - } else if (percentile > 0) { // resistant - sensResult = "Excess insulin resistance detected"; - } else { - sensResult = "Sensitivity normal"; - } - - log.debug(sensResult); - - double rawRatio = ratio; - ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); - ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); - - if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; - log.debug(ratioLimit); - } - - log.error("Sensitivity to: " + new Date(toTime).toLocaleString() + " percentile: " + percentile); - - AutosensResult output = new AutosensResult(); - output.ratio = Round.roundTo(ratio, 0.01); - output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); - output.pastSensitivity = pastSensitivity; - output.ratioLimit = ratioLimit; - output.sensResult = sensResult; - return output; + private static AutosensResult detectSensitivity(long fromTime, long toTime) { + return ConfigBuilderPlugin.getActiveSensitivity().detectSensitivity(fromTime, toTime); } - public static JSONArray convertToJSONArray(IobTotal[] iobArray) { JSONArray array = new JSONArray(); for (int i = 0; i < iobArray.length; i++) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java index 210614714f..ac7f8ccb86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java @@ -1,16 +1,34 @@ package info.nightscout.androidaps.plugins.SensitivityMK; +import android.support.v4.util.LongSparseArray; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.SensitivityInterface; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.utils.Round; +import info.nightscout.utils.SP; +import info.nightscout.utils.SafeParse; /** * Created by mike on 24.06.2017. */ public class SensitivityMKPlugin implements PluginBase, SensitivityInterface{ + private static Logger log = LoggerFactory.getLogger(SensitivityMKPlugin.class); + private static boolean fragmentEnabled = true; private static boolean fragmentVisible = false; @@ -80,6 +98,103 @@ public class SensitivityMKPlugin implements PluginBase, SensitivityInterface{ @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { - return null; + LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getAutosensDataTable(); + + String age = SP.getString(R.string.key_age, ""); + int defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; + if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; + int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); + + long now = System.currentTimeMillis(); + + if (autosensDataTable == null || autosensDataTable.size() < 4) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); + if (current == null) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + + List deviationsArray = new ArrayList<>(); + String pastSensitivity = ""; + int index = 0; + while (index < autosensDataTable.size()) { + AutosensData autosensData = autosensDataTable.valueAt(index); + + if (autosensData.time < fromTime) { + index++; + continue; + } + + if (autosensData.time > toTime) { + index++; + continue; + } + + if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L) + deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d); + if (deviationsArray.size() > hoursForDetection * 60 / 5) + deviationsArray.remove(0); + + + pastSensitivity += autosensData.pastSensitivity; + int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); + if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { + pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; + } + index++; + } + + Double[] deviations = new Double[deviationsArray.size()]; + deviations = deviationsArray.toArray(deviations); + + Profile profile = MainApp.getConfigBuilder().getProfile(); + + double sens = profile.getIsf(); + + String ratioLimit = ""; + String sensResult = ""; + + log.debug("Records: " + index + " " + pastSensitivity); + Arrays.sort(deviations); + + double percentile = IobCobCalculatorPlugin.percentile(deviations, 0.50); + double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); + + if (percentile < 0) { // sensitive + sensResult = "Excess insulin sensitivity detected"; + } else if (percentile > 0) { // resistant + sensResult = "Excess insulin resistance detected"; + } else { + sensResult = "Sensitivity normal"; + } + + log.debug(sensResult); + + double rawRatio = ratio; + ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); + ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); + + if (ratio != rawRatio) { + ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + log.debug(ratioLimit); + } + + log.error("Sensitivity to: " + new Date(toTime).toLocaleString() + " percentile: " + percentile); + + AutosensResult output = new AutosensResult(); + output.ratio = Round.roundTo(ratio, 0.01); + output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); + output.pastSensitivity = pastSensitivity; + output.ratioLimit = ratioLimit; + output.sensResult = sensResult; + return output; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java index 672e878acb..5cf74be25d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java @@ -1,16 +1,33 @@ package info.nightscout.androidaps.plugins.SensitivityOref0; +import android.support.v4.util.LongSparseArray; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.SensitivityInterface; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.utils.Round; +import info.nightscout.utils.SP; +import info.nightscout.utils.SafeParse; /** * Created by mike on 24.06.2017. */ -public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface{ +public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface { + private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class); + private static boolean fragmentEnabled = true; private static boolean fragmentVisible = false; @@ -80,6 +97,114 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface{ @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { - return null; + LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getAutosensDataTable(); + + String age = SP.getString(R.string.key_age, ""); + int defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 24; + int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); + + long now = System.currentTimeMillis(); + + if (autosensDataTable == null || autosensDataTable.size() < 4) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + AutosensData current = IobCobCalculatorPlugin.getLastAutosensData(); + if (current == null) { + log.debug("No current autosens data available"); + return new AutosensResult(); + } + + + List deviationsArray = new ArrayList<>(); + String pastSensitivity = ""; + int index = 0; + while (index < autosensDataTable.size()) { + AutosensData autosensData = autosensDataTable.valueAt(index); + + if (autosensData.time < fromTime) { + index++; + continue; + } + + if (autosensData.time > toTime) { + index++; + continue; + } + + if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L) + deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d); + if (deviationsArray.size() > hoursForDetection * 60 / 5) + deviationsArray.remove(0); + + pastSensitivity += autosensData.pastSensitivity; + int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); + if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { + pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; + } + index++; + } + + Double[] deviations = new Double[deviationsArray.size()]; + deviations = deviationsArray.toArray(deviations); + + Profile profile = MainApp.getConfigBuilder().getProfile(); + + double sens = profile.getIsf(); + + double ratio = 1; + String ratioLimit = ""; + String sensResult = ""; + + log.debug("Records: " + index + " " + pastSensitivity); + Arrays.sort(deviations); + + for (double i = 0.9; i > 0.1; i = i - 0.02) { + if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.02)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) { + log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)"); + } + } + double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50); + double pResistant = IobCobCalculatorPlugin.percentile(deviations, 0.45); + + double basalOff = 0; + + if (pSensitive < 0) { // sensitive + basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + sensResult = "Excess insulin sensitivity detected"; + } else if (pResistant > 0) { // resistant + basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + sensResult = "Excess insulin resistance detected"; + } else { + sensResult = "Sensitivity normal"; + } + log.debug(sensResult); + ratio = 1 + (basalOff / profile.getMaxDailyBasal()); + + double rawRatio = ratio; + ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); + ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); + + if (ratio != rawRatio) { + ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + log.debug(ratioLimit); + } + + double newisf = Math.round(Profile.toMgdl(sens, profile.getUnits()) / ratio); + if (ratio != 1) { + log.debug("ISF adjusted from " + Profile.toMgdl(sens, profile.getUnits()) + " to " + newisf); + } + + AutosensResult output = new AutosensResult(); + output.ratio = Round.roundTo(ratio, 0.01); + output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); + output.pastSensitivity = pastSensitivity; + output.ratioLimit = ratioLimit; + output.sensResult = sensResult; + return output; } } From 129f813de2b9fbfa684f0fcfa359a590c57ffe56 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Jun 2017 15:11:30 +0200 Subject: [PATCH 07/21] reset cache on ConfigBuilderChange event --- .../IobCobCalculator/IobCobCalculatorPlugin.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 12bdad5674..3590407da7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; @@ -597,6 +598,21 @@ public class IobCobCalculatorPlugin implements PluginBase { } } + @Subscribe + public void onStatusEvent(EventConfigBuilderChange ev) { + synchronized (dataLock) { + log.debug("Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); + iobTable = new LongSparseArray<>(); + autosensDataTable = new LongSparseArray<>(); + } + sHandler.post(new Runnable() { + @Override + public void run() { + calculateSensitivityData(); + } + }); + } + // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated @Subscribe public void onNewHistoryData(EventNewHistoryData ev) { From ac98852f7921cde3622e2dc490300eedb07dee95 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Jun 2017 19:55:49 +0200 Subject: [PATCH 08/21] cut off carbs after 4h --- .../IobCobCalculator/AutosensData.java | 50 +++++++++++++++++++ .../IobCobCalculatorPlugin.java | 21 +++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 9b0aa3749a..fa36f265ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -1,17 +1,42 @@ package info.nightscout.androidaps.plugins.IobCobCalculator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; import java.util.Date; +import java.util.List; + +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.utils.SP; /** * Created by mike on 25.04.2017. */ public class AutosensData { + private static Logger log = LoggerFactory.getLogger(AutosensData.class); + + static class CarbsInPast { + long time = 0L; + double carbs = 0d; + double min5minCarbImpact = 0d; + double remaining = 0d; + + public CarbsInPast(Treatment t) { + time = t.date; + carbs = t.carbs; + remaining = t.carbs; + min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0); + } + } + public long time = 0L; public String pastSensitivity = ""; public double deviation = 0d; boolean nonCarbsDeviation = false; public boolean nonEqualDeviation = false; + List activeCarbsList = new ArrayList<>(); double absorbed = 0d; public double carbsFromBolus = 0d; public double cob = 0; @@ -28,4 +53,29 @@ public class AutosensData { return (int) ((System.currentTimeMillis() - time) / 1000 / 60); } + // remove carbs older than 4h + public void removeOldCarbs(long toTime) { + for (int i = 0; i < activeCarbsList.size(); i++) { + CarbsInPast c = activeCarbsList.get(i); + if (c.time + 4 * 60 * 60 * 1000L < toTime) { + activeCarbsList.remove(i--); + if (c.remaining > 0) + cob -= c.remaining; + log.debug("Removing carbs at "+ new Date(toTime).toLocaleString() + " + after 4h :" + new Date(c.time).toLocaleString()); + } + } + } + + public void substractAbosorbedCarbs() { + double ac = absorbed; + for (int i = 0; i < activeCarbsList.size() && ac > 0; i++) { + CarbsInPast c = activeCarbsList.get(i); + if (c.remaining > 0) { + double sub = Math.min(ac, c.remaining); + c.remaining -= sub; + ac -= sub; + } + } + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 3590407da7..c4b864a04f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -353,6 +353,10 @@ public class IobCobCalculatorPlugin implements PluginBase { AutosensData autosensData = new AutosensData(); autosensData.time = bgTime; + if (previous != null) + autosensData.activeCarbsList = new ArrayList<>(previous.activeCarbsList); + else + autosensData.activeCarbsList = new ArrayList<>(); //console.error(bgTime , bucketed_data[i].glucose); double bg; @@ -373,17 +377,28 @@ public class IobCobCalculatorPlugin implements PluginBase { List recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBackFromHistory(bgTime); for (int ir = 0; ir < recentTreatments.size(); ir++) { autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; + autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir))); } + // if we are absorbing carbs if (previous != null && previous.cob > 0) { + // calculate sum of min carb impact from all active treatments + double totalMinCarbsImpact = 0d; + for (int ii = 0; ii < autosensData.activeCarbsList.size(); ++ii) { + AutosensData.CarbsInPast c = autosensData.activeCarbsList.get(ii); + totalMinCarbsImpact += c.min5minCarbImpact; + } + // figure out how many carbs that represents - // but always assume at least 3mg/dL/5m (default) absorption - double ci = Math.max(deviation, SP.getDouble("openapsama_min_5m_carbimpact", 3.0)); + // but always assume at least 3mg/dL/5m (default) absorption per active treatment + double ci = Math.max(deviation, totalMinCarbsImpact); autosensData.absorbed = ci * profile.getIc(bgTime) / sens; // and add that to the running total carbsAbsorbed autosensData.cob = Math.max(previous.cob - autosensData.absorbed, 0d); + autosensData.substractAbosorbedCarbs(); } + autosensData.removeOldCarbs(bgTime); autosensData.cob += autosensData.carbsFromBolus; autosensData.deviation = deviation; autosensData.bgi = bgi; @@ -481,6 +496,7 @@ public class IobCobCalculatorPlugin implements PluginBase { return retval; } + @Nullable public static AutosensData getAutosensData(long time) { long now = System.currentTimeMillis(); if (time > now) @@ -499,6 +515,7 @@ public class IobCobCalculatorPlugin implements PluginBase { } } + @Nullable public static AutosensData getLastAutosensData() { if (autosensDataTable.size() < 1) return null; From 3f641f9c3030c479e8564699fc78f89be9d9fe3b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 25 Jun 2017 11:16:19 +0200 Subject: [PATCH 09/21] carbs absorption settings --- .../androidaps/PreferencesActivity.java | 3 ++ .../IobCobCalculator/AutosensData.java | 16 ++++++++- .../IobCobCalculatorPlugin.java | 3 +- .../plugins/Overview/OverviewFragment.java | 3 ++ .../main/java/info/nightscout/utils/SP.java | 30 ++++++++++++++-- app/src/main/res/values/strings.xml | 5 +++ app/src/main/res/xml/pref_absorption.xml | 35 +++++++++++++++++++ app/src/main/res/xml/pref_openapsama.xml | 15 -------- 8 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/xml/pref_absorption.xml diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 43bfb53c79..71c3a3981e 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugi import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.utils.LocaleHelper; @@ -105,6 +106,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) addPreferencesFromResource(R.xml.pref_openapsama); } + if (MainApp.getSpecificPlugin(SensitivityMKPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityMKPlugin.class).isEnabled(PluginBase.SENSITIVITY)) + addPreferencesFromResource(R.xml.pref_absorption); if (Config.ALLPREFERENCES) { addPreferencesFromResource(R.xml.pref_profile); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index fa36f265ff..7efcf083b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -7,7 +7,12 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin; import info.nightscout.utils.SP; /** @@ -27,7 +32,16 @@ public class AutosensData { time = t.date; carbs = t.carbs; remaining = t.carbs; - min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0); + if (MainApp.getSpecificPlugin(SensitivityMKPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityMKPlugin.class).isEnabled(PluginBase.SENSITIVITY)) { + double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d); + Profile profile = MainApp.getConfigBuilder().getProfile(t.date); + double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); + double ic = profile.getIc(t.date); + min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; + log.debug("Min 5m carbs impact for " + carbs + "g @" + new Date(t.date).toLocaleString() + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic); + } else { + min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index c4b864a04f..03c15602ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -599,7 +599,8 @@ public class IobCobCalculatorPlugin implements PluginBase { @Subscribe public void onStatusEvent(EventPreferenceChange ev) { if (ev.isChanged(R.string.key_openapsama_autosens_period) || - ev.isChanged(R.string.key_age) + ev.isChanged(R.string.key_age) || + ev.isChanged(R.string.key_absorption_maxtime) ) { synchronized (dataLock) { log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); 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 31aacc3d0a..a1b2771d04 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 @@ -305,11 +305,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50); iobGraph.getGridLabelRenderer().setNumVerticalLabels(5); + rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6); + bgGraph.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { rangeToDisplay += 6; rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay; + SP.putInt(R.string.key_rangetodisplay, rangeToDisplay); updateGUI("rangeChange"); return false; } diff --git a/app/src/main/java/info/nightscout/utils/SP.java b/app/src/main/java/info/nightscout/utils/SP.java index 4733c42d04..acb727d864 100644 --- a/app/src/main/java/info/nightscout/utils/SP.java +++ b/app/src/main/java/info/nightscout/utils/SP.java @@ -49,11 +49,19 @@ public class SP { } static public int getInt(int resourceID, Integer defaultValue) { - return SafeParse.stringToInt(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); + try { + return sharedPreferences.getInt(MainApp.sResources.getString(resourceID), defaultValue); + } catch (Exception e) { + return SafeParse.stringToInt(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); + } } static public int getInt(String key, Integer defaultValue) { - return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString())); + try { + return sharedPreferences.getInt(key, defaultValue); + } catch (Exception e) { + return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString())); + } } static public long getLong(int resourceID, Long defaultValue) { @@ -92,6 +100,24 @@ public class SP { editor.apply(); } + static public void putLong(int resourceID, long value) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putLong(MainApp.sResources.getString(resourceID), value); + editor.apply(); + } + + static public void putInt(String key, int value) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putInt(key, value); + editor.apply(); + } + + static public void putInt(int resourceID, int value) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putInt(MainApp.sResources.getString(resourceID), value); + editor.apply(); + } + static public void putString(int resourceID, String value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(MainApp.sResources.getString(resourceID), value); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bab136f254..bd92f721f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -657,4 +657,9 @@ SENS Sensitivity Oref0 Sensitivity MK + Absorption settings + absorption_maxtime + Meal max absorption time + Time in hours where is expected all carbs from meal will be absorbed + rangetodisplay diff --git a/app/src/main/res/xml/pref_absorption.xml b/app/src/main/res/xml/pref_absorption.xml new file mode 100644 index 0000000000..f86a21ec88 --- /dev/null +++ b/app/src/main/res/xml/pref_absorption.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/app/src/main/res/xml/pref_openapsama.xml b/app/src/main/res/xml/pref_openapsama.xml index b9576242dc..c861cac8be 100644 --- a/app/src/main/res/xml/pref_openapsama.xml +++ b/app/src/main/res/xml/pref_openapsama.xml @@ -10,21 +10,6 @@ android:key="openapsama_useautosens" android:title="@string/openapsama_useautosens" /> - - \ No newline at end of file From 311a14e457b51790604f65a01cc59e84e220b545 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 27 Jun 2017 13:59:37 +0200 Subject: [PATCH 10/21] typo --- .../androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java | 2 +- .../plugins/SensitivityOref0/SensitivityOref0Plugin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java index ac7f8ccb86..5506b2b4c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityMK/SensitivityMKPlugin.java @@ -42,7 +42,7 @@ public class SensitivityMKPlugin implements PluginBase, SensitivityInterface{ @Override public int getType() { - return INSULIN; + return SENSITIVITY; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java index 5cf74be25d..5ccc9107b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java @@ -41,7 +41,7 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface @Override public int getType() { - return INSULIN; + return SENSITIVITY; } @Override From f58f70bdca2e389467a7abaae87fd20fde939b96 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 28 Jun 2017 23:11:17 +0200 Subject: [PATCH 11/21] wizard tweaking --- .../plugins/Overview/Dialogs/WizardDialog.java | 4 +--- app/src/main/res/layout/openapsama_fragment.xml | 4 ++-- app/src/main/res/layout/openapsma_fragment.xml | 4 ++-- app/src/main/res/layout/overview_wizard_dialog.xml | 9 ++++++++- app/src/main/res/values-bg/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 12 files changed, 21 insertions(+), 16 deletions(-) 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 b50ea56d89..0a1b5417a8 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 @@ -21,7 +21,6 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; @@ -62,7 +61,6 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.OKDialog; -import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -521,7 +519,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) { String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.to2Decimal(calculatedTotalInsulin) + "U") : ""; String carbsText = calculatedCarbs > 0d ? (DecimalFormatter.to0Decimal(calculatedCarbs) + "g") : ""; - total.setText(getString(R.string.send) + " " + insulinText + " " + carbsText); + total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText); okButton.setVisibility(View.VISIBLE); } else { total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g"); diff --git a/app/src/main/res/layout/openapsama_fragment.xml b/app/src/main/res/layout/openapsama_fragment.xml index 83c9012022..f1f4f364ec 100644 --- a/app/src/main/res/layout/openapsama_fragment.xml +++ b/app/src/main/res/layout/openapsama_fragment.xml @@ -380,7 +380,7 @@ android:layout_weight="2" android:gravity="center_horizontal" android:paddingRight="5dp" - android:text="@string/openapsma_result_label" + android:text="@string/result" android:textColor="@android:color/white" android:textSize="14sp" /> @@ -451,7 +451,7 @@ android:layout_weight="2" android:gravity="end" android:paddingRight="5dp" - android:text="@string/openapsma_result_label" + android:text="@string/result" android:textSize="14sp" /> @@ -361,7 +361,7 @@ android:layout_weight="2" android:gravity="end" android:paddingRight="5dp" - android:text="@string/openapsma_result_label" + android:text="@string/result" android:textSize="14sp" /> + + Няма данни за помпа Профил Искане - Резултат + Резултат Старт сега Достъпно е ново предложение Преглед diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 2d50065133..ca4ead6453 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -111,7 +111,7 @@ Žádná pumpa Profil Požadavek - Výsledek + Výsledek Sputit teď Dostupné nové doporučení Přehled diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c9e986b3e1..cba1fcd6a1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -124,7 +124,7 @@ Extended Bolus Übersicht Neue Empfehlung verfügbar - Ergebnis + Ergebnis Anfrage Run now Keine Pumpe verfügbar diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 0e38aff05e..a85131b68b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -60,7 +60,7 @@ IOB datos Perfil Datos de comidas - Resultado + Resultado No hay disponibles datos de glucosa Sin perfil disponible No se dispone de bomba diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 767d9435ca..0ddc48199d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -299,7 +299,7 @@ Non mostrarlo più Abilita funzionalità superbolus nella procedura guidata. Non abilitare fino a quando non impari quello che realmente fa. PUÒ CAUSARE L\'INVERTIMENTO INSULINO SE USATO BLINDLY! Richiesta - Esito + Esito Avvia ora Apertura Loop Altro diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 874507c316..f2ecad0bbd 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -62,7 +62,7 @@ IOB 데이터 프로파일 식사 데이터 - 결과 + 결과 혈당 데이터 없음 프로파일 없음 No pump available diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8099777ba4..3cb46ac4ea 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -366,7 +366,7 @@ помпа недоступна профиль запрос - результат + результат выполнить сейчас отладка скрипта целевое значение для расчетов diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0da74e858f..80f77c562c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,7 +63,7 @@ IOB data Profile Meal data - Result + Result No glucose data available No profile available No pump available From a8338b2dd1b91c620d95aea9dd0ff4842a035fda Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 29 Jun 2017 01:37:58 +0200 Subject: [PATCH 12/21] careportal dialog number picker --- .../plugins/Actions/ActionsFragment.java | 4 +- .../Careportal/CareportalFragment.java | 40 +- .../Dialogs/NewNSTreatmentDialog.java | 278 +++---- .../plugins/Overview/OverviewFragment.java | 4 +- .../CircadianPercentageProfileFragment.java | 2 +- .../ProfileLocal/LocalProfileFragment.java | 2 +- .../ProfileSimple/SimpleProfileFragment.java | 2 +- .../careportal_newnstreatment_dialog.xml | 769 ++++-------------- .../layout/overview_calibration_dialog.xml | 54 +- .../res/layout/overview_wizard_dialog.xml | 1 - 10 files changed, 357 insertions(+), 799 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 6e0bf61add..bc2c0adb86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -169,14 +169,14 @@ public class ActionsFragment extends Fragment implements View.OnClickListener { NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); final OptionsToShow profileswitch = CareportalFragment.profileswitch; profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(manager, "NewNSTreatmentDialog"); break; case R.id.actions_temptarget: NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); final OptionsToShow temptarget = CareportalFragment.temptarget; temptarget.executeTempTarget = true; - newTTDialog.setOptions(temptarget); + newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget); newTTDialog.show(manager, "NewNSTreatmentDialog"); break; case R.id.actions_extendedbolus: 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 d9a7621a56..309ccecb6e 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 @@ -100,66 +100,66 @@ public class CareportalFragment extends Fragment implements View.OnClickListener NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); switch (id) { case R.id.careportal_bgcheck: - newDialog.setOptions(bgcheck); + newDialog.setOptions(bgcheck, R.string.careportal_bgcheck); break; case R.id.careportal_announcement: - newDialog.setOptions(announcement); + newDialog.setOptions(announcement, R.string.careportal_announcement); break; case R.id.careportal_cgmsensorinsert: - newDialog.setOptions(sensorchange); + newDialog.setOptions(sensorchange, R.string.careportal_cgmsensorinsert); break; case R.id.careportal_cgmsensorstart: - newDialog.setOptions(sensorstart); + newDialog.setOptions(sensorstart, R.string.careportal_cgmsensorstart); break; case R.id.careportal_combobolus: - newDialog.setOptions(combobolus); + newDialog.setOptions(combobolus, R.string.careportal_combobolus); break; case R.id.careportal_correctionbolus: - newDialog.setOptions(correctionbolus); + newDialog.setOptions(correctionbolus, R.string.careportal_correctionbolus); break; case R.id.careportal_carbscorrection: - newDialog.setOptions(carbcorrection); + newDialog.setOptions(carbcorrection, R.string.careportal_carbscorrection); break; case R.id.careportal_exercise: - newDialog.setOptions(exercise); + newDialog.setOptions(exercise, R.string.careportal_exercise); break; case R.id.careportal_insulincartridgechange: - newDialog.setOptions(insulinchange); + newDialog.setOptions(insulinchange, R.string.careportal_insulincartridgechange); break; case R.id.careportal_pumpbatterychange: - newDialog.setOptions(pumpbatterychange); + newDialog.setOptions(pumpbatterychange, R.string.careportal_pumpbatterychange); break; case R.id.careportal_mealbolus: - newDialog.setOptions(mealbolus); + newDialog.setOptions(mealbolus, R.string.careportal_mealbolus); break; case R.id.careportal_note: - newDialog.setOptions(note); + newDialog.setOptions(note, R.string.careportal_note); break; case R.id.careportal_profileswitch: profileswitch.executeProfileSwitch = false; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); break; case R.id.careportal_pumpsitechange: - newDialog.setOptions(sitechange); + newDialog.setOptions(sitechange, R.string.careportal_pumpsitechange); break; case R.id.careportal_question: - newDialog.setOptions(question); + newDialog.setOptions(question, R.string.careportal_question); break; case R.id.careportal_snackbolus: - newDialog.setOptions(snackbolus); + newDialog.setOptions(snackbolus, R.string.careportal_snackbolus); break; case R.id.careportal_tempbasalstart: - newDialog.setOptions(tempbasalstart); + newDialog.setOptions(tempbasalstart, R.string.careportal_tempbasalstart); break; case R.id.careportal_tempbasalend: - newDialog.setOptions(tempbasalend); + newDialog.setOptions(tempbasalend, R.string.careportal_tempbasalend); break; case R.id.careportal_openapsoffline: - newDialog.setOptions(openapsoffline); + newDialog.setOptions(openapsoffline, R.string.careportal_openapsoffline); break; case R.id.careportal_temporarytarget: temptarget.executeTempTarget = false; - newDialog.setOptions(temptarget); + newDialog.setOptions(temptarget, R.string.careportal_temporarytarget); break; default: newDialog = null; 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 f440311d18..ff1811b3ed 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 @@ -15,12 +15,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RadioButton; -import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; @@ -44,6 +42,8 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; @@ -52,12 +52,10 @@ import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; -import info.nightscout.utils.PlusMinusEditText; +import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.Translator; @@ -68,53 +66,44 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick private Activity context; private static OptionsToShow options; + private static String event; Profile profile; ProfileStore profileStore; String units; - RelativeLayout layoutBg; + TextView eventTypeText; + LinearLayout layoutBg; LinearLayout layoutBgSource; - RelativeLayout layoutInsulin; - RelativeLayout layoutCarbs; - RelativeLayout layoutSplit; - RelativeLayout layoutDuration; - RelativeLayout layoutPercent; - RelativeLayout layoutAbsolute; - RelativeLayout layoutCarbTime; - RelativeLayout layoutProfile; + LinearLayout layoutInsulin; + LinearLayout layoutCarbs; + LinearLayout layoutSplit; + LinearLayout layoutDuration; + LinearLayout layoutPercent; + LinearLayout layoutAbsolute; + LinearLayout layoutCarbTime; + LinearLayout layoutProfile; LinearLayout layoutTempTarget; - Button dateButton; - Button timeButton; - Button okButton; - Button cancelButton; + TextView dateButton; + TextView timeButton; TextView bgUnitsView; RadioButton meterRadioButton; RadioButton sensorRadioButton; RadioButton otherRadioButton; EditText notesEdit; - EditText bgInputEdit; - EditText insulinEdit; - EditText carbsEdit; - EditText percentEdit; - EditText absoluteEdit; - EditText durationeEdit; - EditText carbTimeEdit; - EditText splitEdit; Spinner profileSpinner; - EditText low; - EditText high; Spinner reasonSpinner; - PlusMinusEditText editBg; - PlusMinusEditText editCarbs; - PlusMinusEditText editInsulin; - PlusMinusEditText editSplit; - PlusMinusEditText editDuration; - PlusMinusEditText editPercent; - PlusMinusEditText editAbsolute; - PlusMinusEditText editCarbTime; + NumberPicker editBg; + NumberPicker editCarbs; + NumberPicker editInsulin; + NumberPicker editSplit; + NumberPicker editDuration; + NumberPicker editPercent; + NumberPicker editAbsolute; + NumberPicker editCarbTime; + NumberPicker editTemptarget; Date eventTime; @@ -122,8 +111,9 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick private static HandlerThread sHandlerThread; - public void setOptions(OptionsToShow options) { + public void setOptions(OptionsToShow options, int event) { this.options = options; + this.event = MainApp.sResources.getString(event); } public NewNSTreatmentDialog() { @@ -154,88 +144,44 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick setStyle(DialogFragment.STYLE_NORMAL, getTheme()); View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false); - layoutBg = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_bg_layout); + layoutBg = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bg_layout); layoutBgSource = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout); - layoutInsulin = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_insulin_layout); - layoutCarbs = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_carbs_layout); - layoutSplit = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_split_layout); - layoutDuration = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_duration_layout); - layoutPercent = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_percent_layout); - layoutAbsolute = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_absolute_layout); - layoutCarbTime = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout); - layoutProfile = (RelativeLayout) view.findViewById(R.id.careportal_newnstreatment_profile_layout); + layoutInsulin = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_insulin_layout); + layoutCarbs = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbs_layout); + layoutSplit = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_split_layout); + layoutDuration = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_duration_layout); + layoutPercent = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_percent_layout); + layoutAbsolute = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_absolute_layout); + layoutCarbTime = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout); + layoutProfile = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_profile_layout); layoutTempTarget = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout); + eventTypeText = (TextView) view.findViewById(R.id.careportal_newnstreatment_eventtype); + eventTypeText.setText(event); bgUnitsView = (TextView) view.findViewById(R.id.careportal_newnstreatment_bgunits); meterRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_meter); sensorRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_sensor); otherRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_other); profileSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_profile); - bgInputEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_bginput); - insulinEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_insulininput); - carbsEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_carbsinput); - percentEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_percentinput); - percentEdit.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, - int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, - int before, int count) { - layoutPercent.setVisibility(View.VISIBLE); - layoutAbsolute.setVisibility(View.GONE); - } - }); - absoluteEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_absoluteinput); - absoluteEdit.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, - int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, - int before, int count) { - layoutPercent.setVisibility(View.GONE); - layoutAbsolute.setVisibility(View.VISIBLE); - } - }); - durationeEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_durationinput); - carbTimeEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput); notesEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_notes); - splitEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_splitinput); reasonSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_temptarget_reason); - low = (EditText) view.findViewById(R.id.careportal_temptarget_low); - high = (EditText) view.findViewById(R.id.careportal_temptarget_high); eventTime = new Date(); - dateButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventdate); - timeButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventtime); + dateButton = (TextView) view.findViewById(R.id.careportal_newnstreatment_eventdate); + timeButton = (TextView) view.findViewById(R.id.careportal_newnstreatment_eventtime); dateButton.setText(DateUtil.dateString(eventTime)); timeButton.setText(DateUtil.timeString(eventTime)); dateButton.setOnClickListener(this); timeButton.setOnClickListener(this); - okButton = (Button) view.findViewById(R.id.ok); - okButton.setOnClickListener(this); - cancelButton = (Button) view.findViewById(R.id.cancel); - cancelButton.setOnClickListener(this); + view.findViewById(R.id.ok).setOnClickListener(this); + view.findViewById(R.id.cancel).setOnClickListener(this); // profile profile = MainApp.getConfigBuilder().getProfile(); - profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); + profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); ArrayList profileList; units = profile.getUnits(); profileList = profileStore.getProfileList(); @@ -260,25 +206,20 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick // bg bgUnitsView.setText(units); - // Set BG if not old -// BgReading lastBg = MainApp.getDbHelper().lastBg(); -// Double lastBgValue = 0d; -// if (lastBg != null) { -// lastBgValue = lastBg.valueToUnits(units); -// sensorRadioButton.setChecked(true); -// } else { -// meterRadioButton.setChecked(true); -// } - Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL); - if (profile == null) - editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false); - else if (profile.getUnits().equals(Constants.MMOL)) - editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false); - else - editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 1d, new DecimalFormat("0"), false); - bgInputEdit.addTextChangedListener(new TextWatcher() { - + editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput); + editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget); + if (profile == null) { + editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false); + editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false); + } else if (profile.getUnits().equals(Constants.MMOL)) { + editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false); + editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false); + } else { + editBg.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false); + editTemptarget.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false); + } + editBg.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } @@ -289,6 +230,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true); } }); + sensorRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -298,21 +240,63 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick }); Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit); - editCarbs = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbsinput, R.id.careportal_newnstreatment_carbs_plus, R.id.careportal_newnstreatment_carbs_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false); + editCarbs = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbsinput); + editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false); Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit); - editInsulin = new PlusMinusEditText(view, R.id.careportal_newnstreatment_insulininput, R.id.careportal_newnstreatment_insulin_plus, R.id.careportal_newnstreatment_insulin_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false); + editInsulin = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_insulininput); + editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false); - editSplit = new PlusMinusEditText(view, R.id.careportal_newnstreatment_splitinput, R.id.careportal_newnstreatment_split_plus, R.id.careportal_newnstreatment_split_minus, 100d, 0d, 100d, 5d, new DecimalFormat("0"), true); - editDuration = new PlusMinusEditText(view, R.id.careportal_newnstreatment_durationinput, R.id.careportal_newnstreatment_duration_plus, R.id.careportal_newnstreatment_duration_minus, 0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false); + editSplit = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_splitinput); + editSplit.setParams(100d, 0d, 100d, 5d, new DecimalFormat("0"), true); + editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput); + editDuration.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false); Integer maxPercent = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalPercentOnlyForCheckLimit); - editPercent = new PlusMinusEditText(view, R.id.careportal_newnstreatment_percentinput, R.id.careportal_newnstreatment_percent_plus, R.id.careportal_newnstreatment_percent_minus, 0d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true); + editPercent = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentinput); + editPercent.setParams(0d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true); + editPercent.addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, + int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, + int before, int count) { + layoutPercent.setVisibility(View.VISIBLE); + layoutAbsolute.setVisibility(View.GONE); + } + }); Double maxAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit); - editAbsolute = new PlusMinusEditText(view, R.id.careportal_newnstreatment_absoluteinput, R.id.careportal_newnstreatment_absolute_plus, R.id.careportal_newnstreatment_absolute_minus, 0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true); + editAbsolute = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_absoluteinput); + editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true); + editAbsolute.addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, + int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, + int before, int count) { + layoutPercent.setVisibility(View.GONE); + layoutAbsolute.setVisibility(View.VISIBLE); + } + }); + + editCarbTime = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput); + editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false); - editCarbTime = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbtimeinput, R.id.careportal_newnstreatment_carbtime_plus, R.id.careportal_newnstreatment_carbtime_minus, 0d, -60d, 60d, 5d, new DecimalFormat("0"), false); showOrHide(layoutBg, options.bg); showOrHide(layoutBgSource, options.bg); @@ -329,13 +313,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick return view; } - @Override - public void onResume() { - super.onResume(); - if (getDialog() != null) - getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - } - @Override public void onClick(View view) { Calendar calendar = Calendar.getInstance(); @@ -353,7 +330,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick dpd.show(context.getFragmentManager(), "Datepickerdialog"); break; case R.id.careportal_newnstreatment_eventtime: - android.text.format.DateFormat df = new android.text.format.DateFormat(); TimePickerDialog tpd = TimePickerDialog.newInstance( this, calendar.get(Calendar.HOUR_OF_DAY), @@ -417,8 +393,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick data.put("eventType", "Sensor Start"); break; case R.id.careportal_combobolus: - data.put("splitNow", SafeParse.stringToDouble(splitEdit.getText().toString())); - data.put("splitExt", 100 - SafeParse.stringToDouble(splitEdit.getText().toString())); + data.put("splitNow", SafeParse.stringToDouble(editSplit.getText())); + data.put("splitExt", 100 - SafeParse.stringToDouble(editSplit.getText())); data.put("eventType", CareportalEvent.COMBOBOLUS); break; case R.id.careportal_correctionbolus: @@ -468,42 +444,42 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick data.put("eventType", CareportalEvent.TEMPORARYTARGET); if (!reasonSpinner.getSelectedItem().toString().equals("")) data.put("reason", reasonSpinner.getSelectedItem().toString()); - if (SafeParse.stringToDouble(low.getText().toString()) != 0d) - data.put("targetBottom", SafeParse.stringToDouble(low.getText().toString())); - if (SafeParse.stringToDouble(high.getText().toString()) != 0d) - data.put("targetTop", SafeParse.stringToDouble(high.getText().toString())); + if (SafeParse.stringToDouble(editTemptarget.getText()) != 0d) { + data.put("targetBottom", SafeParse.stringToDouble(editTemptarget.getText())); + data.put("targetTop", SafeParse.stringToDouble(editTemptarget.getText())); + } allowZeroDuration = true; break; } - if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) { - data.put("glucose", SafeParse.stringToDouble(bgInputEdit.getText().toString())); + if (SafeParse.stringToDouble(editBg.getText()) != 0d) { + data.put("glucose", SafeParse.stringToDouble(editBg.getText())); if (meterRadioButton.isChecked()) data.put("glucoseType", "Finger"); if (sensorRadioButton.isChecked()) data.put("glucoseType", "Sensor"); if (otherRadioButton.isChecked()) data.put("glucoseType", "Manual"); } - if (SafeParse.stringToDouble(carbsEdit.getText().toString()) != 0d) - data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString())); - if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d) - data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString())); - if (allowZeroDuration || SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d) - data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString())); + if (SafeParse.stringToDouble(editCarbs.getText()) != 0d) + data.put("carbs", SafeParse.stringToDouble(editCarbs.getText())); + if (SafeParse.stringToDouble(editInsulin.getText()) != 0d) + data.put("insulin", SafeParse.stringToDouble(editInsulin.getText())); + if (allowZeroDuration || SafeParse.stringToDouble(editDuration.getText()) != 0d) + data.put("duration", SafeParse.stringToDouble(editDuration.getText())); if (layoutPercent.getVisibility() != View.GONE) - data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString())); + data.put("percent", SafeParse.stringToDouble(editPercent.getText())); if (layoutAbsolute.getVisibility() != View.GONE) - data.put("absolute", SafeParse.stringToDouble(absoluteEdit.getText().toString())); + data.put("absolute", SafeParse.stringToDouble(editAbsolute.getText())); if (options.profile && profileSpinner.getSelectedItem() != null) data.put("profile", profileSpinner.getSelectedItem().toString()); - if (SafeParse.stringToDouble(carbTimeEdit.getText().toString()) != 0d) - data.put("preBolus", SafeParse.stringToDouble(carbTimeEdit.getText().toString())); + if (SafeParse.stringToDouble(editCarbTime.getText()) != 0d) + data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText())); if (!notesEdit.getText().toString().equals("")) data.put("notes", notesEdit.getText().toString()); data.put("units", units); if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); if (options.eventType == R.id.careportal_combobolus) { - Double enteredInsulin = SafeParse.stringToDouble(insulinEdit.getText().toString()); + Double enteredInsulin = SafeParse.stringToDouble(editInsulin.getText()); data.put("enteredinsulin", enteredInsulin); - data.put("insulin", enteredInsulin * SafeParse.stringToDouble(splitEdit.getText().toString()) / 100); - data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(splitEdit.getText().toString())) / 100 / SafeParse.stringToDouble(durationeEdit.getText().toString()) * 60); + data.put("insulin", enteredInsulin * SafeParse.stringToDouble(editInsulin.getText()) / 100); + data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60); } } catch (JSONException e) { e.printStackTrace(); 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 04ce6f535a..5c7c0afe11 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 @@ -1038,7 +1038,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); final OptionsToShow profileswitch = CareportalFragment.profileswitch; profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); return true; } @@ -1053,7 +1053,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); final OptionsToShow temptarget = CareportalFragment.temptarget; temptarget.executeTempTarget = true; - newTTDialog.setOptions(temptarget); + newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget); newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java index 05cb4b5a40..112ead21fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java @@ -143,7 +143,7 @@ public class CircadianPercentageProfileFragment extends Fragment { NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); final OptionsToShow profileswitch = CareportalFragment.profileswitch; profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java index 4080d67ba8..97f32e232a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java @@ -104,7 +104,7 @@ public class LocalProfileFragment extends Fragment { NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); final OptionsToShow profileswitch = CareportalFragment.profileswitch; profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java index 3490e15873..7d1f829849 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java @@ -102,7 +102,7 @@ public class SimpleProfileFragment extends Fragment { NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); final OptionsToShow profileswitch = CareportalFragment.profileswitch; profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch); + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); } }); diff --git a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml index 59c43c3cad..5128262950 100644 --- a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml +++ b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml @@ -17,72 +17,49 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + + + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - + - + + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - - - - - - - - - + - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - + android:layout_centerInParent="true" + android:layout_gravity="center_vertical" /> - - - + - - - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> + android:minWidth="120dp" + android:orientation="vertical" + android:padding="10dp"> - + android:text="@string/target_range" + android:textAppearance="@android:style/TextAppearance.Material.Small" + android:textStyle="bold" /> - + android:layout_centerHorizontal="true" /> - + - + - + android:layout_height="wrap_content" + android:orientation="horizontal"> @@ -813,61 +417,44 @@ android:id="@+id/careportal_newnstreatment_notes" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerHorizontal="true" - android:width="200dp" /> + android:width="180dp" /> - + - - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - + android:layout_gravity="center_horizontal" + android:padding="10dp" + android:text="2017/05/05" /> -