diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java index 34b50e315f..aac7918bdc 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java @@ -15,6 +15,8 @@ public interface ConstraintsInterface { boolean isAMAModeEnabled(); + boolean isSMBModeEnabled(); + Double applyBasalConstraints(Double absoluteRate); Integer applyBasalConstraints(Integer percentRate); 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 a7cedc6381..03f0f60341 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 @@ -16,9 +16,9 @@ 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.Intervals; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; -import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileIntervals; import info.nightscout.androidaps.data.PumpEnactResult; @@ -38,8 +38,8 @@ 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; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.CommandQueue; @@ -482,8 +482,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr @Override public boolean isAMAModeEnabled() { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - boolean result = preferences.getBoolean("openapsama_useautosens", false); + boolean result = SP.getBoolean("openapsama_useautosens", false); ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { @@ -494,6 +493,19 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr return result; } + @Override + public boolean isSMBModeEnabled() { + boolean result = true; // TODO update for SMB // SP.getBoolean("openapsama_useautosens", false); + + ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); + for (PluginBase p : constraintsPlugins) { + ConstraintsInterface constrain = (ConstraintsInterface) p; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + result = result && constrain.isSMBModeEnabled(); + } + return result; + } + @Override public Double applyBasalConstraints(Double absoluteRate) { Double rateAfterConstrain = absoluteRate; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 61edb81a4c..1f0e6704c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -14,9 +14,14 @@ import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; +import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.SP; /** @@ -152,14 +157,35 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { RequirementResult requirementsMet(Integer objNum) { switch (objNum) { case 0: - return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS, + boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginBase.PUMP); + boolean vpUploadEnabled = SP.getBoolean("virtualpump_uploadstatus", false); + boolean vpUploadNeeded = !isVirtualPump || vpUploadEnabled; + + boolean apsEnabled = false; + APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); + if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) + apsEnabled = true; + + return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientInternalPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP) && apsEnabled && vpUploadNeeded, MainApp.sResources.getString(R.string.objectives_bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS) - + " " + MainApp.sResources.getString(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS)); + + " " + MainApp.sResources.getString(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientInternalPlugin.getPlugin().hasWritePermission()) + + (isVirtualPump ? " " + MainApp.sResources.getString(R.string.virtualpump_uploadstatus_title) + ": " + yesOrNo(vpUploadEnabled) : "") + + " " + MainApp.sResources.getString(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS) + + " " + MainApp.sResources.getString(R.string.loopenabled) + ": " + yesOrNo(LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP)) + + " " + MainApp.sResources.getString(R.string.apsselected) + ": " + yesOrNo(apsEnabled) + ); case 1: return new RequirementResult(manualEnacts >= manualEnactsNeeded, MainApp.sResources.getString(R.string.objectives_manualenacts) + ": " + manualEnacts + "/" + manualEnactsNeeded); case 2: return new RequirementResult(true, ""); + case 3: + boolean closedModeEnabled = SafetyPlugin.getPlugin().isClosedModeEnabled(); + return new RequirementResult(closedModeEnabled, MainApp.sResources.getString(R.string.closedmodeenabled) + ": " + yesOrNo(closedModeEnabled)); + case 4: + double maxIOB = MainApp.getConfigBuilder().applyMaxIOBConstraints(1000d); + boolean maxIobSet = maxIOB > 0; + return new RequirementResult(maxIobSet, MainApp.sResources.getString(R.string.maxiobset) + ": " + yesOrNo(maxIobSet)); default: return new RequirementResult(true, ""); } @@ -212,7 +238,13 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { MainApp.sResources.getString(R.string.objectives_6_objective), "", new Date(0), - 14, + 28, + new Date(0))); + objectives.add(new Objective(7, + MainApp.sResources.getString(R.string.objectives_7_objective), + "", + new Date(0), + 28, new Date(0))); } @@ -278,6 +310,11 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { return objectives.get(6).started.getTime() > 0; } + @Override + public boolean isSMBModeEnabled() { + return objectives.get(7).started.getTime() > 0; + } + @Override public Double applyMaxIOBConstraints(Double maxIob) { if (objectives.get(4).started.getTime() > 0 || objectives.get(2).accomplished.getTime() == 0) 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 ecb7aad47d..42f50d52dd 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 @@ -116,6 +116,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { return true; } + @Override + public boolean isSMBModeEnabled() { + return true; + } + @Override public Double applyBasalConstraints(Double absoluteRate) { Double origAbsoluteRate = absoluteRate; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java index cdca4e5b41..a51ea18cc7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java @@ -222,4 +222,8 @@ public class NSClientInternalPlugin implements PluginBase { public String url() { return NSClientService.nsURL; } + + public boolean hasWritePermission() { + return nsClientService.hasWriteAuth; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index affa668148..4ba660db66 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -785,6 +785,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C return true; } + @Override + public boolean isSMBModeEnabled() { + return true; + } + @SuppressWarnings("PointlessBooleanExpression") @Override public Double applyBasalConstraints(Double absoluteRate) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 0caab03cc8..f269aff112 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -787,6 +787,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf return true; } + @Override + public boolean isSMBModeEnabled() { + return true; + } + @SuppressWarnings("PointlessBooleanExpression") @Override public Double applyBasalConstraints(Double absoluteRate) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index fcbd89cfab..dceb7e66bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -289,6 +289,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, return true; } + @Override + public boolean isSMBModeEnabled() { + return true; + } + @Override public Double applyBasalConstraints(Double absoluteRate) { double origAbsoluteRate = absoluteRate; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index f074cb84c0..deb1594c28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -730,6 +730,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, return true; } + @Override + public boolean isSMBModeEnabled() { + return true; + } + @SuppressWarnings("PointlessBooleanExpression") @Override public Double applyBasalConstraints(Double absoluteRate) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 13d3f134f4..c543fe39bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -1,8 +1,6 @@ package info.nightscout.androidaps.plugins.PumpVirtual; -import android.content.SharedPreferences; import android.os.SystemClock; -import android.preference.PreferenceManager; import org.json.JSONException; import org.json.JSONObject; @@ -16,6 +14,7 @@ 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.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; @@ -24,7 +23,6 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; import info.nightscout.utils.DateUtil; @@ -65,6 +63,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { } private static VirtualPumpPlugin plugin = null; + public static VirtualPumpPlugin getPlugin() { loadFakingStatus(); if (plugin == null) @@ -401,8 +400,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public JSONObject getJSONStatus() { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - if (!preferences.getBoolean("virtualpump_uploadstatus", false)) { + if (!SP.getBoolean("virtualpump_uploadstatus", false)) { return null; } JSONObject pump = new JSONObject(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8085c09fd0..4a99a92ced 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -316,6 +316,7 @@ Adjust basals and ratios if needed, and then enable auto-sens 1 week successful daytime looping with regular carb entry Enabling additional features for daytime use, such as advanced meal assist + Enabling additional features for daytime use, such as SMB You reached allowed limit No profile selected Loop has been disabled @@ -802,6 +803,11 @@ Negative only COB calculation Temporary target calculation + Loop enabled + APS selected + NSClient has write permission + Closed mode enabled + Maximal IOB set properly Stopping bolus delivery Bolus delivery stopped Programming pump for bolusing