create singleton from NSstatus
This commit is contained in:
parent
b41a942d11
commit
0f40670c24
4 changed files with 171 additions and 40 deletions
|
@ -166,7 +166,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
|
||||
log.debug("Requesting ignore battery optimization");
|
||||
|
||||
OKDialog.show(getParent(), getString(R.string.pleaseallowpermission), String.format(getString(R.string.needwhitelisting), getString(R.string.app_name)), new Runnable() {
|
||||
OKDialog.show(this, getString(R.string.pleaseallowpermission), String.format(getString(R.string.needwhitelisting), getString(R.string.app_name)), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin
|
|||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
|
@ -230,8 +231,6 @@ public class DataService extends IntentService {
|
|||
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received status: " + bundles);
|
||||
if (bundles.containsKey("nsclientversioncode")) {
|
||||
ConfigBuilderPlugin.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
||||
ConfigBuilderPlugin.nightscoutVersionName = bundles.getString("nightscoutversionname");
|
||||
|
@ -261,6 +260,9 @@ public class DataService extends IntentService {
|
|||
if (bundles.containsKey("status")) {
|
||||
try {
|
||||
JSONObject statusJson = new JSONObject(bundles.getString("status"));
|
||||
NSStatus.getInstance().setData(statusJson);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received status: " + statusJson.toString());
|
||||
if (statusJson.has("settings")) {
|
||||
JSONObject settings = statusJson.getJSONObject("settings");
|
||||
if (settings.has("thresholds")) {
|
||||
|
|
|
@ -5,40 +5,157 @@ import org.json.JSONObject;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
/*
|
||||
{
|
||||
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
|
||||
"status": "ok",
|
||||
"name": "Nightscout",
|
||||
"version": "0.10.0-dev-20170423",
|
||||
"versionNum": 1000,
|
||||
"serverTime": "2017-06-12T07:46:56.006Z",
|
||||
"apiEnabled": true,
|
||||
"careportalEnabled": true,
|
||||
"boluscalcEnabled": true,
|
||||
"head": "96ee154",
|
||||
"settings": {
|
||||
"units": "mmol",
|
||||
"timeFormat": 24,
|
||||
"nightMode": false,
|
||||
"editMode": true,
|
||||
"showRawbg": "always",
|
||||
"customTitle": "Bara's CGM",
|
||||
"theme": "colors",
|
||||
"alarmUrgentHigh": true,
|
||||
"alarmUrgentHighMins": [30, 60, 90, 120],
|
||||
"alarmHigh": true,
|
||||
"alarmHighMins": [30, 60, 90, 120],
|
||||
"alarmLow": true,
|
||||
"alarmLowMins": [15, 30, 45, 60],
|
||||
"alarmUrgentLow": true,
|
||||
"alarmUrgentLowMins": [15, 30, 45],
|
||||
"alarmUrgentMins": [30, 60, 90, 120],
|
||||
"alarmWarnMins": [30, 60, 90, 120],
|
||||
"alarmTimeagoWarn": true,
|
||||
"alarmTimeagoWarnMins": 15,
|
||||
"alarmTimeagoUrgent": true,
|
||||
"alarmTimeagoUrgentMins": 30,
|
||||
"language": "cs",
|
||||
"scaleY": "linear",
|
||||
"showPlugins": "careportal boluscalc food bwp cage sage iage iob cob basal ar2 delta direction upbat rawbg",
|
||||
"showForecast": "ar2",
|
||||
"focusHours": 3,
|
||||
"heartbeat": 60,
|
||||
"baseURL": "http:\/\/barascgm.sysop.cz:82",
|
||||
"authDefaultRoles": "readable",
|
||||
"thresholds": {
|
||||
"bgHigh": 252,
|
||||
"bgTargetTop": 180,
|
||||
"bgTargetBottom": 72,
|
||||
"bgLow": 71
|
||||
},
|
||||
"DEFAULT_FEATURES": ["bgnow", "delta", "direction", "timeago", "devicestatus", "upbat", "errorcodes", "profile"],
|
||||
"alarmTypes": ["predict"],
|
||||
"enable": ["careportal", "boluscalc", "food", "bwp", "cage", "sage", "iage", "iob", "cob", "basal", "ar2", "rawbg", "pushover", "bgi", "pump", "openaps", "pushover", "treatmentnotify", "bgnow", "delta", "direction", "timeago", "devicestatus", "upbat", "profile", "ar2"]
|
||||
},
|
||||
"extendedSettings": {
|
||||
"pump": {
|
||||
"fields": "reservoir battery clock",
|
||||
"urgentBattP": 26,
|
||||
"warnBattP": 51
|
||||
},
|
||||
"openaps": {
|
||||
"enableAlerts": true
|
||||
},
|
||||
"cage": {
|
||||
"alerts": true,
|
||||
"display": "days",
|
||||
"urgent": 96,
|
||||
"warn": 72
|
||||
},
|
||||
"sage": {
|
||||
"alerts": true,
|
||||
"urgent": 336,
|
||||
"warn": 168
|
||||
},
|
||||
"iage": {
|
||||
"alerts": true,
|
||||
"urgent": 150,
|
||||
"warn": 120
|
||||
},
|
||||
"basal": {
|
||||
"render": "default"
|
||||
},
|
||||
"profile": {
|
||||
"history": true,
|
||||
"multiple": true
|
||||
},
|
||||
"devicestatus": {
|
||||
"advanced": true
|
||||
}
|
||||
},
|
||||
"activeProfile": "2016 +30%"
|
||||
}
|
||||
*/
|
||||
public class NSStatus {
|
||||
private JSONObject data;
|
||||
private static NSStatus instance = null;
|
||||
|
||||
public NSStatus(JSONObject obj) {
|
||||
this.data = obj;
|
||||
public static NSStatus getInstance() {
|
||||
if (instance == null)
|
||||
instance = new NSStatus();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getName () { return getStringOrNull("name"); }
|
||||
public String getVersion () { return getStringOrNull("version"); }
|
||||
public Integer getVersionNum () { return getIntegerOrNull("versionNum"); }
|
||||
public Date getServerTime () { return getDateOrNull("versionNum"); }
|
||||
public boolean getApiEnabled () { return getBooleanOrNull("apiEnabled"); }
|
||||
public boolean getCareportalEnabled () { return getBooleanOrNull("careportalEnabled"); }
|
||||
public boolean getBoluscalcEnabled () { return getBooleanOrNull("boluscalcEnabled"); }
|
||||
public String getHead () { return getStringOrNull("head"); }
|
||||
public String getSettings () { return getStringOrNull("settings"); }
|
||||
public String getExtendedSettings () { return getStringOrNull("extendedSettings"); }
|
||||
public String getActiveProfile () { return getStringOrNull("activeProfile"); }
|
||||
private JSONObject data;
|
||||
|
||||
public NSStatus() {}
|
||||
|
||||
public NSStatus setData(JSONObject obj) {
|
||||
this.data = obj;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getStringOrNull("name");
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return getStringOrNull("version");
|
||||
}
|
||||
|
||||
public Integer getVersionNum() {
|
||||
return getIntegerOrNull("versionNum");
|
||||
}
|
||||
|
||||
public Date getServerTime() {
|
||||
return getDateOrNull("versionNum");
|
||||
}
|
||||
|
||||
public boolean getApiEnabled() {
|
||||
return getBooleanOrNull("apiEnabled");
|
||||
}
|
||||
|
||||
public boolean getCareportalEnabled() {
|
||||
return getBooleanOrNull("careportalEnabled");
|
||||
}
|
||||
|
||||
public boolean getBoluscalcEnabled() {
|
||||
return getBooleanOrNull("boluscalcEnabled");
|
||||
}
|
||||
|
||||
public String getHead() {
|
||||
return getStringOrNull("head");
|
||||
}
|
||||
|
||||
public String getSettings() {
|
||||
return getStringOrNull("settings");
|
||||
}
|
||||
|
||||
public String getExtendedSettings() {
|
||||
return getStringOrNull("extendedSettings");
|
||||
}
|
||||
|
||||
public String getActiveProfile() {
|
||||
return getStringOrNull("activeProfile");
|
||||
}
|
||||
|
||||
private String getStringOrNull(String key) {
|
||||
String ret = null;
|
||||
|
@ -50,7 +167,9 @@ public class NSStatus {
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private Integer getIntegerOrNull(String key) {
|
||||
Integer ret = null;
|
||||
|
@ -62,7 +181,9 @@ public class NSStatus {
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private Long getLongOrNull(String key) {
|
||||
Long ret = null;
|
||||
|
@ -74,7 +195,9 @@ public class NSStatus {
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private Date getDateOrNull(String key) {
|
||||
Date ret = null;
|
||||
|
@ -86,7 +209,9 @@ public class NSStatus {
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private boolean getBooleanOrNull(String key) {
|
||||
boolean ret = false;
|
||||
|
@ -98,8 +223,12 @@ public class NSStatus {
|
|||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
public JSONObject getData () { return data; }
|
||||
;
|
||||
|
||||
public JSONObject getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -430,15 +430,15 @@ public class NSClientService extends Service {
|
|||
|
||||
if (data.has("status")) {
|
||||
JSONObject status = data.getJSONObject("status");
|
||||
NSStatus nsStatus = new NSStatus(status);
|
||||
NSStatus nsStatus = NSStatus.getInstance().setData(status);
|
||||
|
||||
if (!status.has("versionNum")) {
|
||||
if (status.getInt("versionNum") < 900) {
|
||||
if (status.getInt("versionNum") < Config.SUPPORTEDNSVERSION) {
|
||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
|
||||
}
|
||||
} else {
|
||||
nightscoutVersionName = status.getString("version");
|
||||
nightscoutVersionCode = status.getInt("versionNum");
|
||||
nightscoutVersionName = nsStatus.getVersion();
|
||||
nightscoutVersionCode = nsStatus.getVersionNum();
|
||||
}
|
||||
BroadcastStatus.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta);
|
||||
|
||||
|
|
Loading…
Reference in a new issue