fix OPAS fragments
This commit is contained in:
parent
b0eecac00e
commit
442d48b4c2
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -97,7 +98,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
||||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
||||||
try {
|
try {
|
||||||
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
|
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
|
||||||
iobDataView.setText(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0)));
|
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
iobDataView.setText("JSONException");
|
iobDataView.setText("JSONException");
|
||||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -94,26 +96,26 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
|
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
|
||||||
if (determineBasalAdapterSMBJS != null) {
|
if (determineBasalAdapterSMBJS != null) {
|
||||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
|
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()));
|
||||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
|
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()));
|
||||||
try {
|
try {
|
||||||
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
|
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
|
||||||
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
|
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
iobDataView.setText("JSONException see log for details");
|
iobDataView.setText("JSONException see log for details");
|
||||||
}
|
}
|
||||||
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
|
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()));
|
||||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
|
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()));
|
||||||
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
|
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug());
|
||||||
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
|
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
|
||||||
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
|
constraintsView.setText(lastAPSResult.inputConstraints.getReasons());
|
||||||
}
|
}
|
||||||
if (plugin.lastAPSRun != 0) {
|
if (plugin.lastAPSRun != 0) {
|
||||||
lastRunView.setText(DateUtil.dateAndTimeFullString(plugin.lastAPSRun));
|
lastRunView.setText(DateUtil.dateAndTimeFullString(plugin.lastAPSRun));
|
||||||
}
|
}
|
||||||
if (plugin.lastAutosensResult != null) {
|
if (plugin.lastAutosensResult != null) {
|
||||||
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
|
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.utils;
|
package info.nightscout.androidaps.utils;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
@ -18,14 +19,23 @@ public class JSONFormatter {
|
||||||
private static Logger log = LoggerFactory.getLogger(JSONFormatter.class);
|
private static Logger log = LoggerFactory.getLogger(JSONFormatter.class);
|
||||||
|
|
||||||
public static Spanned format(final String jsonString) {
|
public static Spanned format(final String jsonString) {
|
||||||
final JsonVisitor visitor = new JsonVisitor(4, ' ');
|
final JsonVisitor visitor = new JsonVisitor(1, '\t');
|
||||||
try {
|
try {
|
||||||
if (jsonString.equals("undefined"))
|
if (jsonString.equals("undefined"))
|
||||||
return Html.fromHtml("undefined");
|
return Html.fromHtml("undefined");
|
||||||
else if (jsonString.getBytes()[0] == '[')
|
else if (jsonString.getBytes()[0] == '[')
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0), Html.FROM_HTML_MODE_COMPACT);
|
||||||
|
} else {
|
||||||
return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0));
|
return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0));
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0), Html.FROM_HTML_MODE_COMPACT);
|
||||||
|
} else {
|
||||||
return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0));
|
return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
return Html.fromHtml("");
|
return Html.fromHtml("");
|
||||||
|
@ -33,7 +43,7 @@ public class JSONFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spanned format(final JSONObject object) {
|
public static Spanned format(final JSONObject object) {
|
||||||
final JsonVisitor visitor = new JsonVisitor(4, ' ');
|
final JsonVisitor visitor = new JsonVisitor(1, '\t');
|
||||||
try {
|
try {
|
||||||
return Html.fromHtml(visitor.visit(object, 0));
|
return Html.fromHtml(visitor.visit(object, 0));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -58,7 +68,7 @@ public class JSONFormatter {
|
||||||
} else {
|
} else {
|
||||||
ret += write("[", indent);
|
ret += write("[", indent);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
ret += visit(array.get(i), indent + 1);
|
ret += visit(array.get(i), indent);
|
||||||
}
|
}
|
||||||
ret += write("]", indent);
|
ret += write("]", indent);
|
||||||
}
|
}
|
||||||
|
@ -73,8 +83,8 @@ public class JSONFormatter {
|
||||||
final Iterator<String> keys = obj.keys();
|
final Iterator<String> keys = obj.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
final String key = keys.next();
|
final String key = keys.next();
|
||||||
ret += write("<b>" + key + "</b>: ", indent + 1);
|
ret += write("<b>" + key + "</b>: ", indent);
|
||||||
ret += visit(obj.get(key), 0);
|
ret += visit(obj.get(key), indent + 1);
|
||||||
ret += "<br>";
|
ret += "<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +96,7 @@ public class JSONFormatter {
|
||||||
if (object instanceof JSONArray) {
|
if (object instanceof JSONArray) {
|
||||||
ret += visit((JSONArray) object, indent);
|
ret += visit((JSONArray) object, indent);
|
||||||
} else if (object instanceof JSONObject) {
|
} else if (object instanceof JSONObject) {
|
||||||
ret += visit((JSONObject) object, indent);
|
ret += "<br>" + visit((JSONObject) object, indent);
|
||||||
} else {
|
} else {
|
||||||
if (object instanceof String) {
|
if (object instanceof String) {
|
||||||
ret += write("\"" + ((String) object).replace("<", "<").replace(">", ">") + "\"", indent);
|
ret += write("\"" + ((String) object).replace("<", "<").replace(">", ">") + "\"", indent);
|
||||||
|
|
Loading…
Reference in a new issue