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 org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
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.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||
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.Overview.OverviewFragment;
|
||||
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) {
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CareportalEvent careportalEvent;
|
||||
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
||||
JSONObject extendedSettings = nsSettings.getExtendedValues();
|
||||
() -> {
|
||||
CareportalEvent careportalEvent;
|
||||
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
||||
|
||||
double iageUrgent = 0;
|
||||
double iageWarn = 0;
|
||||
double cageUrgent = 0;
|
||||
double cageWarn = 0;
|
||||
double sageUrgent = 0;
|
||||
double sageWarn = 0;
|
||||
double pbageUrgent = 0;
|
||||
double pbageWarn = 0;
|
||||
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");
|
||||
double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 72);
|
||||
double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 48);
|
||||
double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72);
|
||||
double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48);
|
||||
double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166);
|
||||
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
|
||||
double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
|
||||
double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
|
||||
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable);
|
||||
if (sage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
||||
if(careportalEvent != null) {
|
||||
sage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, sageUrgent, sageWarn));
|
||||
sage.setText(careportalEvent.age());
|
||||
} else {
|
||||
sage.setText(notavailable);
|
||||
}
|
||||
}
|
||||
if (iage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||
if (careportalEvent != null) {
|
||||
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageWarn, iageUrgent));
|
||||
iage.setText(careportalEvent.age());
|
||||
} else {
|
||||
iage.setText(notavailable);
|
||||
}
|
||||
if (iage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||
if(careportalEvent != null) {
|
||||
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageUrgent, iageWarn));
|
||||
iage.setText(careportalEvent.age());
|
||||
} else {
|
||||
iage.setText(notavailable);
|
||||
}
|
||||
}
|
||||
if (cage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||
if (careportalEvent != null) {
|
||||
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageWarn, cageUrgent));
|
||||
cage.setText(careportalEvent.age());
|
||||
} else {
|
||||
cage.setText(notavailable);
|
||||
}
|
||||
if (cage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||
if (careportalEvent != null) {
|
||||
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageUrgent, cageWarn));
|
||||
cage.setText(careportalEvent.age());
|
||||
} else {
|
||||
cage.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);
|
||||
}
|
||||
}
|
||||
if (pbage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
|
||||
if (careportalEvent != null) {
|
||||
pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageWarn, pbageUrgent));
|
||||
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){
|
||||
if(careportalEvent.isOlderThan(urgentThreshold)){
|
||||
public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold) {
|
||||
if (careportalEvent.isOlderThan(urgentThreshold)) {
|
||||
return MainApp.sResources.getColor(R.color.low);
|
||||
} else if(careportalEvent.isOlderThan( warnThreshold)) {
|
||||
} else if (careportalEvent.isOlderThan(warnThreshold)) {
|
||||
return MainApp.sResources.getColor(R.color.high);
|
||||
} else {
|
||||
return Color.WHITE;
|
||||
|
|
|
@ -170,36 +170,17 @@ public class NSSettingsStatus {
|
|||
|
||||
}
|
||||
|
||||
// return JSONObject with the WARN and URGENT values of cage,sage and iage
|
||||
// added pbage for pump battery warnings
|
||||
public JSONObject getExtendedValues(){
|
||||
JSONObject extendedValues = new JSONObject(); //
|
||||
JSONObject defaultSettings = new JSONObject();
|
||||
// valid property is "warn" or "urgent"
|
||||
// plugings "iage" "sage" "cage" "pbage"
|
||||
|
||||
public double getExtendedWarnValue(String plugin, String property, double defaultvalue) {
|
||||
JSONObject extendedSettings = this.getExtendedSettings();
|
||||
// Thresholds in NS are in hours
|
||||
try {
|
||||
// Default
|
||||
defaultSettings.put("urgent", 7*24D);
|
||||
defaultSettings.put("warn", 5*24D);
|
||||
|
||||
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;
|
||||
if (extendedSettings == null)
|
||||
return defaultvalue;
|
||||
JSONObject pluginJson = extendedSettings.optJSONObject(plugin);
|
||||
if (pluginJson == null)
|
||||
return defaultvalue;
|
||||
return pluginJson.optDouble(property, defaultvalue);
|
||||
}
|
||||
|
||||
public String getActiveProfile() {
|
||||
|
@ -225,7 +206,7 @@ public class NSSettingsStatus {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")){
|
||||
if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")) {
|
||||
Double result = settingsO.getDouble(what);
|
||||
return result;
|
||||
}
|
||||
|
@ -238,7 +219,7 @@ public class NSSettingsStatus {
|
|||
|
||||
private String getStringOrNull(String key) {
|
||||
String ret = null;
|
||||
if(data == null) return null;
|
||||
if (data == null) return null;
|
||||
if (data.has(key)) {
|
||||
try {
|
||||
ret = data.getString(key);
|
||||
|
@ -320,21 +301,21 @@ public class NSSettingsStatus {
|
|||
JSONObject pump = extentendedPumpSettings();
|
||||
switch (setting) {
|
||||
case "warnClock":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "urgentClock":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "warnRes":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "urgentRes":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "warnBattV":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "urgentBattV":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "warnBattP":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
case "warnBattP":
|
||||
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
|
||||
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) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -347,7 +328,7 @@ public class NSSettingsStatus {
|
|||
public JSONObject extentendedPumpSettings() {
|
||||
try {
|
||||
JSONObject extended = getExtendedSettings();
|
||||
if(extended == null) return null;
|
||||
if (extended == null) return null;
|
||||
if (extended.has("pump")) {
|
||||
JSONObject pump = extended.getJSONObject("pump");
|
||||
return pump;
|
||||
|
@ -382,7 +363,7 @@ public class NSSettingsStatus {
|
|||
return "";
|
||||
}
|
||||
|
||||
public boolean openAPSEnabledAlerts() {
|
||||
public boolean openAPSEnabledAlerts() {
|
||||
try {
|
||||
JSONObject pump = extentendedPumpSettings();
|
||||
if (pump != null && pump.has("openaps")) {
|
||||
|
|
Loading…
Reference in a new issue