Merge pull request #59 from AdrianLxM/uploadOnly2

Upload only2
This commit is contained in:
Milos Kozak 2016-11-10 19:39:45 +01:00 committed by GitHub
commit 585d3fbb2c
4 changed files with 88 additions and 61 deletions

View file

@ -39,6 +39,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync; 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.Objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
@ -70,26 +71,42 @@ public class DataService extends IntentService {
if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
xDripEnabled = true; xDripEnabled = true;
nsClientEnabled = false; nsClientEnabled = false;
} } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
xDripEnabled = false; xDripEnabled = false;
nsClientEnabled = true; nsClientEnabled = true;
} }
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfileViewerPlugin.class);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
if (intent != null) { if (intent != null) {
final String action = intent.getAction(); final String action = intent.getAction();
if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) { if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) {
if (xDripEnabled) if (xDripEnabled) {
handleNewDataFromXDrip(intent); handleNewDataFromXDrip(intent);
} else if (Intents.ACTION_NEW_PROFILE.equals(action) || }
Intents.ACTION_NEW_TREATMENT.equals(action) || } else if (Intents.ACTION_NEW_SGV.equals(action)) {
Intents.ACTION_CHANGED_TREATMENT.equals(action) || // always handle SGV if NS-Client is the source
Intents.ACTION_REMOVED_TREATMENT.equals(action) || if (nsClientEnabled) {
Intents.ACTION_NEW_SGV.equals(action) || handleNewDataFromNSClient(intent);
Intents.ACTION_NEW_STATUS.equals(action) || }
Intents.ACTION_NEW_DEVICESTATUS.equals(action) || // Objectives 0
Intents.ACTION_NEW_CAL.equals(action) || ObjectivesPlugin.bgIsAvailableInNS = true;
Intents.ACTION_NEW_MBG.equals(action) 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) ||
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); handleNewDataFromNSClient(intent);
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) { } else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
@ -318,48 +335,43 @@ public class DataService extends IntentService {
} }
if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) { if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) {
if (nsClientEnabled) { try {
try { if (bundles.containsKey("sgv")) {
if (bundles.containsKey("sgv")) { String sgvstring = bundles.getString("sgv");
String sgvstring = bundles.getString("sgv"); JSONObject sgvJson = new JSONObject(sgvstring);
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); NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv); BgReading bgReading = new BgReading(nsSgv);
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) { if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
if (Config.logIncommingData) if (Config.logIncommingData)
log.debug("Ignoring old BG: " + bgReading.toString()); log.debug("Ignoring old BG: " + bgReading.toString());
return; } else {
} MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); if (Config.logIncommingData)
if (Config.logIncommingData) log.debug("ADD: Stored new BG: " + bgReading.toString());
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());
}
} }
} }
} catch (Exception e) {
e.printStackTrace();
} }
MainApp.bus().post(new EventNewBG()); } catch (Exception e) {
e.printStackTrace();
} }
// Objectives 0 MainApp.bus().post(new EventNewBG());
ObjectivesPlugin.bgIsAvailableInNS = true;
ObjectivesPlugin.saveProgress();
} }
if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) { if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) {

View file

@ -3,7 +3,9 @@ package info.nightscout.androidaps.plugins.Treatments;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView; 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.androidaps.interfaces.FragmentBase;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;
public class TreatmentsFragment extends Fragment implements View.OnClickListener, FragmentBase { public class TreatmentsFragment extends Fragment implements View.OnClickListener, FragmentBase {
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class); 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) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.treatments_reshreshfromnightscout: case R.id.treatments_reshreshfromnightscout:
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext());
builder.setTitle(this.getContext().getString(R.string.confirmation)); boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
builder.setMessage(this.getContext().getString(R.string.refreshfromnightscout)); if(nsUploadOnly){
builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled));
public void onClick(DialogInterface dialog, int id) { } else {
MainApp.getDbHelper().resetTreatments(); AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
treatmentsPlugin.initializeData(); builder.setTitle(this.getContext().getString(R.string.confirmation));
updateGUI(); builder.setMessage(this.getContext().getString(R.string.refreshfromnightscout));
Intent restartNSClient = new Intent(Intents.ACTION_RESTART); builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); public void onClick(DialogInterface dialog, int id) {
} MainApp.getDbHelper().resetTreatments();
}); treatmentsPlugin.initializeData();
builder.setNegativeButton(this.getContext().getString(R.string.cancel), null); updateGUI();
builder.show(); Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
}
});
builder.setNegativeButton(this.getContext().getString(R.string.cancel), null);
builder.show();
}
break; break;
} }
} }

View file

@ -336,5 +336,7 @@
<string name="ko_lang">Korean</string> <string name="ko_lang">Korean</string>
<string name="actions">Actions</string> <string name="actions">Actions</string>
<string name="androidaps_start">AndroidAPS started</string> <string name="androidaps_start">AndroidAPS started</string>
<string name="ns_upload_only">NS upload only (disabled sync)</string>
<string name="ns_upload_only_summary">NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used.</string>
<string name="ns_upload_only_enabled">Please deactivate "NS upload only" to use this feature.</string>
</resources> </resources>

View file

@ -8,6 +8,11 @@
android:defaultValue="false" android:defaultValue="false"
android:key="syncprofiletopump" android:key="syncprofiletopump"
android:title="@string/syncprofiletopump_title" /> android:title="@string/syncprofiletopump_title" />
<SwitchPreference
android:defaultValue="false"
android:key="ns_upload_only"
android:title="@string/ns_upload_only"
android:summary="@string/ns_upload_only_summary"/>
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="ns_sync_use_absolute" android:key="ns_sync_use_absolute"