code cleanup
This commit is contained in:
parent
36d94ecdef
commit
e5bf36bfe3
|
@ -13,12 +13,9 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -27,7 +24,6 @@ import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
||||||
import info.nightscout.utils.FabricPrivacy;
|
import info.nightscout.utils.FabricPrivacy;
|
||||||
|
@ -216,75 +212,54 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
public static void updateAge(Activity activity, final TextView sage, final TextView iage, final TextView cage, final TextView pbage) {
|
public static void updateAge(Activity activity, final TextView sage, final TextView iage, final TextView cage, final TextView pbage) {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
activity.runOnUiThread(
|
activity.runOnUiThread(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
CareportalEvent careportalEvent;
|
||||||
public void run() {
|
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
||||||
CareportalEvent careportalEvent;
|
|
||||||
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
|
||||||
JSONObject extendedSettings = nsSettings.getExtendedValues();
|
|
||||||
|
|
||||||
double iageUrgent = 0;
|
double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 72);
|
||||||
double iageWarn = 0;
|
double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 48);
|
||||||
double cageUrgent = 0;
|
double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72);
|
||||||
double cageWarn = 0;
|
double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48);
|
||||||
double sageUrgent = 0;
|
double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166);
|
||||||
double sageWarn = 0;
|
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
|
||||||
double pbageUrgent = 0;
|
double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
|
||||||
double pbageWarn = 0;
|
double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
|
||||||
log.debug("Values from NSSettings "+extendedSettings.toString());
|
|
||||||
// Thresholds in NS are in hours
|
|
||||||
try {
|
|
||||||
iageUrgent = extendedSettings.getDouble("iageUrgent");
|
|
||||||
iageWarn = extendedSettings.getDouble("iageWarn");
|
|
||||||
cageUrgent = extendedSettings.getDouble("cageUrgent");
|
|
||||||
cageWarn = extendedSettings.getDouble("cageWarn");
|
|
||||||
sageUrgent = extendedSettings.getDouble("sageUrgent");
|
|
||||||
sageWarn = extendedSettings.getDouble("sageWarn");
|
|
||||||
pbageUrgent = extendedSettings.getDouble("pbageUrgent");
|
|
||||||
pbageWarn = extendedSettings.getDouble("pbageWarn");
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable);
|
||||||
log.error("Unhandled exception", e);
|
if (sage != null) {
|
||||||
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
||||||
|
if (careportalEvent != null) {
|
||||||
|
sage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, sageWarn, sageUrgent));
|
||||||
|
sage.setText(careportalEvent.age());
|
||||||
|
} else {
|
||||||
|
sage.setText(notavailable);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (iage != null) {
|
||||||
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||||
String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable);
|
if (careportalEvent != null) {
|
||||||
if (sage != null) {
|
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageWarn, iageUrgent));
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
iage.setText(careportalEvent.age());
|
||||||
if(careportalEvent != null) {
|
} else {
|
||||||
sage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, sageUrgent, sageWarn));
|
iage.setText(notavailable);
|
||||||
sage.setText(careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
sage.setText(notavailable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (iage != null) {
|
}
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
if (cage != null) {
|
||||||
if(careportalEvent != null) {
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||||
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageUrgent, iageWarn));
|
if (careportalEvent != null) {
|
||||||
iage.setText(careportalEvent.age());
|
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageWarn, cageUrgent));
|
||||||
} else {
|
cage.setText(careportalEvent.age());
|
||||||
iage.setText(notavailable);
|
} else {
|
||||||
}
|
cage.setText(notavailable);
|
||||||
}
|
}
|
||||||
if (cage != null) {
|
}
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
if (pbage != null) {
|
||||||
if (careportalEvent != null) {
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
|
||||||
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageUrgent, cageWarn));
|
if (careportalEvent != null) {
|
||||||
cage.setText(careportalEvent.age());
|
pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageWarn, pbageUrgent));
|
||||||
} else {
|
pbage.setText(careportalEvent.age());
|
||||||
cage.setText(notavailable);
|
} else {
|
||||||
}
|
pbage.setText(notavailable);
|
||||||
}
|
|
||||||
if (pbage != null) {
|
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
|
|
||||||
if (careportalEvent != null) {
|
|
||||||
pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageUrgent, pbageWarn));
|
|
||||||
pbage.setText(careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
pbage.setText(notavailable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,10 +267,10 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold){
|
public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold) {
|
||||||
if(careportalEvent.isOlderThan(urgentThreshold)){
|
if (careportalEvent.isOlderThan(urgentThreshold)) {
|
||||||
return MainApp.sResources.getColor(R.color.low);
|
return MainApp.sResources.getColor(R.color.low);
|
||||||
} else if(careportalEvent.isOlderThan( warnThreshold)) {
|
} else if (careportalEvent.isOlderThan(warnThreshold)) {
|
||||||
return MainApp.sResources.getColor(R.color.high);
|
return MainApp.sResources.getColor(R.color.high);
|
||||||
} else {
|
} else {
|
||||||
return Color.WHITE;
|
return Color.WHITE;
|
||||||
|
|
|
@ -170,36 +170,17 @@ public class NSSettingsStatus {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return JSONObject with the WARN and URGENT values of cage,sage and iage
|
// valid property is "warn" or "urgent"
|
||||||
// added pbage for pump battery warnings
|
// plugings "iage" "sage" "cage" "pbage"
|
||||||
public JSONObject getExtendedValues(){
|
|
||||||
JSONObject extendedValues = new JSONObject(); //
|
public double getExtendedWarnValue(String plugin, String property, double defaultvalue) {
|
||||||
JSONObject defaultSettings = new JSONObject();
|
|
||||||
JSONObject extendedSettings = this.getExtendedSettings();
|
JSONObject extendedSettings = this.getExtendedSettings();
|
||||||
// Thresholds in NS are in hours
|
if (extendedSettings == null)
|
||||||
try {
|
return defaultvalue;
|
||||||
// Default
|
JSONObject pluginJson = extendedSettings.optJSONObject(plugin);
|
||||||
defaultSettings.put("urgent", 7*24D);
|
if (pluginJson == null)
|
||||||
defaultSettings.put("warn", 5*24D);
|
return defaultvalue;
|
||||||
|
return pluginJson.optDouble(property, defaultvalue);
|
||||||
JSONObject iageSettings = extendedSettings.optJSONObject("iage") != null ? extendedSettings.optJSONObject("iage") : defaultSettings;
|
|
||||||
JSONObject cageSettings = extendedSettings.optJSONObject("cage") != null ? extendedSettings.optJSONObject("cage") : defaultSettings;
|
|
||||||
JSONObject sageSettings = extendedSettings.optJSONObject("sage") != null ? extendedSettings.optJSONObject("sage") : defaultSettings;
|
|
||||||
|
|
||||||
extendedValues.put("cageUrgent", cageSettings.optDouble("urgent", 72));
|
|
||||||
extendedValues.put("cageWarn", cageSettings.optDouble("warn", 48));
|
|
||||||
extendedValues.put("sageUrgent", sageSettings.optDouble("urgent", 166));
|
|
||||||
extendedValues.put("sageWarn", sageSettings.optDouble("warn", 164));
|
|
||||||
extendedValues.put("iageUrgent", iageSettings.optDouble("urgent", 72));
|
|
||||||
extendedValues.put("iageWarn", iageSettings.optDouble("warn", 48));
|
|
||||||
extendedValues.put("pbageWarn", 240D);
|
|
||||||
extendedValues.put("pbageUrgent", 360D);
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return extendedValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActiveProfile() {
|
public String getActiveProfile() {
|
||||||
|
@ -225,7 +206,7 @@ public class NSSettingsStatus {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")){
|
if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")) {
|
||||||
Double result = settingsO.getDouble(what);
|
Double result = settingsO.getDouble(what);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +219,7 @@ public class NSSettingsStatus {
|
||||||
|
|
||||||
private String getStringOrNull(String key) {
|
private String getStringOrNull(String key) {
|
||||||
String ret = null;
|
String ret = null;
|
||||||
if(data == null) return null;
|
if (data == null) return null;
|
||||||
if (data.has(key)) {
|
if (data.has(key)) {
|
||||||
try {
|
try {
|
||||||
ret = data.getString(key);
|
ret = data.getString(key);
|
||||||
|
@ -320,21 +301,21 @@ public class NSSettingsStatus {
|
||||||
JSONObject pump = extentendedPumpSettings();
|
JSONObject pump = extentendedPumpSettings();
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case "warnClock":
|
case "warnClock":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "urgentClock":
|
case "urgentClock":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "warnRes":
|
case "warnRes":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "urgentRes":
|
case "urgentRes":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "warnBattV":
|
case "warnBattV":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "urgentBattV":
|
case "urgentBattV":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "warnBattP":
|
case "warnBattP":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
case "urgentBattP":
|
case "urgentBattP":
|
||||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -342,12 +323,12 @@ public class NSSettingsStatus {
|
||||||
return 0d;
|
return 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JSONObject extentendedPumpSettings() {
|
public JSONObject extentendedPumpSettings() {
|
||||||
try {
|
try {
|
||||||
JSONObject extended = getExtendedSettings();
|
JSONObject extended = getExtendedSettings();
|
||||||
if(extended == null) return null;
|
if (extended == null) return null;
|
||||||
if (extended.has("pump")) {
|
if (extended.has("pump")) {
|
||||||
JSONObject pump = extended.getJSONObject("pump");
|
JSONObject pump = extended.getJSONObject("pump");
|
||||||
return pump;
|
return pump;
|
||||||
|
@ -382,7 +363,7 @@ public class NSSettingsStatus {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean openAPSEnabledAlerts() {
|
public boolean openAPSEnabledAlerts() {
|
||||||
try {
|
try {
|
||||||
JSONObject pump = extentendedPumpSettings();
|
JSONObject pump = extentendedPumpSettings();
|
||||||
if (pump != null && pump.has("openaps")) {
|
if (pump != null && pump.has("openaps")) {
|
||||||
|
|
Loading…
Reference in a new issue