Allow to disable NS upload while client is connected

This commit is contained in:
Milos Kozak 2017-05-09 16:24:53 +02:00
parent 8d3be5e958
commit 09fea02ed2
6 changed files with 24 additions and 9 deletions

View file

@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTarget
import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.utils.SP;
public class DataService extends IntentService { public class DataService extends IntentService {
@ -98,8 +99,7 @@ public class DataService extends IntentService {
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class); boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
if (intent != null) { if (intent != null) {
final String action = intent.getAction(); final String action = intent.getAction();

View file

@ -14,10 +14,12 @@ import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.utils.SP;
public class DBAccessReceiver extends BroadcastReceiver { public class DBAccessReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class); private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class);
@ -32,6 +34,10 @@ public class DBAccessReceiver extends BroadcastReceiver {
if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) { if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
return; return;
} }
if (SP.getBoolean(R.string.key_ns_noupload, false)) {
log.debug("Upload disabled. Message dropped");
return;
}
wakeLock.acquire(); wakeLock.acquire();
try { try {
Bundle bundles = intent.getExtras(); Bundle bundles = intent.getExtras();

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange; import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
/** /**
@ -194,8 +195,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.temptargetrange_refreshfromnightscout: case R.id.temptargetrange_refreshfromnightscout:
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
if (nsUploadOnly) { if (nsUploadOnly) {
ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled));
} else { } else {

View file

@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
public class TreatmentsFragment extends Fragment implements View.OnClickListener { 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) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.treatments_reshreshfromnightscout: case R.id.treatments_reshreshfromnightscout:
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
if (nsUploadOnly) { if (nsUploadOnly) {
ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled));
} else { } else {

View file

@ -508,12 +508,12 @@
<string name="settings_password">Password for settings</string> <string name="settings_password">Password for settings</string>
<string name="unlock_settings">Unlock settings</string> <string name="unlock_settings">Unlock settings</string>
<string name="approachingdailylimit">Approaching insulin daily limit</string> <string name="approachingdailylimit">Approaching insulin daily limit</string>
<string name="nsclientinternal">NSClient internal</string> <string name="nsclientinternal">NSClient</string>
<string name="nsclientinternal_shortname">NSCI</string> <string name="nsclientinternal_shortname">NSCI</string>
<string name="nsclientinternal_url">URL:</string> <string name="nsclientinternal_url">URL:</string>
<string name="nsclientinternal_autoscroll">Autoscroll</string> <string name="nsclientinternal_autoscroll">Autoscroll</string>
<string name="restart">Restart</string> <string name="restart">Restart</string>
<string name="nsclientinternal_title">Internal NSClient</string> <string name="nsclientinternal_title">NSClient</string>
<string name="nsclientinternal_url_title">Nightscout URL</string> <string name="nsclientinternal_url_title">Nightscout URL</string>
<string name="nsclientinternal_url_dialogmessage">Enter Nightscout URL</string> <string name="nsclientinternal_url_dialogmessage">Enter Nightscout URL</string>
<string name="nsclientinternal_secret_title">NS API secret</string> <string name="nsclientinternal_secret_title">NS API secret</string>
@ -603,4 +603,8 @@
<string name="xdripstatus_settings">xDrip Status (watch)</string> <string name="xdripstatus_settings">xDrip Status (watch)</string>
<string name="xdripstatus">xDrip Statusline (watch)</string> <string name="xdripstatus">xDrip Statusline (watch)</string>
<string name="xdripstatus_shortname">xds</string> <string name="xdripstatus_shortname">xds</string>
<string name="ns_noupload">No upload to NS</string>
<string name="ns_noupload_summary">All data sent to NS are dropped. AAPS is connected to NS but no change in NS is done</string>
<string name="key_ns_upload_only" translatable="false">ns_upload_only</string>
<string name="key_ns_noupload" translatable="false">ns_noupload</string>
</resources> </resources>

View file

@ -10,9 +10,14 @@
android:title="@string/nightscout"> android:title="@string/nightscout">
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="ns_upload_only" android:key="@string/key_ns_upload_only"
android:title="@string/ns_upload_only" android:title="@string/ns_upload_only"
android:summary="@string/ns_upload_only_summary"/> android:summary="@string/ns_upload_only_summary"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_ns_noupload"
android:title="@string/ns_noupload"
android:summary="@string/ns_noupload_summary"/>
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="ns_sync_use_absolute" android:key="ns_sync_use_absolute"