From 8001796f4b17622911d8408c29f52e5bf76e1425 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 14 Feb 2017 15:41:30 +0100 Subject: [PATCH] virtual pump status upload optional --- .../nightscout/androidaps/PreferencesActivity.java | 5 +++++ .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 5 ++++- .../plugins/VirtualPump/VirtualPumpPlugin.java | 6 ++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_virtualpump.xml | 13 +++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/xml/pref_virtualpump.xml diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index ccd6fc3857..dc1c5eefdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin; import info.nightscout.utils.LocaleHelper; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -104,6 +105,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_danarprofile); } } + VirtualPumpPlugin virtualPumpPlugin = (VirtualPumpPlugin) MainApp.getSpecificPlugin(VirtualPumpPlugin.class); + if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) { + addPreferencesFromResource(R.xml.pref_virtualpump); + } if (Config.SMSCOMMUNICATORENABLED) addPreferencesFromResource(R.xml.pref_smscommunicator); addPreferencesFromResource(R.xml.pref_others); 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 95bc0df99d..a0b2a7b3b0 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 @@ -969,7 +969,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } if (activePump != null) { deviceStatus.device = "openaps://" + deviceID(); - deviceStatus.pump = getJSONStatus(); + JSONObject pumpstatus = getJSONStatus(); + if (pumpstatus != null) { + deviceStatus.pump = getJSONStatus(); + } deviceStatus.created_at = DateUtil.toISOString(new Date()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java index 33bceea49a..e90916122f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java @@ -1,6 +1,8 @@ package info.nightscout.androidaps.plugins.VirtualPump; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import org.json.JSONException; import org.json.JSONObject; @@ -401,6 +403,10 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public JSONObject getJSONStatus() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + if (!preferences.getBoolean("virtualpump_uploadstatus", false)) { + return null; + } JSONObject pump = new JSONObject(); JSONObject battery = new JSONObject(); JSONObject status = new JSONObject(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 30c834e5b5..08470fbbec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -501,4 +501,6 @@ Updating basal rates Disconnecting Executing + Virtual pump settings + Upload status to NS diff --git a/app/src/main/res/xml/pref_virtualpump.xml b/app/src/main/res/xml/pref_virtualpump.xml new file mode 100644 index 0000000000..23d39114b4 --- /dev/null +++ b/app/src/main/res/xml/pref_virtualpump.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file