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,44 +212,24 @@ 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();
|
||||
|
||||
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");
|
||||
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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.setTextColor(CareportalFragment.determineTextColor(careportalEvent, sageWarn, sageUrgent));
|
||||
sage.setText(careportalEvent.age());
|
||||
} else {
|
||||
sage.setText(notavailable);
|
||||
|
@ -262,7 +238,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
|||
if (iage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||
if (careportalEvent != null) {
|
||||
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageUrgent, iageWarn));
|
||||
iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageWarn, iageUrgent));
|
||||
iage.setText(careportalEvent.age());
|
||||
} else {
|
||||
iage.setText(notavailable);
|
||||
|
@ -271,7 +247,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
|||
if (cage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||
if (careportalEvent != null) {
|
||||
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageUrgent, cageWarn));
|
||||
cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageWarn, cageUrgent));
|
||||
cage.setText(careportalEvent.age());
|
||||
} else {
|
||||
cage.setText(notavailable);
|
||||
|
@ -280,14 +256,13 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
|||
if (pbage != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
|
||||
if (careportalEvent != null) {
|
||||
pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageUrgent, pbageWarn));
|
||||
pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageWarn, pbageUrgent));
|
||||
pbage.setText(careportalEvent.age());
|
||||
} else {
|
||||
pbage.setText(notavailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue