x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
+
+ log.debug("TREAT_REMOVE " + treatments.length() + " treatments " + x.size() + " receivers");
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/client/data/DbLogger.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java
similarity index 96%
rename from app/src/main/java/info/nightscout/client/data/DbLogger.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java
index 3695d5e735..70d8e9e336 100644
--- a/app/src/main/java/info/nightscout/client/data/DbLogger.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import android.content.Intent;
import android.content.pm.ResolveInfo;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbRequest.java
new file mode 100644
index 0000000000..ed7de35f49
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbRequest.java
@@ -0,0 +1,87 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
+
+import com.google.common.base.Charsets;
+import com.google.common.hash.Hashing;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created by mike on 27.02.2016.
+ *
+ * Allowed actions "dbAdd" || "dbUpdate" || "dbUpdateUnset" || "dbRemove"
+ */
+public class DbRequest {
+ public String action = null;
+ public String collection = null;
+ public JSONObject data = null;
+ public String _id = null;
+ public String nsClientID = null;
+
+ public DbRequest() {
+ }
+
+ // dbAdd
+ public DbRequest(String action, String collection, String nsClientID, JSONObject data) {
+ this.action = action;
+ this.collection = collection;
+ this.data = data;
+ this.nsClientID = nsClientID;
+ this._id = "";
+ }
+
+ // dbUpdate, dbUpdateUnset
+ public DbRequest(String action, String collection, String nsClientID, String _id, JSONObject data) {
+ this.action = action;
+ this.collection = collection;
+ this.data = data;
+ this.nsClientID = nsClientID;
+ this._id = _id;
+ }
+
+ // dbRemove
+ public DbRequest(String action, String collection, String nsClientID, String _id) {
+ this.action = action;
+ this.collection = collection;
+ this.data = new JSONObject();
+ this.nsClientID = nsClientID;
+ this._id = _id;
+ }
+
+ public String hash() {
+ return Hashing.sha1().hashString(action + collection + _id + data.toString(), Charsets.UTF_8).toString();
+ }
+
+ public JSONObject toJSON() {
+ JSONObject object = new JSONObject();
+ try {
+ object.put("action", action);
+ object.put("collection", collection);
+ object.put("data", data);
+ if (_id != null) object.put("_id", _id);
+ if (nsClientID != null) object.put("nsClientID", nsClientID);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return object;
+ }
+
+ public static DbRequest fromJSON(JSONObject jsonObject) {
+ DbRequest result = new DbRequest();
+ try {
+ if (jsonObject.has("action"))
+ result.action = jsonObject.getString("action");
+ if (jsonObject.has("collection"))
+ result.collection = jsonObject.getString("collection");
+ if (jsonObject.has("data"))
+ result.data = jsonObject.getJSONObject("data");
+ if (jsonObject.has("_id"))
+ result._id = jsonObject.getString("_id");
+ if (jsonObject.has("nsClientID"))
+ result.nsClientID = jsonObject.getString("nsClientID");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/client/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java
similarity index 67%
rename from app/src/main/java/info/nightscout/client/data/NSCal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java
index 5a78dbaa02..74b5f688d9 100644
--- a/app/src/main/java/info/nightscout/client/data/NSCal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java
@@ -1,9 +1,12 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class NSCal {
+ private static Logger log = LoggerFactory.getLogger(NSCal.class);
public long date;
public double slope;
public double intercept;
@@ -17,6 +20,7 @@ public class NSCal {
scale = json.getDouble("scale");
} catch (JSONException e) {
e.printStackTrace();
+ log.debug("Data: " + json.toString());
}
}
}
diff --git a/app/src/main/java/info/nightscout/client/data/NSProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java
similarity index 99%
rename from app/src/main/java/info/nightscout/client/data/NSProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java
index 2e732c8c9f..4d3df3068c 100644
--- a/app/src/main/java/info/nightscout/client/data/NSProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import com.crashlytics.android.Crashlytics;
diff --git a/app/src/main/java/info/nightscout/client/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java
similarity index 96%
rename from app/src/main/java/info/nightscout/client/data/NSSgv.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java
index 5ce9b35caa..c8666f4306 100644
--- a/app/src/main/java/info/nightscout/client/data/NSSgv.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/client/data/NSStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
similarity index 97%
rename from app/src/main/java/info/nightscout/client/data/NSStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
index f247907296..fe20e90b1d 100644
--- a/app/src/main/java/info/nightscout/client/data/NSStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/client/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java
similarity index 97%
rename from app/src/main/java/info/nightscout/client/data/NSTreatment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java
index f358b4e74d..7430caf600 100644
--- a/app/src/main/java/info/nightscout/client/data/NSTreatment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.data;
+package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java
new file mode 100644
index 0000000000..7f576fde7e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java
@@ -0,0 +1,30 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.events;
+
+import android.text.Html;
+import android.text.Spanned;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Created by mike on 15.02.2017.
+ */
+
+public class EventNSClientNewLog {
+ public Date date = new Date();
+ public String action;
+ public String logText;
+ public EventNSClientNewLog(String action, String logText) {
+ this.action = action;
+ this.logText = logText;
+ }
+
+ public Spanned toHtml() {
+ SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
+ Spanned line = Html.fromHtml(timeFormat.format(date) + " " + action + " " + logText + "
");
+ return line;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java
new file mode 100644
index 0000000000..9bf90be31b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java
@@ -0,0 +1,8 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.events;
+
+/**
+ * Created by mike on 15.02.2017.
+ */
+
+public class EventNSClientRestart {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java
new file mode 100644
index 0000000000..6a1c721535
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java
@@ -0,0 +1,16 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.events;
+
+/**
+ * Created by mike on 02.01.2016.
+ */
+public class EventNSClientStatus {
+ public String status = "";
+
+ public EventNSClientStatus(String status) {
+ this.status = status;
+ }
+
+ public EventNSClientStatus() {
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java
new file mode 100644
index 0000000000..8f00bd3424
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java
@@ -0,0 +1,8 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.events;
+
+/**
+ * Created by mike on 17.02.2017.
+ */
+
+public class EventNSClientUpdateGUI {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java
new file mode 100644
index 0000000000..dd5d3330ab
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java
@@ -0,0 +1,17 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
+
+public class AutoStartReceiver extends BroadcastReceiver {
+ public AutoStartReceiver() {
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ context.startService(new Intent(context, NSClientService.class));
+ }
+}
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
new file mode 100644
index 0000000000..5f715ad78e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java
@@ -0,0 +1,93 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.PowerManager;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
+import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.DbRequest;
+
+public class DBAccessReceiver extends BroadcastReceiver {
+ private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class);
+
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ "sendQueue");
+ NSClientInternalPlugin nsClientInternalPlugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
+ if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
+ return;
+ }
+ wakeLock.acquire();
+ try {
+ Bundle bundles = intent.getExtras();
+ if (bundles == null) return;
+ if (!bundles.containsKey("action")) return;
+
+ String collection = null;
+ String _id = null;
+ JSONObject data = null;
+ String action = bundles.getString("action");
+ try { collection = bundles.getString("collection"); } catch (Exception e) {}
+ try { _id = bundles.getString("_id"); } catch (Exception e) {}
+ try { data = new JSONObject(bundles.getString("data")); } catch (Exception e) {}
+
+ if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) {
+ log.debug("DBACCESS no data inside record");
+ return;
+ }
+
+ if (action.equals("dbRemove")) {
+ data = new JSONObject();
+ }
+ // mark by id
+ Long nsclientid = new Date().getTime();
+ try {
+ data.put("NSCLIENT_ID", nsclientid);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ if (!isAllowedCollection(collection)) {
+ log.debug("DBACCESS wrong collection specified");
+ return;
+ }
+
+ if (action.equals("dbRemove")) {
+ DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
+ UploadQueue.add(dbr);
+ } else {
+ DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
+ UploadQueue.add(dbr);
+ }
+
+ } finally {
+ wakeLock.release();
+ }
+
+ }
+
+ private boolean isAllowedCollection(String collection) {
+ // "treatments" || "entries" || "devicestatus" || "profile" || "food"
+ if (collection.equals("treatments")) return true;
+ if (collection.equals("entries")) return true;
+ if (collection.equals("devicestatus")) return true;
+ if (collection.equals("profile")) return true;
+ if (collection.equals("food")) return true;
+ return false;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java
new file mode 100644
index 0000000000..a38ca842f9
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java
@@ -0,0 +1,25 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.support.v4.content.WakefulBroadcastReceiver;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
+import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
+
+public class RestartReceiver extends WakefulBroadcastReceiver {
+ public RestartReceiver() {
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ startWakefulService(context, new Intent(context, NSClientService.class)
+ .setAction(intent.getAction())
+ .putExtras(intent));
+
+ MainApp.bus().post(new EventNSClientRestart());
+ completeWakefulIntent(intent);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java
new file mode 100644
index 0000000000..272959b21c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java
@@ -0,0 +1,674 @@
+package info.nightscout.androidaps.plugins.NSClientInternal.services;
+
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.preference.PreferenceManager;
+
+import com.google.common.base.Charsets;
+import com.google.common.hash.Hashing;
+import com.squareup.otto.Subscribe;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.events.EventAppExit;
+import info.nightscout.androidaps.events.EventConfigBuilderChange;
+import info.nightscout.androidaps.events.EventPreferenceChange;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
+import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
+import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
+import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck;
+import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAuthAck;
+import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSPingAck;
+import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSUpdateAck;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastStatus;
+import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.DbRequest;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSCal;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
+import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
+import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
+import info.nightscout.androidaps.plugins.Overview.Notification;
+import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
+import info.nightscout.utils.DateUtil;
+import info.nightscout.utils.SP;
+import io.socket.client.IO;
+import io.socket.client.Socket;
+import io.socket.emitter.Emitter;
+
+public class NSClientService extends Service {
+ private static Logger log = LoggerFactory.getLogger(ExecutionService.class);
+
+ static public PowerManager.WakeLock mWakeLock;
+ private IBinder mBinder = new NSClientService.LocalBinder();
+
+ static NSProfile nsProfile;
+
+ static public Handler handler;
+ static private HandlerThread handlerThread;
+
+ public static Socket mSocket;
+ public static boolean isConnected = false;
+ public static boolean hasWriteAuth = false;
+ private static Integer dataCounter = 0;
+
+
+ public static String nightscoutVersionName = "";
+ public static Integer nightscoutVersionCode = 0;
+
+ private boolean nsEnabled = false;
+ static public String nsURL = "";
+ private String nsAPISecret = "";
+ private String nsDevice = "";
+ private Integer nsHours = 24;
+
+ private final Integer timeToWaitForResponseInMs = 30000;
+ private boolean uploading = false;
+ public Date lastReception = new Date();
+
+ public long latestDateInReceivedData = 0;
+
+ private String nsAPIhashCode = "";
+
+ public static UploadQueue uploadQueue = new UploadQueue();
+
+ public NSClientService() {
+ registerBus();
+ if (handler == null) {
+ handlerThread = new HandlerThread(NSClientService.class.getSimpleName() + "Handler");
+ handlerThread.start();
+ handler = new Handler(handlerThread.getLooper());
+ }
+
+ PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
+ mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSClientService");
+ initialize();
+ }
+
+ public class LocalBinder extends Binder {
+ public NSClientService getServiceInstance() {
+ return NSClientService.this;
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+
+ return START_STICKY;
+ }
+
+ private void registerBus() {
+ try {
+ MainApp.bus().unregister(this);
+ } catch (RuntimeException x) {
+ // Ignore
+ }
+ MainApp.bus().register(this);
+ }
+
+ @Subscribe
+ public void onStatusEvent(EventAppExit event) {
+ if (Config.logFunctionCalls)
+ log.debug("EventAppExit received");
+
+ destroy();
+
+ stopSelf();
+ if (Config.logFunctionCalls)
+ log.debug("EventAppExit finished");
+ }
+
+ @Subscribe
+ public void onStatusEvent(EventPreferenceChange ev) {
+ if (ev.isChanged(R.string.key_nsclientinternal_url) ||
+ ev.isChanged(R.string.key_nsclientinternal_api_secret) ||
+ ev.isChanged(R.string.key_nsclientinternal_paused)
+ ) {
+ destroy();
+ initialize();
+ }
+ }
+
+ @Subscribe
+ public void onStatusEvent(EventConfigBuilderChange ev) {
+ if (nsEnabled != MainApp.getSpecificPlugin(NSClientInternalPlugin.class).isEnabled(PluginBase.GENERAL)) {
+ destroy();
+ initialize();
+ }
+ }
+
+ public static void setNsProfile(NSProfile profile) {
+ nsProfile = profile;
+ }
+
+ public static NSProfile getNsProfile() {
+ return nsProfile;
+ }
+
+ public void initialize() {
+ dataCounter = 0;
+
+ NSClientService.mWakeLock.acquire();
+
+ readPreferences();
+
+ if (!nsAPISecret.equals(""))
+ nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString();
+
+ MainApp.bus().post(new EventNSClientStatus("Initializing"));
+ if (((NSClientInternalPlugin)MainApp.getSpecificPlugin(NSClientInternalPlugin.class)).paused) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "paused"));
+ MainApp.bus().post(new EventNSClientStatus("Paused"));
+ } else if (!nsEnabled) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled"));
+ MainApp.bus().post(new EventNSClientStatus("Disabled"));
+ } else if (!nsURL.equals("")) {
+ try {
+ MainApp.bus().post(new EventNSClientStatus("Connecting ..."));
+ IO.Options opt = new IO.Options();
+ opt.forceNew = true;
+ opt.reconnection = true;
+ mSocket = IO.socket(nsURL, opt);
+ mSocket.on(Socket.EVENT_CONNECT, onConnect);
+ mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
+ mSocket.on(Socket.EVENT_PING, onPing);
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "do connect"));
+ mSocket.connect();
+ mSocket.on("dataUpdate", onDataUpdate);
+ } catch (URISyntaxException | RuntimeException e) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
+ MainApp.bus().post(new EventNSClientStatus("Wrong URL syntax"));
+ }
+ } else {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "No NS URL specified"));
+ MainApp.bus().post(new EventNSClientStatus("Not configured"));
+ }
+ NSClientService.mWakeLock.release();
+ }
+
+ private Emitter.Listener onConnect = new Emitter.Listener() {
+ @Override
+ public void call(Object... args) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "connect event. ID: " + mSocket.id()));
+ sendAuthMessage(new NSAuthAck());
+ }
+ };
+
+ private Emitter.Listener onDisconnect = new Emitter.Listener() {
+ @Override
+ public void call(Object... args) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
+ }
+ };
+
+ public void destroy() {
+ if (mSocket != null) {
+ MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy"));
+ isConnected = false;
+ hasWriteAuth = false;
+ mSocket.disconnect();
+ mSocket = null;
+ }
+ }
+
+
+ public void sendAuthMessage(NSAuthAck ack) {
+ JSONObject authMessage = new JSONObject();
+ try {
+ authMessage.put("client", "Android_" + nsDevice);
+ authMessage.put("history", nsHours);
+ authMessage.put("status", true); // receive status
+ authMessage.put("pingme", true); // send mi pings to keep alive
+ authMessage.put("from", latestDateInReceivedData); // send data newer than
+ authMessage.put("secret", nsAPIhashCode);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ return;
+ }
+ MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth"));
+ mSocket.emit("authorize", authMessage, ack);
+ }
+
+ @Subscribe
+ public void onStatusEvent(NSAuthAck ack) {
+ String connectionStatus = "Authenticated (";
+ if (ack.read) connectionStatus += "R";
+ if (ack.write) connectionStatus += "W";
+ if (ack.write_treatment) connectionStatus += "T";
+ connectionStatus += ')';
+ isConnected = true;
+ hasWriteAuth = ack.write && ack.write_treatment;
+ MainApp.bus().post(new EventNSClientStatus(connectionStatus));
+ MainApp.bus().post(new EventNSClientNewLog("AUTH", connectionStatus));
+ if (!ack.write) {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write permission not granted !!!!"));
+ }
+ if (!ack.write_treatment) {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
+ }
+ if (!hasWriteAuth) {
+ Notification noperm = new Notification(Notification.NSCLIENT_NO_WRITE_PERMISSION, MainApp.sResources.getString(R.string.nowritepermission), Notification.URGENT);
+ MainApp.bus().post(new EventNewNotification(noperm));
+ } else {
+ MainApp.bus().post(new EventDismissNotification(Notification.NSCLIENT_NO_WRITE_PERMISSION));
+ }
+ lastReception = new Date();
+ }
+
+ public void readPreferences() {
+ nsEnabled = MainApp.getSpecificPlugin(NSClientInternalPlugin.class).isEnabled(PluginBase.GENERAL);
+ nsURL = SP.getString(R.string.key_nsclientinternal_url, "");
+ nsAPISecret = SP.getString(R.string.key_nsclientinternal_api_secret, "");
+ nsDevice = SP.getString("careportal_enteredby", "");
+ }
+
+ private Emitter.Listener onPing = new Emitter.Listener() {
+ @Override
+ public void call(final Object... args) {
+ if (Config.detailedLog)
+ MainApp.bus().post(new EventNSClientNewLog("PING", "received"));
+ // send data if there is something waiting
+ resend("Ping received");
+ }
+ };
+
+ private Emitter.Listener onDataUpdate = new Emitter.Listener() {
+ @Override
+ public void call(final Object... args) {
+ lastReception = new Date();
+ NSClientService.handler.post(new Runnable() {
+ @Override
+ public void run() {
+ PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
+ PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ "onDataUpdate");
+ wakeLock.acquire();
+ try {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
+
+ JSONObject data = (JSONObject) args[0];
+ NSCal actualCal = new NSCal();
+ boolean broadcastProfile = false;
+ try {
+ // delta means only increment/changes are comming
+ boolean isDelta = data.has("delta");
+ boolean isFull = !isDelta;
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "Data packet #" + dataCounter++ + (isDelta ? " delta" : " full")));
+
+ if (data.has("profiles")) {
+ JSONArray profiles = (JSONArray) data.getJSONArray("profiles");
+ if (profiles.length() > 0) {
+ JSONObject profile = (JSONObject) profiles.get(profiles.length() - 1);
+ String activeProfile = NSClientService.getNsProfile() == null ? null : NSClientService.getNsProfile().getActiveProfile();
+ NSProfile nsProfile = new NSProfile(profile, activeProfile);
+ NSClientService.setNsProfile(nsProfile);
+ broadcastProfile = true;
+ MainApp.bus().post(new EventNSClientNewLog("PROFILE", "profile received"));
+ }
+ }
+
+ if (data.has("status")) {
+ JSONObject status = data.getJSONObject("status");
+ NSStatus nsStatus = new NSStatus(status);
+
+ if (!status.has("versionNum")) {
+ if (status.getInt("versionNum") < 900) {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
+ }
+ } else {
+ nightscoutVersionName = status.getString("version");
+ nightscoutVersionCode = status.getInt("versionNum");
+ }
+
+ BroadcastStatus bs = new BroadcastStatus();
+ bs.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta);
+
+ if (NSClientService.getNsProfile() != null) {
+ String oldActiveProfile = NSClientService.getNsProfile().getActiveProfile();
+ String receivedActiveProfile = nsStatus.getActiveProfile();
+ NSClientService.getNsProfile().setActiveProfile(receivedActiveProfile);
+ if (receivedActiveProfile != null) {
+ MainApp.bus().post(new EventNSClientNewLog("PROFILE", "status activeProfile received: " + receivedActiveProfile));
+ }
+ // Change possible nulls to ""
+ String oldP = oldActiveProfile == null ? "" : oldActiveProfile;
+ String newP = receivedActiveProfile == null ? "" : receivedActiveProfile;
+ if (!newP.equals(oldP)) {
+ broadcastProfile = true;
+ }
+ }
+ /* Other received data to 2016/02/10
+ {
+ status: 'ok'
+ , name: env.name
+ , version: env.version
+ , versionNum: versionNum (for ver 1.2.3 contains 10203)
+ , serverTime: new Date().toISOString()
+ , apiEnabled: apiEnabled
+ , careportalEnabled: apiEnabled && env.settings.enable.indexOf('careportal') > -1
+ , boluscalcEnabled: apiEnabled && env.settings.enable.indexOf('boluscalc') > -1
+ , head: env.head
+ , settings: env.settings
+ , extendedSettings: ctx.plugins && ctx.plugins.extendedClientSettings ? ctx.plugins.extendedClientSettings(env.extendedSettings) : {}
+ , activeProfile ..... calculated from treatments or missing
+ }
+ */
+ } else if (!isDelta) {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
+ }
+
+ // If new profile received or change detected broadcast it
+ if (broadcastProfile && nsProfile != null) {
+ BroadcastProfile bp = new BroadcastProfile();
+ bp.handleNewTreatment(nsProfile, MainApp.instance().getApplicationContext(), isDelta);
+ MainApp.bus().post(new EventNSClientNewLog("PROFILE", "broadcasting"));
+ }
+
+ if (data.has("treatments")) {
+ JSONArray treatments = (JSONArray) data.getJSONArray("treatments");
+ JSONArray removedTreatments = new JSONArray();
+ JSONArray updatedTreatments = new JSONArray();
+ JSONArray addedTreatments = new JSONArray();
+ BroadcastTreatment bt = new BroadcastTreatment();
+ if (treatments.length() > 0)
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + treatments.length() + " treatments"));
+ for (Integer index = 0; index < treatments.length(); index++) {
+ JSONObject jsonTreatment = treatments.getJSONObject(index);
+ NSTreatment treatment = new NSTreatment(jsonTreatment);
+
+ // remove from upload queue if Ack is failing
+ UploadQueue.removeID(jsonTreatment);
+ //Find latest date in treatment
+ if (treatment.getMills() != null && treatment.getMills() < new Date().getTime())
+ if (treatment.getMills() > latestDateInReceivedData)
+ latestDateInReceivedData = treatment.getMills();
+
+ if (treatment.getAction() == null) {
+ if (!isCurrent(treatment)) continue;
+ addedTreatments.put(jsonTreatment);
+ } else if (treatment.getAction().equals("update")) {
+ if (!isCurrent(treatment)) continue;
+ updatedTreatments.put(jsonTreatment);
+ } else if (treatment.getAction().equals("remove")) {
+ removedTreatments.put(jsonTreatment);
+ }
+ }
+ if (removedTreatments.length() > 0) {
+ bt.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ if (updatedTreatments.length() > 0) {
+ bt.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ if (addedTreatments.length() > 0) {
+ bt.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ }
+ if (data.has("devicestatus")) {
+ BroadcastDeviceStatus bds = new BroadcastDeviceStatus();
+ JSONArray devicestatuses = (JSONArray) data.getJSONArray("devicestatus");
+ if (devicestatuses.length() > 0) {
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + devicestatuses.length() + " devicestatuses"));
+ for (Integer index = 0; index < devicestatuses.length(); index++) {
+ JSONObject jsonStatus = devicestatuses.getJSONObject(index);
+ // remove from upload queue if Ack is failing
+ UploadQueue.removeID(jsonStatus);
+ }
+ // send only last record
+ bds.handleNewDeviceStatus(devicestatuses.getJSONObject(devicestatuses.length() - 1), MainApp.instance().getApplicationContext(), isDelta);
+ }
+ }
+ if (data.has("mbgs")) {
+ BroadcastMbgs bmbg = new BroadcastMbgs();
+ JSONArray mbgs = (JSONArray) data.getJSONArray("mbgs");
+ if (mbgs.length() > 0)
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + mbgs.length() + " mbgs"));
+ for (Integer index = 0; index < mbgs.length(); index++) {
+ JSONObject jsonMbg = mbgs.getJSONObject(index);
+ // remove from upload queue if Ack is failing
+ UploadQueue.removeID(jsonMbg);
+ }
+ bmbg.handleNewMbg(mbgs, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ if (data.has("cals")) {
+ BroadcastCals bc = new BroadcastCals();
+ JSONArray cals = (JSONArray) data.getJSONArray("cals");
+ if (cals.length() > 0)
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + cals.length() + " cals"));
+ // Retreive actual calibration
+ for (Integer index = 0; index < cals.length(); index++) {
+ if (index == 0) {
+ actualCal.set(cals.optJSONObject(index));
+ }
+ // remove from upload queue if Ack is failing
+ UploadQueue.removeID(cals.optJSONObject(index));
+ }
+ bc.handleNewCal(cals, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ if (data.has("sgvs")) {
+ BroadcastSgvs bs = new BroadcastSgvs();
+ String units = nsProfile != null ? nsProfile.getUnits() : "mg/dl";
+ JSONArray sgvs = (JSONArray) data.getJSONArray("sgvs");
+ if (sgvs.length() > 0)
+ MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs"));
+ for (Integer index = 0; index < sgvs.length(); index++) {
+ JSONObject jsonSgv = sgvs.getJSONObject(index);
+ // MainApp.bus().post(new EventNSClientNewLog("DATA", "svg " + sgvs.getJSONObject(index).toString());
+ NSSgv sgv = new NSSgv(jsonSgv);
+ // Handle new sgv here
+ // remove from upload queue if Ack is failing
+ UploadQueue.removeID(jsonSgv);
+ //Find latest date in sgv
+ if (sgv.getMills() != null && sgv.getMills() < new Date().getTime())
+ if (sgv.getMills() > latestDateInReceivedData)
+ latestDateInReceivedData = sgv.getMills();
+ }
+ bs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
+ }
+ MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ //MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
+ } finally {
+ wakeLock.release();
+ }
+ }
+
+ });
+ }
+ };
+
+ public void dbUpdate(DbRequest dbr, NSUpdateAck ack) {
+ try {
+ if (!isConnected || !hasWriteAuth) return;
+ JSONObject message = new JSONObject();
+ message.put("collection", dbr.collection);
+ message.put("_id", dbr._id);
+ message.put("data", dbr.data);
+ mSocket.emit("dbUpdate", message, ack);
+ MainApp.bus().post(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void dbUpdateUnset(DbRequest dbr, NSUpdateAck ack) {
+ try {
+ if (!isConnected || !hasWriteAuth) return;
+ JSONObject message = new JSONObject();
+ message.put("collection", dbr.collection);
+ message.put("_id", dbr._id);
+ message.put("data", dbr.data);
+ mSocket.emit("dbUpdateUnset", message, ack);
+ MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void dbRemove(DbRequest dbr, NSUpdateAck ack) {
+ try {
+ if (!isConnected || !hasWriteAuth) return;
+ JSONObject message = new JSONObject();
+ message.put("collection", dbr.collection);
+ message.put("_id", dbr._id);
+ mSocket.emit("dbRemove", message, ack);
+ MainApp.bus().post(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Subscribe
+ public void onStatusEvent(NSUpdateAck ack) {
+ if (ack.result) {
+ uploadQueue.removeID(ack.action, ack._id);
+ MainApp.bus().post(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked " + ack._id));
+ } else {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "DBUPDATE/DBREMOVE Unknown response"));
+ }
+ }
+
+ public void dbAdd(DbRequest dbr, NSAddAck ack) {
+ try {
+ if (!isConnected || !hasWriteAuth) return;
+ JSONObject message = new JSONObject();
+ message.put("collection", dbr.collection);
+ message.put("data", dbr.data);
+ mSocket.emit("dbAdd", message, ack);
+ MainApp.bus().post(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Subscribe
+ public void onStatusEvent(NSAddAck ack) {
+ if (ack.nsClientID != null) {
+ uploadQueue.removeID(ack.json);
+ MainApp.bus().post(new EventNSClientNewLog("DBADD", "Acked " + ack.nsClientID));
+ } else {
+ MainApp.bus().post(new EventNSClientNewLog("ERROR", "DBADD Unknown response"));
+ }
+ }
+
+ public void doPing() {
+ if (!isConnected || !hasWriteAuth) return;
+ MainApp.bus().post(new EventNSClientNewLog("PING", "Sending"));
+ uploading = true;
+ JSONObject message = new JSONObject();
+ try {
+ message.put("mills", new Date().getTime());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ NSPingAck ack = new NSPingAck();
+ mSocket.emit("nsping", message, ack);
+ synchronized (ack) {
+ try {
+ ack.wait(timeToWaitForResponseInMs);
+ } catch (InterruptedException e) {
+ }
+ }
+ if (ack.received) {
+ String connectionStatus = "Pong received";
+ if (ack.auth_received) {
+ connectionStatus += ": ";
+ if (ack.read) connectionStatus += "R";
+ if (ack.write) connectionStatus += "W";
+ if (ack.write_treatment) connectionStatus += "T";
+ }
+ if (!ack.read) sendAuthMessage(new NSAuthAck());
+ MainApp.bus().post(new EventNSClientNewLog("AUTH ", connectionStatus));
+ } else {
+ MainApp.bus().post(new EventNSClientNewLog("PING", "Ping lost"));
+ }
+ uploading = false;
+ }
+
+ private boolean isCurrent(NSTreatment treatment) {
+ long now = (new Date()).getTime();
+ long minPast = now - nsHours * 60L * 60 * 1000;
+ if (treatment.getMills() == null) {
+ log.debug("treatment.getMills() == null " + treatment.getData().toString());
+ return false;
+ }
+ if (treatment.getMills() > minPast) return true;
+ return false;
+ }
+
+ public void resend(final String reason) {
+ if (UploadQueue.queue.size() == 0)
+ return;
+
+ if (!isConnected || !hasWriteAuth) return;
+
+ MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
+
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ Logger log = LoggerFactory.getLogger(UploadQueue.class);
+ Iterator> iter = UploadQueue.queue.entrySet().iterator();
+
+ if (mSocket == null || !mSocket.connected()) return;
+
+ while (iter.hasNext()) {
+ DbRequest dbr = iter.next().getValue();
+ if (dbr.action.equals("dbAdd")) {
+ NSAddAck addAck = new NSAddAck();
+ dbAdd(dbr, addAck);
+ } else if (dbr.action.equals("dbRemove")) {
+ NSUpdateAck removeAck = new NSUpdateAck(dbr.action, dbr._id);
+ dbRemove(dbr, removeAck);
+ } else if (dbr.action.equals("dbUpdate")) {
+ NSUpdateAck updateAck = new NSUpdateAck(dbr.action, dbr._id);
+ dbUpdate(dbr, updateAck);
+ } else if (dbr.action.equals("dbUpdateUnset")) {
+ NSUpdateAck updateUnsetAck = new NSUpdateAck(dbr.action, dbr._id);
+ dbUpdateUnset(dbr, updateUnsetAck);
+ }
+ }
+ MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
+ }
+ });
+ }
+
+ public void restart() {
+ destroy();
+ initialize();
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfile/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfile/NSProfilePlugin.java
index 5f5ed9ca1d..3c19b5a5c4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfile/NSProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfile/NSProfilePlugin.java
@@ -19,8 +19,9 @@ import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.NSProfile.events.EventNSProfileUpdateGUI;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.utils.SP;
/**
* Created by mike on 05.08.2016.
@@ -110,9 +111,8 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
private void loadNSProfile() {
if (Config.logPrefsChange)
log.debug("Loading stored profile");
- SharedPreferences store = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- String activeProfile = store.getString("activeProfile", null);
- String profileString = store.getString("profile", null);
+ String activeProfile = SP.getString("activeProfile", null);
+ String profileString = SP.getString("profile", null);
if (profileString != null) {
if (Config.logPrefsChange) {
log.debug("Loaded profile: " + profileString);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java
index 030878b6e9..5d33fdae5e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java
@@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
/**
@@ -211,20 +212,19 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
}
void loadProgress() {
- SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
for (int num = 0; num < objectives.size(); num++) {
Objective o = objectives.get(num);
try {
- o.started = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "started", "0")));
- o.accomplished = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "accomplished", "0")));
+ o.started = new Date(SP.getLong("Objectives" + num + "started", 0L));
+ o.accomplished = new Date(SP.getLong("Objectives" + num + "accomplished", 0L));
} catch (Exception e) {
e.printStackTrace();
}
}
- bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false);
- pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false);
+ bgIsAvailableInNS = SP.getBoolean("Objectives" + "bgIsAvailableInNS", false);
+ pumpStatusIsAvailableInNS = SP.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false);
try {
- manualEnacts = SafeParse.stringToInt(settings.getString("Objectives" + "manualEnacts", "0"));
+ manualEnacts = SP.getInt("Objectives" + "manualEnacts", 0);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/Autosens.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/Autosens.java
index eb449b96c8..44c3970ac5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/Autosens.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/Autosens.java
@@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.OpenAPSAMA;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -11,12 +8,12 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.Round;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
@@ -24,7 +21,6 @@ public class Autosens {
private static Logger log = LoggerFactory.getLogger(Autosens.class);
public static AutosensResult detectSensitivityandCarbAbsorption(List glucose_data, Long mealTime) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
//console.error(mealTime);
@@ -132,7 +128,7 @@ public class Autosens {
if (mealTime != null && bgTime > mealTime) {
// figure out how many carbs that represents
// but always assume at least 3mg/dL/5m (default) absorption
- double ci = Math.max(deviation, SafeParse.stringToDouble(SP.getString("openapsama_min_5m_carbimpact", "3.0")));
+ double ci = Math.max(deviation, SP.getDouble("openapsama_min_5m_carbimpact", 3.0));
double absorbed = ci * profile.getIc(secondsFromMidnight) / sens;
// and add that to the running total carbsAbsorbed
carbsAbsorbed += absorbed;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
index aa6c0ae36d..f03a892cae 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
@@ -16,17 +16,15 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import info.nightscout.androidaps.Config;
-import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.data.IobTotal;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
public class DetermineBasalAdapterAMAJS {
@@ -209,7 +207,6 @@ public class DetermineBasalAdapterAMAJS {
double min_5m_carbimpact) {
String units = profile.getUnits();
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
mProfile = new V8Object(mV8rt);
mProfile.add("max_iob", maxIob);
@@ -222,13 +219,13 @@ public class DetermineBasalAdapterAMAJS {
mProfile.add("target_bg", targetBg);
mProfile.add("carb_ratio", profile.getIc(profile.secondsFromMidnight()));
mProfile.add("sens", NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()).doubleValue(), units));
- mProfile.add("max_daily_safety_multiplier", SafeParse.stringToInt(preferences.getString("openapsama_max_daily_safety_multiplier", "3")));
- mProfile.add("current_basal_safety_multiplier", SafeParse.stringToInt(preferences.getString("openapsama_current_basal_safety_multiplier", "4")));
+ mProfile.add("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
+ mProfile.add("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
mProfile.add("skip_neutral_temps", true);
mProfile.add("current_basal", pump.getBaseBasalRate());
mProfile.add("temptargetSet", tempTargetSet);
- mProfile.add("autosens_adjust_targets", preferences.getBoolean("openapsama_autosens_adjusttargets", true));
- mProfile.add("min_5m_carbimpact", SafeParse.stringToDouble(preferences.getString("openapsama_min_5m_carbimpact", "3.0")));
+ mProfile.add("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
+ mProfile.add("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
mV8rt.add(PARAM_profile, mProfile);
mCurrentTemp = new V8Object(mV8rt);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java
index 49d5b760b9..2cbffae52a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java
@@ -22,17 +22,17 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
@@ -156,12 +156,11 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
return;
}
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String units = profile.getUnits();
- String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
- String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
- String targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
+ Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
+ Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
+ Double targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
if (!units.equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
@@ -170,11 +169,11 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
Date now = new Date();
- double maxIob = SafeParse.stringToDouble(SP.getString("openapsma_max_iob", "1.5"));
- double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
- double minBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_min_bg", minBgDefault)), units);
- double maxBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_max_bg", maxBgDefault)), units);
- double targetBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_target_bg", targetBgDefault)), units);
+ double maxIob = SP.getDouble("openapsma_max_iob", 1.5d);
+ double maxBasal = SP.getDouble("openapsma_max_basal", 1d);
+ double minBg = NSProfile.toMgdl(SP.getDouble("openapsma_min_bg", minBgDefault), units);
+ double maxBg = NSProfile.toMgdl(SP.getDouble("openapsma_max_bg", maxBgDefault), units);
+ double targetBg = NSProfile.toMgdl(SP.getDouble("openapsma_target_bg", targetBgDefault), units);
minBg = Round.roundTo(minBg, 0.1d);
maxBg = Round.roundTo(maxBg, 0.1d);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
index 75c68cd5cc..75f87021c5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
@@ -18,7 +18,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
public class DetermineBasalAdapterMAJS {
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java
index a3d5c3c508..c4b8f3e34a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java
@@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.OpenAPSMA;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,15 +22,15 @@ import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
-import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.checkOnlyHardLimits;
import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.verifyHardLimits;
@@ -157,12 +154,11 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
return;
}
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String units = profile.getUnits();
- String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
- String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
- String targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
+ Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
+ Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
+ Double targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
if (!units.equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
@@ -171,11 +167,11 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
Date now = new Date();
- double maxIob = SafeParse.stringToDouble(SP.getString("openapsma_max_iob", "1.5"));
+ double maxIob = SP.getDouble("openapsma_max_iob", 1.5d);
double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
- double minBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_min_bg", minBgDefault)), units);
- double maxBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_max_bg", maxBgDefault)), units);
- double targetBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("openapsma_target_bg", targetBgDefault)), units);
+ double minBg = NSProfile.toMgdl(SP.getDouble("openapsma_min_bg", minBgDefault), units);
+ double maxBg = NSProfile.toMgdl(SP.getDouble("openapsma_max_bg", maxBgDefault), units);
+ double targetBg = NSProfile.toMgdl(SP.getDouble("openapsma_target_bg", targetBgDefault), units);
minBg = Round.roundTo(minBg, 0.1d);
maxBg = Round.roundTo(maxBg, 0.1d);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java
index dfedda106e..a5d45128be 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java
@@ -18,10 +18,10 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
-import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
public class BolusProgressDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(BolusProgressDialog.class);
@@ -46,7 +46,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
bolusEnded = false;
}
- public void setHelperActivity(BolusProgressHelperActivity activity){
+ public void setHelperActivity(BolusProgressHelperActivity activity) {
this.helperActivity = activity;
}
@@ -77,9 +77,9 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
}
@Override
- public void dismiss(){
+ public void dismiss() {
super.dismiss();
- if (helperActivity!= null){
+ if (helperActivity != null) {
helperActivity.finish();
}
}
@@ -128,7 +128,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
}
@Subscribe
- public void onStatusEvent(final EventDanaRConnectionStatus c) {
+ public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity();
if (activity != null) {
@@ -136,14 +136,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
new Runnable() {
@Override
public void run() {
- if (c.sStatus == c.CONNECTING) {
- statusView.setText(String.format(MainApp.sResources.getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
- } else if (c.sStatus == c.CONNECTED) {
- statusView.setText(MainApp.sResources.getString(R.string.connected));
- } else {
- statusView.setText(MainApp.sResources.getString(R.string.disconnected));
- if (started) scheduleDismiss();
- }
+ statusView.setText(c.textStatus());
}
}
);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java
index 9e06bbb600..0c2b9068bf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java
@@ -21,7 +21,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.XdripCalibrations;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
index 890c393edc..2fc8764a9d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
@@ -43,7 +43,7 @@ import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.data.IobTotal;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
index 5d83a76cc7..0508917312 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
@@ -23,6 +23,7 @@ public class Notification {
public static final int OLD_NSCLIENT = 8;
public static final int INVALID_PHONE_NUMBER = 9;
public static final int APPROACHING_DAILY_LIMIT = 10;
+ public static final int NSCLIENT_NO_WRITE_PERMISSION = 10;
public int id;
public Date date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
index 61f4279a51..ac9035b7fd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
@@ -63,6 +63,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
+import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
@@ -71,7 +72,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
@@ -87,19 +87,18 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLa
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.utils.SP;
public class OverviewFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
private static OverviewPlugin overviewPlugin = new OverviewPlugin();
- private SharedPreferences prefs;
public static OverviewPlugin getPlugin() {
return overviewPlugin;
@@ -118,6 +117,8 @@ public class OverviewFragment extends Fragment {
TextView apsModeView;
TextView tempTargetView;
TextView pumpStatusView;
+ LinearLayout loopStatusLayout;
+ LinearLayout pumpStatusLayout;
GraphView bgGraph;
CheckBox showPredictionView;
@@ -151,7 +152,6 @@ public class OverviewFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
View view = inflater.inflate(R.layout.overview_fragment, container, false);
bgView = (TextView) view.findViewById(R.id.overview_bg);
@@ -163,7 +163,9 @@ public class OverviewFragment extends Fragment {
baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal);
basalLayout = (LinearLayout) view.findViewById(R.id.overview_basallayout);
activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile);
- pumpStatusView = (TextView) view.findViewById(R.id.overview_initializing);
+ pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
+ loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
+ pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
iobView = (TextView) view.findViewById(R.id.overview_iob);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
@@ -185,12 +187,13 @@ public class OverviewFragment extends Fragment {
llm = new LinearLayoutManager(view.getContext());
notificationsView.setLayoutManager(llm);
- showPredictionView.setChecked(prefs.getBoolean("showprediction", false));
+ showPredictionView.setChecked(SP.getBoolean("showprediction", false));
showPredictionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- SharedPreferences.Editor editor = prefs.edit();
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
+ SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("showprediction", showPredictionView.isChecked());
editor.apply();
updateGUI();
@@ -295,7 +298,7 @@ public class OverviewFragment extends Fragment {
sHandler.post(new Runnable() {
@Override
public void run() {
- MainApp.getConfigBuilder().updateStatus("RefreshClicked");
+ MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
}
});
}
@@ -320,7 +323,7 @@ public class OverviewFragment extends Fragment {
final JSONObject boluscalcJSON = new JSONObject();
try {
- boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
+ boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
boluscalcJSON.put("targetBGLow", wizard.targetBGLow);
boluscalcJSON.put("targetBGHigh", wizard.targetBGHigh);
boluscalcJSON.put("isf", wizard.sens);
@@ -477,18 +480,13 @@ public class OverviewFragment extends Fragment {
}
@Subscribe
- public void onStatusEvent(final EventDanaRConnectionStatus s) {
+ public void onStatusEvent(final EventPumpStatusChanged s) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
- if (s.sStatus == EventDanaRConnectionStatus.CONNECTING)
- updatePumpStatus(String.format(getString(R.string.danar_history_connectingfor), s.sSecondsElapsed));
- else if (s.sStatus == EventDanaRConnectionStatus.PERFORMING)
- updatePumpStatus(s.sAction);
- else if (s.sStatus == EventDanaRConnectionStatus.DISCONNECTED)
- updatePumpStatus(null);
+ updatePumpStatus(s.textStatus());
}
});
}
@@ -517,30 +515,15 @@ public class OverviewFragment extends Fragment {
private void updatePumpStatus(String status) {
PumpInterface pump = MainApp.getConfigBuilder();
- if (status != null) {
+ if (!status.equals("")) {
pumpStatusView.setText(status);
- pumpStatusView.setVisibility(View.VISIBLE);
- } else if (pump.isBusy()) {
- pumpStatusView.setText(R.string.pumpbusy);
- pumpStatusView.setVisibility(View.VISIBLE);
- } else if (pump.isSuspended()) {
- // disable all treatment buttons because we are not able to check constraints without profile
- wizardButton.setVisibility(View.INVISIBLE);
- treatmentButton.setVisibility(View.INVISIBLE);
- quickWizardButton.setVisibility(View.INVISIBLE);
- pumpStatusView.setText(R.string.pumpsuspendedclicktorefresh);
- pumpStatusView.setVisibility(View.VISIBLE);
- } else if (!pump.isInitialized()) {
- // disable all treatment buttons because we are not able to check constraints without profile
- wizardButton.setVisibility(View.INVISIBLE);
- treatmentButton.setVisibility(View.INVISIBLE);
- quickWizardButton.setVisibility(View.INVISIBLE);
- pumpStatusView.setText(R.string.waitingforpumpclicktorefresh);
- pumpStatusView.setVisibility(View.VISIBLE);
+ pumpStatusLayout.setVisibility(View.VISIBLE);
+ loopStatusLayout.setVisibility(View.GONE);
} else {
wizardButton.setVisibility(View.VISIBLE);
treatmentButton.setVisibility(View.VISIBLE);
- pumpStatusView.setVisibility(View.GONE);
+ pumpStatusLayout.setVisibility(View.GONE);
+ loopStatusLayout.setVisibility(View.VISIBLE);
}
}
@@ -552,10 +535,12 @@ public class OverviewFragment extends Fragment {
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null || MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
- pumpStatusView.setVisibility(View.VISIBLE);
+ pumpStatusLayout.setVisibility(View.VISIBLE);
+ loopStatusLayout.setVisibility(View.GONE);
return;
} else {
- pumpStatusView.setVisibility(View.GONE);
+ pumpStatusLayout.setVisibility(View.GONE);
+ loopStatusLayout.setVisibility(View.VISIBLE);
}
// Skip if not initialized yet
@@ -623,15 +608,15 @@ public class OverviewFragment extends Fragment {
tempTargetView.setText(NSProfile.toUnitsString(tempTarget.low, NSProfile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + NSProfile.toUnitsString(tempTarget.high, NSProfile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits()));
} else {
- String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
- String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
+ Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
+ Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
if (!profile.getUnits().equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
}
tempTargetView.setTextColor(Color.WHITE);
tempTargetView.setBackgroundResource(R.drawable.temptargetborderdisabled);
- tempTargetView.setText(prefs.getString("openapsma_min_bg", minBgDefault) + " - " + prefs.getString("openapsma_max_bg", maxBgDefault));
+ tempTargetView.setText(SP.getDouble("openapsma_min_bg", minBgDefault) + " - " + SP.getDouble("openapsma_max_bg", maxBgDefault));
tempTargetView.setVisibility(View.VISIBLE);
}
} else {
@@ -799,8 +784,8 @@ public class OverviewFragment extends Fragment {
endTime = toTime;
}
- Double lowLine = SafeParse.stringToDouble(prefs.getString("low_mark", "0"));
- Double highLine = SafeParse.stringToDouble(prefs.getString("high_mark", "0"));
+ Double lowLine = SP.getDouble("low_mark", 0d);
+ Double highLine = SP.getDouble("high_mark", 0d);
if (lowLine < 1) {
lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units);
@@ -1003,7 +988,7 @@ public class OverviewFragment extends Fragment {
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(ContextCompat.getColor(MainApp.instance(), R.color.background_material_dark)); // same color as backround = hide
}
- updatePumpStatus(null);
+ //updatePumpStatus(null);
}
//Notifications
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java
index 9caa2fde10..a8f0083afc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java
@@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.Overview;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
@@ -13,6 +10,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
+import info.nightscout.utils.SP;
/**
* Created by mike on 05.08.2016.
@@ -27,8 +25,7 @@ public class OverviewPlugin implements PluginBase {
public NotificationStore notificationStore = new NotificationStore();
public OverviewPlugin() {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- String storedData = preferences.getString("QuickWizard", "[]");
+ String storedData = SP.getString("QuickWizard", "[]");
try {
quickWizard.setData(new JSONArray(storedData));
} catch (JSONException e) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java
index ac7dbaa101..4f3e2a255c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java
@@ -7,12 +7,10 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import info.nightscout.androidaps.MainApp;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyPlugin.java
index d9bff5a4cd..9cbda6bf06 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyPlugin.java
@@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.SafetyFragment;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,9 +10,9 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.Round;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.utils.SP;
/**
* Created by mike on 05.08.2016.
@@ -78,7 +75,6 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
**/
@Override
public boolean isClosedModeEnabled() {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String mode = SP.getString("aps_mode", "open");
return mode.equals("closed") && BuildConfig.CLOSEDLOOP;
}
@@ -96,15 +92,14 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
@Override
public Double applyBasalConstraints(Double absoluteRate) {
Double origAbsoluteRate = absoluteRate;
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- Double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
+ Double maxBasal = SP.getDouble("openapsma_max_basal", 1d);
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null) return absoluteRate;
if (absoluteRate < 0) absoluteRate = 0d;
- Integer maxBasalMult = SafeParse.stringToInt(SP.getString("openapsama_current_basal_safety_multiplier", "4"));
- Integer maxBasalFromDaily = SafeParse.stringToInt(SP.getString("openapsama_max_daily_safety_multiplier", "3"));
+ Integer maxBasalMult = SP.getInt("openapsama_current_basal_safety_multiplier", 4);
+ Integer maxBasalFromDaily = SP.getInt("openapsama_max_daily_safety_multiplier", 3);
// Check percentRate but absolute rate too, because we know real current basal in pump
Double origRate = absoluteRate;
if (absoluteRate > maxBasal) {
@@ -128,8 +123,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
@Override
public Integer applyBasalConstraints(Integer percentRate) {
Integer origPercentRate = percentRate;
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- Double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
+ Double maxBasal = SP.getDouble("openapsma_max_basal", 1d);
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null) return percentRate;
@@ -142,8 +136,8 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
if (absoluteRate < 0) absoluteRate = 0d;
- Integer maxBasalMult = SafeParse.stringToInt(SP.getString("openapsama_current_basal_safety_multiplier", "4"));
- Integer maxBasalFromDaily = SafeParse.stringToInt(SP.getString("openapsama_max_daily_safety_multiplier", "3"));
+ Integer maxBasalMult = SP.getInt("openapsama_current_basal_safety_multiplier", 4);
+ Integer maxBasalFromDaily = SP.getInt("openapsama_max_daily_safety_multiplier", 3);
// Check percentRate but absolute rate too, because we know real current basal in pump
Double origRate = absoluteRate;
if (absoluteRate > maxBasal) {
@@ -174,9 +168,8 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
@Override
public Double applyBolusConstraints(Double insulin) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
try {
- Double maxBolus = SafeParse.stringToDouble(SP.getString("treatmentssafety_maxbolus", "3"));
+ Double maxBolus = SP.getDouble("treatmentssafety_maxbolus", 3d);
if (insulin < 0) insulin = 0d;
if (insulin > maxBolus) insulin = maxBolus;
@@ -189,9 +182,8 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
@Override
public Integer applyCarbsConstraints(Integer carbs) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
try {
- Integer maxCarbs = SafeParse.stringToInt(SP.getString("treatmentssafety_maxcarbs", "48"));
+ Integer maxCarbs = SP.getInt("treatmentssafety_maxcarbs", 48);
if (carbs < 0) carbs = 0;
if (carbs > maxCarbs) carbs = maxCarbs;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfilePlugin.java
index 3264696feb..f40d85371e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfilePlugin.java
@@ -15,7 +15,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
/**
@@ -60,7 +61,7 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.simpleprofile_shortname);
- if (!name.trim().isEmpty()){
+ if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
@@ -114,64 +115,15 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
private void loadSettings() {
if (Config.logPrefsChange)
log.debug("Loading stored settings");
- SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- if (settings.contains("SimpleProfile" + "mgdl"))
- try {
- mgdl = settings.getBoolean("SimpleProfile" + "mgdl", true);
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else mgdl = true;
- if (settings.contains("SimpleProfile" + "mmol"))
- try {
- mmol = settings.getBoolean("SimpleProfile" + "mmol", false);
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else mmol = false;
- if (settings.contains("SimpleProfile" + "dia"))
- try {
- dia = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "dia", "3"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else dia = 3d;
- if (settings.contains("SimpleProfile" + "ic"))
- try {
- ic = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "ic", "20"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else ic = 20d;
- if (settings.contains("SimpleProfile" + "isf"))
- try {
- isf = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "isf", "200"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else isf = 200d;
- if (settings.contains("SimpleProfile" + "basal"))
- try {
- basal = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "basal", "1"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else basal = 1d;
- if (settings.contains("SimpleProfile" + "targetlow"))
- try {
- targetLow = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "targetlow", "80"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else targetLow = 80d;
- if (settings.contains("SimpleProfile" + "targethigh"))
- try {
- targetHigh = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "targethigh", "120"));
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
- else targetHigh = 120d;
+ mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);
+ mmol = SP.getBoolean("SimpleProfile" + "mmol", false);
+ dia = SP.getDouble("SimpleProfile" + "dia", 3d);
+ ic = SP.getDouble("SimpleProfile" + "ic", 20d);
+ isf = SP.getDouble("SimpleProfile" + "isf", 200d);
+ basal = SP.getDouble("SimpleProfile" + "basal", 1d);
+ targetLow = SP.getDouble("SimpleProfile" + "targetlow", 80d);
+ targetHigh = SP.getDouble("SimpleProfile" + "targethigh", 120d);
createConvertedProfile();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java
index 4097efcdf9..e216764a3d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java
@@ -22,6 +22,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.GlucoseStatus;
+import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventPreferenceChange;
@@ -30,13 +31,13 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.data.IobTotal;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
-import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.XdripCalibrations;
@@ -159,8 +160,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
@Subscribe
public void processSettings(final EventPreferenceChange ev) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
- String settings = sharedPreferences.getString("smscommunicator_allowednumbers", "");
+ String settings = SP.getString("smscommunicator_allowednumbers", "");
String pattern = ";";
@@ -191,8 +191,6 @@ public class SmsCommunicatorPlugin implements PluginBase {
}
private void processSms(Sms receivedSms) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
-
if (!isEnabled(PluginBase.GENERAL)) {
log.debug("Ignoring SMS. Plugin disabled.");
return;
@@ -319,7 +317,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
break;
case "BASAL":
if (splited.length > 1) {
- boolean remoteCommandsAllowed = sharedPreferences.getBoolean("smscommunicator_remotecommandsallowed", false);
+ boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
if (remoteCommandsAllowed) {
passCode = generatePasscode();
@@ -355,7 +353,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
} else if (splited.length > 1) {
amount = SafeParse.stringToDouble(splited[1]);
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
- boolean remoteCommandsAllowed = sharedPreferences.getBoolean("smscommunicator_remotecommandsallowed", false);
+ boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
if (amount > 0d && remoteCommandsAllowed) {
passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
@@ -372,7 +370,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
case "CAL":
if (splited.length > 1) {
amount = SafeParse.stringToDouble(splited[1]);
- boolean remoteCommandsAllowed = sharedPreferences.getBoolean("smscommunicator_remotecommandsallowed", false);
+ boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
if (amount > 0d && remoteCommandsAllowed) {
passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
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 4bfe4ca74e..f9e979ae45 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
@@ -34,7 +34,7 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;
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 38a4904b56..4e1b41906e 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
@@ -36,7 +36,7 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.FragmentBase;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
index 966a5e7578..c49e26553e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
@@ -1,35 +1,25 @@
package info.nightscout.androidaps.plugins.Treatments;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
-import com.j256.ormlite.dao.Dao;
-import com.j256.ormlite.stmt.PreparedQuery;
-import com.j256.ormlite.stmt.QueryBuilder;
-import com.j256.ormlite.stmt.Where;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
+import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
-import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.client.data.NSProfile;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
+import info.nightscout.utils.SP;
/**
* Created by mike on 05.08.2016.
@@ -125,7 +115,6 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override
public IobTotal getCalculationToTime(long time) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
IobTotal total = new IobTotal(time);
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
@@ -143,7 +132,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
Iob tIOB = t.iobCalc(now, dia);
total.iob += tIOB.iobContrib;
total.activity += tIOB.activityContrib;
- Iob bIOB = t.iobCalc(now, dia / SafeParse.stringToInt(SP.getString("openapsama_bolussnooze_dia_divisor", "2")));
+ Iob bIOB = t.iobCalc(now, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
total.bolussnooze += bIOB.iobContrib;
}
return total;
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 e90916122f..0e46b6a219 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
@@ -23,7 +23,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.VirtualPump.events.EventVirtualPumpUpdateGui;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**
@@ -158,12 +158,12 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
- public Date lastStatusTime() {
+ public Date lastDataTime() {
return new Date();
}
@Override
- public void updateStatus(String reason) {
+ public void refreshDataFromPump(String reason) {
// do nothing
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
index 8b24be7979..6afb51c5c6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
@@ -1,21 +1,11 @@
package info.nightscout.androidaps.plugins.Wear;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.graphics.Color;
import android.os.Handler;
import android.os.HandlerThread;
-import android.preference.PreferenceManager;
-import android.support.annotation.BoolRes;
import android.support.annotation.NonNull;
-import android.support.v7.app.AlertDialog;
-import android.view.View;
import com.j256.ormlite.dao.Dao;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Date;
@@ -32,15 +22,14 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Overview.QuickWizard;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
-import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
@@ -56,9 +45,6 @@ public class ActionStringHandler {
private static String lastConfirmActionString = null;
private static BolusWizard lastBolusWizard = null;
- private static SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
-
-
private static HandlerThread handlerThread = new HandlerThread(FillDialog.class.getSimpleName());
static {
handlerThread.start();
@@ -83,11 +69,11 @@ public class ActionStringHandler {
///////////////////////////////////// PRIME/FILL
double amount = 0d;
if ("1".equals(act[1])) {
- amount = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button1", "0.3"))));
+ amount = SP.getDouble("fill_button1", 0.3);
} else if ("2".equals(act[1])) {
- amount = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button2", "0"))));
+ amount = SP.getDouble("fill_button2", 0d);
} else if ("3".equals(act[1])) {
- amount = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button3", "0"))));
+ amount = SP.getDouble("fill_button3", 0d);
} else {
return;
}
@@ -305,17 +291,17 @@ public class ActionStringHandler {
}
//Default Range/Target
- String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
- String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
- String targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
+ Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
+ Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
+ Double targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
if (!profile.getUnits().equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
targetBgDefault = Constants.TARGET_BG_DEFAULT_MMOL;
}
ret += "DEFAULT RANGE: ";
- ret += sp.getString("openapsma_min_bg", minBgDefault) + " - " + sp.getString("openapsma_max_bg", maxBgDefault);
- ret += " target: " + sp.getString("openapsma_target_bg", targetBgDefault);
+ ret += SP.getDouble("openapsma_min_bg", minBgDefault) + " - " + SP.getDouble("openapsma_max_bg", maxBgDefault);
+ ret += " target: " + SP.getDouble("openapsma_target_bg", targetBgDefault);
return ret;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
index 9e1f9709dd..5df62fd4dd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
@@ -35,7 +35,7 @@ import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java
index 532959d926..37b2d5b99d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java
@@ -28,7 +28,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.IobTotal;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java
index a7f3f02f36..434d488086 100644
--- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java
@@ -18,14 +18,10 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
-import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);
@@ -43,7 +39,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
boolean isBasalOutdated = false;
boolean isStatusOutdated = false;
- Date lastConnection = pump.lastStatusTime();
+ Date lastConnection = pump.lastDataTime();
if (lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime())
isStatusOutdated = true;
if (Math.abs(profile.getBasal(NSProfile.secondsFromMidnight()) - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep)
@@ -62,7 +58,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
- pump.updateStatus("KeepAlive. Status outdated.");
+ pump.refreshDataFromPump("KeepAlive. Status outdated.");
}
});
t.start();
@@ -70,7 +66,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
- pump.updateStatus("KeepAlive. Basal outdated.");
+ pump.refreshDataFromPump("KeepAlive. Basal outdated.");
}
});
t.start();
diff --git a/app/src/main/java/info/nightscout/utils/BatteryLevel.java b/app/src/main/java/info/nightscout/utils/BatteryLevel.java
new file mode 100644
index 0000000000..44f6b6e0e5
--- /dev/null
+++ b/app/src/main/java/info/nightscout/utils/BatteryLevel.java
@@ -0,0 +1,28 @@
+package info.nightscout.utils;
+
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+
+import info.nightscout.androidaps.MainApp;
+
+/**
+ * Created by mike on 20.02.2017.
+ */
+
+public class BatteryLevel {
+ static public int lastUploadedLevel = 0;
+
+ static public int getBatteryLevel() {
+ Intent batteryIntent = MainApp.instance().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ if (batteryIntent != null) {
+ int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
+ int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
+ if (level == -1 || scale == -1) {
+ return 50;
+ }
+ return (int) (((float) level / (float) scale) * 100.0f);
+ } else return 50;
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java
index 80e907bb6f..c3607cc89a 100644
--- a/app/src/main/java/info/nightscout/utils/BolusWizard.java
+++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java
@@ -6,7 +6,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.data.IobTotal;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 11.10.2016.
diff --git a/app/src/main/java/info/nightscout/utils/LocaleHelper.java b/app/src/main/java/info/nightscout/utils/LocaleHelper.java
index 1d89c7d689..c8faa83b9d 100644
--- a/app/src/main/java/info/nightscout/utils/LocaleHelper.java
+++ b/app/src/main/java/info/nightscout/utils/LocaleHelper.java
@@ -40,8 +40,7 @@ public class LocaleHelper {
}
private static String getPersistedData(Context context, String defaultLanguage) {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- return preferences.getString(SELECTED_LANGUAGE, defaultLanguage);
+ return SP.getString(SELECTED_LANGUAGE, defaultLanguage);
}
private static void persist(Context context, String language) {
diff --git a/app/src/main/java/info/nightscout/utils/PasswordProtection.java b/app/src/main/java/info/nightscout/utils/PasswordProtection.java
index 2b8d7a59c1..1af10eb2d2 100644
--- a/app/src/main/java/info/nightscout/utils/PasswordProtection.java
+++ b/app/src/main/java/info/nightscout/utils/PasswordProtection.java
@@ -3,8 +3,6 @@ package info.nightscout.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
@@ -19,7 +17,6 @@ import info.nightscout.androidaps.R;
public class PasswordProtection {
static public boolean isLocked(String preference) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
final String password = SP.getString(preference, "");
if (password.equals("")) {
return false;
@@ -28,7 +25,6 @@ public class PasswordProtection {
}
static public void QueryPassword(final Context context, int stringID, String preference, final Runnable ok, final Runnable fail) {
- SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
final String password = SP.getString(preference, "");
if (password.equals("")) {
if (ok != null) ok.run();
diff --git a/app/src/main/java/info/nightscout/utils/SP.java b/app/src/main/java/info/nightscout/utils/SP.java
new file mode 100644
index 0000000000..3626d7c69e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/utils/SP.java
@@ -0,0 +1,90 @@
+package info.nightscout.utils;
+
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+
+import info.nightscout.androidaps.MainApp;
+
+/**
+ * Created by mike on 17.02.2017.
+ */
+
+public class SP {
+ static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
+
+ static public boolean contains(String key) {
+ return sharedPreferences.contains(key);
+ }
+
+ static public String getString(int resourceID, String defaultValue) {
+ return sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue);
+ }
+
+ static public String getString(String key, String defaultValue) {
+ return sharedPreferences.getString(key, defaultValue);
+ }
+
+ static public boolean getBoolean(int resourceID, boolean defaultValue) {
+ try {
+ return sharedPreferences.getBoolean(MainApp.sResources.getString(resourceID), defaultValue);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ static public boolean getBoolean(String key, boolean defaultValue) {
+ try {
+ return sharedPreferences.getBoolean(key, defaultValue);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ static public Double getDouble(int resourceID, Double defaultValue) {
+ return SafeParse.stringToDouble(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString()));
+ }
+
+ static public Double getDouble(String key, Double defaultValue) {
+ return SafeParse.stringToDouble(sharedPreferences.getString(key, defaultValue.toString()));
+ }
+
+ static public int getInt(int resourceID, Integer defaultValue) {
+ return SafeParse.stringToInt(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString()));
+ }
+
+ static public int getInt(String key, Integer defaultValue) {
+ return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString()));
+ }
+
+ static public long getLong(int resourceID, Long defaultValue) {
+ return SafeParse.stringToLong(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString()));
+ }
+
+ static public long getLong(String key, Long defaultValue) {
+ return SafeParse.stringToLong(sharedPreferences.getString(key, defaultValue.toString()));
+ }
+
+ static public void putBoolean(String key, boolean value) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putBoolean(key, value);
+ editor.apply();
+ }
+
+ static public void putBoolean(int resourceID, boolean value) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putBoolean(MainApp.sResources.getString(resourceID), value);
+ editor.apply();
+ }
+
+ static public void putString(String key, String value) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putString(key, value);
+ editor.apply();
+ }
+
+ static public void putString(int resourceID, String value) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putString(MainApp.sResources.getString(resourceID), value);
+ editor.apply();
+ }
+}
diff --git a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java
index 338304d790..53c3bf45ec 100644
--- a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java
+++ b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java
@@ -17,7 +17,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
-import info.nightscout.client.data.NSProfile;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 10.02.2017.
diff --git a/app/src/main/res/layout/nsclientinternal_fragment.xml b/app/src/main/res/layout/nsclientinternal_fragment.xml
new file mode 100644
index 0000000000..580df825ca
--- /dev/null
+++ b/app/src/main/res/layout/nsclientinternal_fragment.xml
@@ -0,0 +1,168 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml
index 939f506890..26d53c7e9a 100644
--- a/app/src/main/res/layout/overview_fragment.xml
+++ b/app/src/main/res/layout/overview_fragment.xml
@@ -21,6 +21,7 @@
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+ android:textColor="@color/mdtp_white" />
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+ android:gravity="center_horizontal"
+ android:orientation="horizontal">
Прекъсване