From f85f04d33fbd1bfd2aa892384bfa17f858fe450f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 9 Nov 2016 17:48:44 +0100 Subject: [PATCH 1/3] NS upload only --- .../androidaps/Services/DataService.java | 97 ++++++++++--------- app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_nightscout.xml | 5 + 3 files changed, 59 insertions(+), 45 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 29b70eb1e9..615acc041c 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -70,26 +70,38 @@ public class DataService extends IntentService { if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { xDripEnabled = true; nsClientEnabled = false; - } - if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) { + } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) { xDripEnabled = false; nsClientEnabled = true; } + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + + boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + if (intent != null) { final String action = intent.getAction(); if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) { - if (xDripEnabled) + if (xDripEnabled) { handleNewDataFromXDrip(intent); - } else if (Intents.ACTION_NEW_PROFILE.equals(action) || - Intents.ACTION_NEW_TREATMENT.equals(action) || - Intents.ACTION_CHANGED_TREATMENT.equals(action) || - Intents.ACTION_REMOVED_TREATMENT.equals(action) || - Intents.ACTION_NEW_SGV.equals(action) || - Intents.ACTION_NEW_STATUS.equals(action) || - Intents.ACTION_NEW_DEVICESTATUS.equals(action) || - Intents.ACTION_NEW_CAL.equals(action) || - Intents.ACTION_NEW_MBG.equals(action) + } + } else if (Intents.ACTION_NEW_SGV.equals(action)) { + // always handle SGV if NS-Client is the source + if (nsClientEnabled) { + handleNewDataFromNSClient(intent); + } + // Objectives 0 + ObjectivesPlugin.bgIsAvailableInNS = true; + ObjectivesPlugin.saveProgress(); + } else if (!nsUploadOnly && + (Intents.ACTION_NEW_PROFILE.equals(action) || + Intents.ACTION_NEW_TREATMENT.equals(action) || + Intents.ACTION_CHANGED_TREATMENT.equals(action) || + Intents.ACTION_REMOVED_TREATMENT.equals(action) || + Intents.ACTION_NEW_STATUS.equals(action) || + Intents.ACTION_NEW_DEVICESTATUS.equals(action) || + Intents.ACTION_NEW_CAL.equals(action) || + Intents.ACTION_NEW_MBG.equals(action)) ) { handleNewDataFromNSClient(intent); } else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) { @@ -318,48 +330,43 @@ public class DataService extends IntentService { } if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) { - if (nsClientEnabled) { - try { - if (bundles.containsKey("sgv")) { - String sgvstring = bundles.getString("sgv"); - JSONObject sgvJson = new JSONObject(sgvstring); + try { + if (bundles.containsKey("sgv")) { + String sgvstring = bundles.getString("sgv"); + JSONObject sgvJson = new JSONObject(sgvstring); + NSSgv nsSgv = new NSSgv(sgvJson); + BgReading bgReading = new BgReading(nsSgv); + if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) { + if (Config.logIncommingData) + log.debug("Ignoring old BG: " + bgReading.toString()); + return; + } + MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); + if (Config.logIncommingData) + log.debug("ADD: Stored new BG: " + bgReading.toString()); + } + + if (bundles.containsKey("sgvs")) { + String sgvstring = bundles.getString("sgvs"); + JSONArray jsonArray = new JSONArray(sgvstring); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject sgvJson = jsonArray.getJSONObject(i); NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) { if (Config.logIncommingData) log.debug("Ignoring old BG: " + bgReading.toString()); - return; - } - MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); - if (Config.logIncommingData) - log.debug("ADD: Stored new BG: " + bgReading.toString()); - } - - if (bundles.containsKey("sgvs")) { - String sgvstring = bundles.getString("sgvs"); - JSONArray jsonArray = new JSONArray(sgvstring); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject sgvJson = jsonArray.getJSONObject(i); - NSSgv nsSgv = new NSSgv(sgvJson); - BgReading bgReading = new BgReading(nsSgv); - if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) { - if (Config.logIncommingData) - log.debug("Ignoring old BG: " + bgReading.toString()); - } else { - MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); - if (Config.logIncommingData) - log.debug("ADD: Stored new BG: " + bgReading.toString()); - } + } else { + MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); + if (Config.logIncommingData) + log.debug("ADD: Stored new BG: " + bgReading.toString()); } } - } catch (Exception e) { - e.printStackTrace(); } - MainApp.bus().post(new EventNewBG()); + } catch (Exception e) { + e.printStackTrace(); } - // Objectives 0 - ObjectivesPlugin.bgIsAvailableInNS = true; - ObjectivesPlugin.saveProgress(); + MainApp.bus().post(new EventNewBG()); } if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8efd2f7c93..55ee95ae70 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -336,5 +336,7 @@ Korean Actions AndroidAPS started + NS upload only (disabled sync) + NS upload only. Not effective on SGV unless a local source like xDrip is selected. diff --git a/app/src/main/res/xml/pref_nightscout.xml b/app/src/main/res/xml/pref_nightscout.xml index 4b76a35820..937ba32aa5 100644 --- a/app/src/main/res/xml/pref_nightscout.xml +++ b/app/src/main/res/xml/pref_nightscout.xml @@ -8,6 +8,11 @@ android:defaultValue="false" android:key="syncprofiletopump" android:title="@string/syncprofiletopump_title" /> + Date: Wed, 9 Nov 2016 18:31:15 +0100 Subject: [PATCH 2/3] Warn on "refresh treatments from NS" button in upload only mode. --- .../androidaps/Services/DataService.java | 1 - .../Treatments/TreatmentsFragment.java | 38 +++++++++++-------- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 24 insertions(+), 17 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 615acc041c..7d8edb7e7f 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -76,7 +76,6 @@ public class DataService extends IntentService { } SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); if (intent != null) { 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 8021b40a1b..0c36451573 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 @@ -3,7 +3,9 @@ package info.nightscout.androidaps.plugins.Treatments; import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; @@ -34,6 +36,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.ToastUtils; public class TreatmentsFragment extends Fragment implements View.OnClickListener, FragmentBase { private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class); @@ -148,21 +151,26 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener public void onClick(View view) { switch (view.getId()) { case R.id.treatments_reshreshfromnightscout: - AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); - builder.setTitle(this.getContext().getString(R.string.confirmation)); - builder.setMessage(this.getContext().getString(R.string.refreshfromnightscout)); - builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - MainApp.getDbHelper().resetTreatments(); - treatmentsPlugin.initializeData(); - updateGUI(); - Intent restartNSClient = new Intent(Intents.ACTION_RESTART); - MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); - } - }); - builder.setNegativeButton(this.getContext().getString(R.string.cancel), null); - builder.show(); - + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + if(nsUploadOnly){ + ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled)); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); + builder.setTitle(this.getContext().getString(R.string.confirmation)); + builder.setMessage(this.getContext().getString(R.string.refreshfromnightscout)); + builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + MainApp.getDbHelper().resetTreatments(); + treatmentsPlugin.initializeData(); + updateGUI(); + Intent restartNSClient = new Intent(Intents.ACTION_RESTART); + MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); + } + }); + builder.setNegativeButton(this.getContext().getString(R.string.cancel), null); + builder.show(); + } break; } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 55ee95ae70..26f125b4a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -338,5 +338,5 @@ AndroidAPS started NS upload only (disabled sync) NS upload only. Not effective on SGV unless a local source like xDrip is selected. - + Please deactivate "NS upload only" to use this feature. From a6ae92bb2f7d5b9efe63ffc66e7bba8a3a3a67ff Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 9 Nov 2016 21:01:21 +0100 Subject: [PATCH 3/3] Receive profile updates on uploadOnly when NS-Profiles are used --- .../info/nightscout/androidaps/Services/DataService.java | 6 ++++++ app/src/main/res/values/strings.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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 7d8edb7e7f..c38724d6bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync; +import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerPlugin; import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; @@ -75,6 +76,8 @@ public class DataService extends IntentService { nsClientEnabled = true; } + boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfileViewerPlugin.class); + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); @@ -92,6 +95,9 @@ public class DataService extends IntentService { // Objectives 0 ObjectivesPlugin.bgIsAvailableInNS = true; ObjectivesPlugin.saveProgress(); + } else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action)){ + // always handle Profili if NSProfile is enabled without looking at nsUploadOnly + handleNewDataFromNSClient(intent); } else if (!nsUploadOnly && (Intents.ACTION_NEW_PROFILE.equals(action) || Intents.ACTION_NEW_TREATMENT.equals(action) || diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 26f125b4a0..9e05a98082 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -337,6 +337,6 @@ Actions AndroidAPS started NS upload only (disabled sync) - NS upload only. Not effective on SGV unless a local source like xDrip is selected. + NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used. Please deactivate "NS upload only" to use this feature.