From 09fea02ed284696bd4e1139c2fbf7be468f3c0b1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 9 May 2017 16:24:53 +0200 Subject: [PATCH] Allow to disable NS upload while client is connected --- .../info/nightscout/androidaps/Services/DataService.java | 4 ++-- .../NSClientInternal/receivers/DBAccessReceiver.java | 6 ++++++ .../plugins/TempTargetRange/TempTargetRangeFragment.java | 4 ++-- .../androidaps/plugins/Treatments/TreatmentsFragment.java | 4 ++-- app/src/main/res/values/strings.xml | 8 ++++++-- app/src/main/res/xml/pref_advanced.xml | 7 ++++++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 0863c8e72d..ca811af251 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTarget import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; +import info.nightscout.utils.SP; public class DataService extends IntentService { @@ -98,8 +99,7 @@ public class DataService extends IntentService { boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class); - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (intent != null) { final String action = intent.getAction(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 44c6587fb1..91fca44d12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -14,10 +14,12 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.db.DbRequest; +import info.nightscout.utils.SP; public class DBAccessReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class); @@ -32,6 +34,10 @@ public class DBAccessReceiver extends BroadcastReceiver { if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) { return; } + if (SP.getBoolean(R.string.key_ns_noupload, false)) { + log.debug("Upload disabled. Message dropped"); + return; + } wakeLock.acquire(); try { Bundle bundles = intent.getExtras(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java index 13cae1aad0..9222a9a819 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java @@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; /** @@ -194,8 +195,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis public void onClick(View view) { switch (view.getId()) { case R.id.temptargetrange_refreshfromnightscout: - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (nsUploadOnly) { ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index 704d71e61b..0c4dcb26f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; public class TreatmentsFragment extends Fragment implements View.OnClickListener { @@ -192,8 +193,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener public void onClick(View view) { switch (view.getId()) { case R.id.treatments_reshreshfromnightscout: - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (nsUploadOnly) { ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); } else { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4370d8f297..027ae451b9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -508,12 +508,12 @@ Password for settings Unlock settings Approaching insulin daily limit - NSClient internal + NSClient NSCI URL: Autoscroll Restart - Internal NSClient + NSClient Nightscout URL Enter Nightscout URL NS API secret @@ -603,4 +603,8 @@ xDrip Status (watch) xDrip Statusline (watch) xds + No upload to NS + All data sent to NS are dropped. AAPS is connected to NS but no change in NS is done + ns_upload_only + ns_noupload diff --git a/app/src/main/res/xml/pref_advanced.xml b/app/src/main/res/xml/pref_advanced.xml index b385206d10..05898654fe 100644 --- a/app/src/main/res/xml/pref_advanced.xml +++ b/app/src/main/res/xml/pref_advanced.xml @@ -10,9 +10,14 @@ android:title="@string/nightscout"> +