From f7715a34094f423231fdef8a98e6bf0dcd0cf5b0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 11 Jul 2016 17:49:09 +0200 Subject: [PATCH] xml reformating, some code cleaning --- .../info/nightscout/androidaps/Config.java | 3 +- .../androidaps/data/PumpEnactResult.java | 46 ++++++-- .../androidaps/db/DatabaseHelper.java | 17 +-- .../ConfigBuilder/ConfigBuilderFragment.java | 13 ++- .../plugins/DanaR/DanaConnection.java | 2 +- .../androidaps/plugins/Loop/APSResult.java | 25 +++-- .../androidaps/plugins/Loop/LoopFragment.java | 6 +- .../LowSuspend/LowSuspendFragment.java | 23 ++-- .../plugins/OpenAPSMA/OpenAPSMAFragment.java | 16 +-- .../plugins/Overview/OverviewFragment.java | 47 +++++--- .../TempBasals/TempBasalsFragment.java | 2 +- .../Treatments/TreatmentsFragment.java | 11 +- .../nightscout/utils/DecimalFormatter.java | 29 +++++ .../info/nightscout/utils/JsonFormatter.java | 101 ++++++++++++++++++ .../careportal_newnstreatment_dialog.xml | 1 - .../res/layout/configbuilder_fragment.xml | 28 ++--- app/src/main/res/layout/loop_fragment.xml | 15 +-- .../main/res/layout/lowsuspend_fragment.xml | 16 ++- .../main/res/layout/openapsma_fragment.xml | 22 ++-- .../main/res/layout/tempbasals_fragment.xml | 16 +-- app/src/main/res/layout/tempbasals_item.xml | 59 ++++++---- .../main/res/layout/treatments_fragment.xml | 30 +++--- app/src/main/res/layout/treatments_item.xml | 47 ++++---- app/src/main/res/values-bg/strings.xml | 10 +- app/src/main/res/values-cs/strings.xml | 12 +-- app/src/main/res/values-de/strings.xml | 16 +-- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 22 ++-- 28 files changed, 431 insertions(+), 205 deletions(-) create mode 100644 app/src/main/java/info/nightscout/utils/DecimalFormatter.java create mode 100644 app/src/main/java/info/nightscout/utils/JsonFormatter.java diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 3ec1707787..c0bb7e8d06 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -11,7 +11,8 @@ public class Config { public static final boolean OPENAPSMAENABLED = APS && true; public static final boolean LOOPENABLED = APS && true; public static final boolean OBJECTIVESENABLED = APS && true; - public static final boolean CAREPORTALENABLED = APS && true; + + public static final boolean CAREPORTALENABLED = true; public static final boolean DANAR = true; diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index 27737007cd..ec416e6635 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -2,11 +2,14 @@ package info.nightscout.androidaps.data; import android.os.Parcel; import android.os.Parcelable; +import android.text.Html; +import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.Round; @@ -30,22 +33,53 @@ public class PumpEnactResult extends Object implements Parcelable { } public String toString() { - String ret = "Success: " + success; + String ret = MainApp.sResources.getString(R.string.success) + ": " + success; if (enacted) { if (isTempCancel) { - ret += "\nEnacted: " + enacted + "\nComment: " + comment + "\n" + - "Temp cancel"; + ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment + "\n" + + MainApp.sResources.getString(R.string.tempcancel); } else if (isPercent) { - ret += "\nEnacted: " + enacted + "\nComment: " + comment + "\nDuration: " + duration + " min\nPercent: " + percent + "%"; + ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; + ret += "\n" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%"; } else { - ret += "\nEnacted: " + enacted + "\nComment: " + comment + "\nDuration: " + duration + " min\nAbsolute: " + absolute + " U/h"; + ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; + ret += "\n" + MainApp.sResources.getString(R.string.absolute) + ": " + absolute + " U/h"; } } else { - ret += "\nComment: " + comment; + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; } return ret; } + public Spanned toSpanned() { + String ret = "" + MainApp.sResources.getString(R.string.success) + ": " + success; + if (enacted) { + if (isTempCancel) { + ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment + + "
" + MainApp.sResources.getString(R.string.tempcancel); + } else if (isPercent) { + ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + ret += "
" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; + ret += "
" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%"; + } else { + ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + ret += "
" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min"; + ret += "
" + MainApp.sResources.getString(R.string.absolute) + ": " + absolute + " U/h"; + } + } else { + ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment; + } + return Html.fromHtml(ret); + } + @Override public int describeContents() { return 0; diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 7ef6018b66..7e742e0672 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -12,6 +12,8 @@ import android.database.sqlite.SQLiteDatabase; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.Nullable; +import android.text.Html; +import android.text.Spanned; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.Dao; @@ -31,6 +33,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; public class DatabaseHelper extends OrmLiteSqliteOpenHelper { @@ -213,13 +216,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { @Override public String toString() { - Context context = MainApp.instance().getApplicationContext(); - DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0"); - DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); + return MainApp.sResources.getString(R.string.glucose) + " " + DecimalFormatter.to0Decimal(glucose) + " mg/dl\n" + + MainApp.sResources.getString(R.string.delta) + " " + DecimalFormatter.to0Decimal(delta) + " mg/dl\n" + + MainApp.sResources.getString(R.string.avgdelta) + " " + DecimalFormatter.to2Decimal(avgdelta) + " mg/dl"; + } - return context.getString(R.string.glucose) + " " + formatNumber0decimalplaces.format(glucose) + "\n" + - context.getString(R.string.delta) + " " + formatNumber0decimalplaces.format(delta) + "\n" + - context.getString(R.string.avgdelta) + " " + formatNumber2decimalplaces.format(avgdelta); + public Spanned toSpanned() { + return Html.fromHtml("" + MainApp.sResources.getString(R.string.glucose) + ": " + DecimalFormatter.to0Decimal(glucose) + " mg/dl
" + + "" + MainApp.sResources.getString(R.string.delta) + ": " + DecimalFormatter.to0Decimal(delta) + " mg/dl
" + + "" + MainApp.sResources.getString(R.string.avgdelta) + ": " + DecimalFormatter.to2Decimal(avgdelta) + " mg/dl"); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index a82f961ff5..c73ae114ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -61,10 +61,12 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ListView bgsourceListView; ListView pumpListView; ListView loopListView; + TextView loopLabel; ListView treatmentsListView; ListView tempsListView; ListView profileListView; ListView apsListView; + TextView apsLabel; ListView constraintsListView; ListView generalListView; TextView nsclientVerView; @@ -95,6 +97,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList pluginList; + // TODO: sorting + public ConfigBuilderFragment() { super(); registerBus(); @@ -126,10 +130,12 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview); pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview); loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview); + loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel); treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview); tempsListView = (ListView) view.findViewById(R.id.configbuilder_tempslistview); profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview); apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview); + apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel); constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview); generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview); nsclientVerView = (TextView) view.findViewById(R.id.configbuilder_nsclientversion); @@ -144,7 +150,6 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI } void setViews() { - // TODO: hide empty categories bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE), PluginBase.BGSOURCE); bgsourceListView.setAdapter(bgsourceDataAdapter); setListViewHeightBasedOnChildren(bgsourceListView); @@ -154,6 +159,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.LOOP), PluginBase.LOOP); loopListView.setAdapter(loopDataAdapter); setListViewHeightBasedOnChildren(loopListView); + if (MainActivity.getSpecificPluginsList(PluginBase.LOOP).size() == 0) loopLabel.setVisibility(View.GONE); treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TREATMENT), PluginBase.TREATMENT); treatmentsListView.setAdapter(treatmentsDataAdapter); setListViewHeightBasedOnChildren(treatmentsListView); @@ -166,6 +172,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.APS), PluginBase.APS); apsListView.setAdapter(apsDataAdapter); setListViewHeightBasedOnChildren(apsListView); + if (MainActivity.getSpecificPluginsList(PluginBase.APS).size() == 0) apsLabel.setVisibility(View.GONE); constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class), PluginBase.CONSTRAINTS); constraintsListView.setAdapter(constraintsDataAdapter); setListViewHeightBasedOnChildren(constraintsListView); @@ -670,7 +677,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI for (int type = 1; type < PluginBase.LAST; type++) { for (PluginBase p : pluginList) { String settingEnabled = "ConfigBuilder_" + type + "_" + p.getName() + "_Enabled"; - String settingVisible = "ConfigBuilder_" + p.getName() + "_Visible"; + String settingVisible = "ConfigBuilder_" + type + "_" + p.getName() + "_Visible"; editor.putBoolean(settingEnabled, p.isEnabled(type)); editor.putBoolean(settingVisible, p.isVisibleInTabs(type)); } @@ -687,7 +694,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI for (int type = 1; type < PluginBase.LAST; type++) { for (PluginBase p : pluginList) { String settingEnabled = "ConfigBuilder_" + type + "_" + p.getName() + "_Enabled"; - String settingVisible = "ConfigBuilder_" + p.getName() + "_Visible"; + String settingVisible = "ConfigBuilder_" + type + "_" + p.getName() + "_Visible"; if (SP.contains(settingEnabled)) p.setFragmentEnabled(type, SP.getBoolean(settingEnabled, true)); if (SP.contains("ConfigBuilder" + p.getName() + "Visible")) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java index b08e3f1db4..890b4c26c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java @@ -178,7 +178,7 @@ public class DanaConnection { if (timeToConnectTimeSoFar / 60 > 15 || connectionAttemptCount > 180) { Intent alarmServiceIntent = new Intent(MainApp.instance().getApplicationContext(), AlertService.class); - alarmServiceIntent.putExtra("alarmText", MainApp.sResources.getString(R.string.connectionerror)); //TODO: hardcoded string + alarmServiceIntent.putExtra("alarmText", MainApp.sResources.getString(R.string.connectionerror)); MainApp.instance().getApplicationContext().startService(alarmServiceIntent); } waitMsec(1000); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 56d4637229..b992922cde 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.Loop; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; +import android.text.Html; +import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; @@ -11,6 +13,7 @@ import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.utils.DecimalFormatter; /** * Created by mike on 09.06.2016. @@ -23,17 +26,21 @@ public class APSResult implements Parcelable { @Override public String toString() { - Context context = MainApp.instance().getApplicationContext(); - - DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0"); - DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); - if (changeRequested) - return context.getString(R.string.rate) + " " + formatNumber2decimalplaces.format(rate) + " U/h\n" + - context.getString(R.string.duration) + " " + formatNumber0decimalplaces.format(duration) + " min\n" + - context.getString(R.string.reason) + " " + reason; + return MainApp.sResources.getString(R.string.rate) + " " + DecimalFormatter.to2Decimal(rate) + " U/h\n" + + MainApp.sResources.getString(R.string.duration) + " " + DecimalFormatter.to0Decimal(duration) + " min\n" + + MainApp.sResources.getString(R.string.reason) + " " + reason; else - return MainApp.instance().getApplicationContext().getString(R.string.nochangerequested); + return MainApp.sResources.getString(R.string.nochangerequested); + } + + public Spanned toSpanned() { + if (changeRequested) + return Html.fromHtml("" + MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h
" + + "" + MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min
" + + "" + MainApp.sResources.getString(R.string.reason) + ": " + reason); + else + return Html.fromHtml(MainApp.sResources.getString(R.string.nochangerequested)); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index e05dcf9136..4fe9fedeb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -329,9 +329,9 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug @Override public void run() { if (lastRun != null) { - requestView.setText(lastRun.request != null ? lastRun.request.toString() : ""); - constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toString() : ""); - setByPumpView.setText(lastRun.setByPump != null ? lastRun.setByPump.toString() : ""); + requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : ""); + constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : ""); + setByPumpView.setText(lastRun.setByPump != null ? lastRun.setByPump.toSpanned() : ""); sourceView.setText(lastRun.source != null ? lastRun.source : ""); lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : ""); lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : ""); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java index b86b2659d6..bf42a18121 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java @@ -7,6 +7,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -29,6 +30,7 @@ import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; /** @@ -57,7 +59,6 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener public Boolean lastLow = null; public Boolean lastLowProjected = null; public Double lastMinBg = null; - public String lastUnits = null; public DatabaseHelper.GlucoseStatus lastGlucoseStatus = null; public Date lastAPSRun = null; public APSResult lastAPSResult = null; @@ -72,7 +73,6 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener dest.writeInt(lastLow ? 1 : 0); dest.writeInt(lastLowProjected ? 1 : 0); dest.writeDouble(lastMinBg); - dest.writeString(lastUnits); dest.writeParcelable(lastGlucoseStatus, 0); dest.writeLong(lastAPSRun.getTime()); dest.writeParcelable(lastAPSResult, 0); @@ -92,7 +92,6 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener lastLow = in.readInt() == 1; lastLowProjected = in.readInt() == 1; lastMinBg = in.readDouble(); - lastUnits = in.readString(); lastGlucoseStatus = in.readParcelable(DatabaseHelper.GlucoseStatus.class.getClassLoader()); lastAPSRun = new Date(in.readLong()); lastAPSResult = in.readParcelable(APSResult.class.getClassLoader()); @@ -251,10 +250,10 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener minBgDefault = "5"; } - double minBg = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("lowsuspend_lowthreshold", minBgDefault)), profile.getUnits()); + double minBgMgdl = NSProfile.toMgdl(SafeParse.stringToDouble(SP.getString("lowsuspend_lowthreshold", minBgDefault)), profile.getUnits()); - boolean lowProjected = (glucoseStatus.glucose + 6.0 * glucoseStatus.avgdelta) < minBg; - boolean low = glucoseStatus.glucose < minBg; + boolean lowProjected = (glucoseStatus.glucose + 6.0 * glucoseStatus.avgdelta) < minBgMgdl; + boolean low = glucoseStatus.glucose < minBgMgdl; APSResult request = new APSResult(); Double baseBasalRate = pump.getBaseBasalRate(); @@ -293,11 +292,10 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener } lastRun = new LastRun(); - lastRun.lastMinBg = minBg; + lastRun.lastMinBg = minBgMgdl; lastRun.lastLow = low; lastRun.lastLowProjected = lowProjected; lastRun.lastGlucoseStatus = glucoseStatus; - lastRun.lastUnits = profile.getUnits(); lastRun.lastAPSResult = request; lastRun.lastAPSRun = now; updateGUI(); @@ -310,11 +308,10 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener @Override public void run() { if (lastRun != null) { - DecimalFormat formatNumber1decimalplaces = new DecimalFormat("0.0"); - glucoseStatusView.setText(lastRun.lastGlucoseStatus.toString()); - minBgView.setText(formatNumber1decimalplaces.format(lastRun.lastMinBg) + " " + lastRun.lastUnits); - resultView.setText(getString(R.string.lowsuspend_low) + " " + lastRun.lastLow + "\n" + getString(R.string.lowsuspend_lowprojected) + " " + lastRun.lastLowProjected); - requestView.setText(lastRun.lastAPSResult.toString()); + glucoseStatusView.setText(lastRun.lastGlucoseStatus.toSpanned()); + minBgView.setText(DecimalFormatter.to1Decimal(lastRun.lastMinBg) + " mgdl"); + resultView.setText(Html.fromHtml("" + getString(R.string.lowsuspend_low) + ": " + lastRun.lastLow + "
" + getString(R.string.lowsuspend_lowprojected) + ": " + lastRun.lastLowProjected)); + requestView.setText(lastRun.lastAPSResult.toSpanned()); lastRunView.setText(lastRun.lastAPSRun.toLocaleString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java index 7b0ad5e6db..30cd7b1488 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java @@ -14,6 +14,7 @@ import android.widget.Button; import android.widget.TextView; import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +36,7 @@ import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.JSONFormatter; import info.nightscout.utils.Round; import info.nightscout.utils.SafeParse; @@ -304,13 +306,13 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, @Override public void run() { if (lastRun != null) { - glucoseStatusView.setText(lastRun.lastDetermineBasalAdapterJS.getGlucoseStatusParam()); - currentTempView.setText(lastRun.lastDetermineBasalAdapterJS.getCurrentTempParam()); - iobDataView.setText(lastRun.lastDetermineBasalAdapterJS.getIobDataParam()); - profileView.setText(lastRun.lastDetermineBasalAdapterJS.getProfileParam()); - mealDataView.setText(lastRun.lastDetermineBasalAdapterJS.getMealDataParam()); - resultView.setText(lastRun.lastAPSResult.json.toString()); - requestView.setText(lastRun.lastAPSResult.toString()); + glucoseStatusView.setText(JSONFormatter.format(lastRun.lastDetermineBasalAdapterJS.getGlucoseStatusParam())); + currentTempView.setText(JSONFormatter.format(lastRun.lastDetermineBasalAdapterJS.getCurrentTempParam())); + iobDataView.setText(JSONFormatter.format(lastRun.lastDetermineBasalAdapterJS.getIobDataParam())); + profileView.setText(JSONFormatter.format(lastRun.lastDetermineBasalAdapterJS.getProfileParam())); + mealDataView.setText(JSONFormatter.format(lastRun.lastDetermineBasalAdapterJS.getMealDataParam())); + resultView.setText(JSONFormatter.format(lastRun.lastAPSResult.json)); + requestView.setText(lastRun.lastAPSResult.toSpanned()); lastRunView.setText(lastRun.lastAPSRun.toLocaleString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 05026e0f17..d6f0414e25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -7,6 +7,7 @@ import android.graphics.DashPathEffect; import android.graphics.Paint; import android.os.Bundle; import android.os.Handler; +import android.os.HandlerThread; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; @@ -88,11 +89,17 @@ public class OverviewFragment extends Fragment implements PluginBase { Handler loopHandler = new Handler(); Runnable refreshLoop = null; + Handler mHandler; + public static HandlerThread mHandlerThread; + public Double bgTargetLow = 80d; public Double bgTargetHigh = 180d; public OverviewFragment() { super(); + mHandlerThread = new HandlerThread(OverviewFragment.class.getSimpleName()); + mHandlerThread.start(); + mHandler = new Handler(mHandlerThread.getLooper()); registerBus(); } @@ -203,10 +210,15 @@ public class OverviewFragment extends Fragment implements PluginBase { cancelTempButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); + final PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); if (pump.isTempBasalInProgress()) { - pump.cancelTempBasal(); - MainApp.bus().post(new EventTempBasalChange()); + mHandler.post(new Runnable() { + @Override + public void run() { + pump.cancelTempBasal(); + MainApp.bus().post(new EventTempBasalChange()); + } + }); } } }); @@ -240,19 +252,24 @@ public class OverviewFragment extends Fragment implements PluginBase { builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed); - if (applyResult.enacted) { - finalLastRun.setByPump = applyResult; - finalLastRun.lastEnact = new Date(); - finalLastRun.lastOpenModeAccept = new Date(); - MainApp.getConfigBuilder().uploadDeviceStatus(); - ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class); - if (objectivesFragment != null) { - objectivesFragment.manualEnacts++; - objectivesFragment.saveProgress(); + mHandler.post(new Runnable() { + @Override + public void run() { + PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed); + if (applyResult.enacted) { + finalLastRun.setByPump = applyResult; + finalLastRun.lastEnact = new Date(); + finalLastRun.lastOpenModeAccept = new Date(); + MainApp.getConfigBuilder().uploadDeviceStatus(); + ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class); + if (objectivesFragment != null) { + objectivesFragment.manualEnacts++; + objectivesFragment.saveProgress(); + } + } + updateGUI(); } - } - updateGUI(); + }); } }); builder.setNegativeButton(getContext().getString(R.string.cancel), null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java index 6300c5d7f9..066c16d3ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java @@ -417,7 +417,7 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa public void run() { recyclerView.swapAdapter(new RecyclerViewAdapter(getMergedList()), false); if (lastCalculation != null) { - String totalText = formatNumber2decimalplaces.format(lastCalculation.basaliob) + "U"; + String totalText = formatNumber2decimalplaces.format(lastCalculation.basaliob) + " U"; tempBasalTotalView.setText(totalText); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index 6fd8747820..b0457da35c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -13,6 +13,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.TextView; import com.j256.ormlite.dao.Dao; @@ -215,6 +216,10 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia()); holder.iob.setText(formatNumber2decimalplaces.format(iob.iobContrib) + " U"); holder.activity.setText(formatNumber3decimalplaces.format(iob.activityContrib) + " U"); + if (iob.iobContrib != 0) + holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB)); + else + holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground)); } @Override @@ -234,6 +239,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener TextView carbs; TextView iob; TextView activity; + LinearLayout dateLinearLayout; TreatmentsViewHolder(View itemView) { super(itemView); @@ -243,6 +249,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener carbs = (TextView) itemView.findViewById(R.id.treatments_carbs); iob = (TextView) itemView.findViewById(R.id.treatments_iob); activity = (TextView) itemView.findViewById(R.id.treatments_activity); + dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout); } } } @@ -333,9 +340,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener public void run() { recyclerView.swapAdapter(new RecyclerViewAdapter(treatments), false); if (lastCalculation != null) - iobTotal.setText(formatNumber2decimalplaces.format(lastCalculation.iob)); + iobTotal.setText(formatNumber2decimalplaces.format(lastCalculation.iob) + " U"); if (lastCalculation != null) - activityTotal.setText(formatNumber3decimalplaces.format(lastCalculation.activity)); + activityTotal.setText(formatNumber3decimalplaces.format(lastCalculation.activity) + " U"); } }); } diff --git a/app/src/main/java/info/nightscout/utils/DecimalFormatter.java b/app/src/main/java/info/nightscout/utils/DecimalFormatter.java new file mode 100644 index 0000000000..1a70b43c30 --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/DecimalFormatter.java @@ -0,0 +1,29 @@ +package info.nightscout.utils; + +import java.text.DecimalFormat; + +/** + * Created by mike on 11.07.2016. + */ +public class DecimalFormatter { + private static DecimalFormat format0dec = new DecimalFormat("0"); + private static DecimalFormat format1dec = new DecimalFormat("0.0"); + private static DecimalFormat format2dec = new DecimalFormat("0.00"); + private static DecimalFormat format3dec = new DecimalFormat("0.000"); + + public static String to0Decimal(double value) { + return format0dec.format(value); + } + + public static String to1Decimal(double value) { + return format1dec.format(value); + } + + public static String to2Decimal(double value) { + return format2dec.format(value); + } + + public static String to3Decimal(double value) { + return format3dec.format(value); + } +} diff --git a/app/src/main/java/info/nightscout/utils/JsonFormatter.java b/app/src/main/java/info/nightscout/utils/JsonFormatter.java new file mode 100644 index 0000000000..b4e3bf48dd --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/JsonFormatter.java @@ -0,0 +1,101 @@ +package info.nightscout.utils; + +import android.text.Html; +import android.text.Spanned; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +/** + * Created by mike on 11.07.2016. + */ +public class JSONFormatter { + + public static Spanned format(final String jsonString) { + final JsonVisitor visitor = new JsonVisitor(4, ' '); + try { + return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0)); + } catch (JSONException e) { + e.printStackTrace(); + return Html.fromHtml(""); + } + } + + public static Spanned format(final JSONObject object) { + final JsonVisitor visitor = new JsonVisitor(4, ' '); + try { + return Html.fromHtml(visitor.visit(object, 0)); + } catch (JSONException e) { + e.printStackTrace(); + return Html.fromHtml(""); + } + } + + private static class JsonVisitor { + private final int indentationSize; + private final char indentationChar; + + public JsonVisitor(final int indentationSize, final char indentationChar) { + this.indentationSize = indentationSize; + this.indentationChar = indentationChar; + } + + private String visit(final JSONArray array, final int indent) throws JSONException { + String ret = ""; + final int length = array.length(); + if (length == 0) { + } else { + ret += write("[", indent); + for (int i = 0; i < length; i++) { + ret += visit(array.get(i), indent + 1); + } + ret += write("]", indent); + } + return ret; + } + + private String visit(final JSONObject obj, final int indent) throws JSONException { + String ret = ""; + final int length = obj.length(); + if (length == 0) { + } else { + final Iterator keys = obj.keys(); + while (keys.hasNext()) { + final String key = keys.next(); + ret += write("" + key + ": ", indent + 1); + ret += visit(obj.get(key), 0); + ret += "
"; + } + } + return ret; + } + + private String visit(final Object object, final int indent) throws JSONException { + String ret = ""; + if (object instanceof JSONArray) { + ret += visit((JSONArray) object, indent); + } else if (object instanceof JSONObject) { + ret += visit((JSONObject) object, indent); + } else { + if (object instanceof String) { + ret += write("\"" + (String) object + "\"", indent); + } else { + ret += write(String.valueOf(object), indent); + } + } + return ret; + } + + private String write(final String data, final int indent) { + String ret = ""; + for (int i = 0; i < (indent * indentationSize); i++) { + ret += indentationChar; + } + ret += data; + return ret; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml index a6c12858e9..f57f14e200 100644 --- a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml +++ b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml @@ -583,7 +583,6 @@ @@ -41,13 +41,13 @@ @@ -57,7 +57,7 @@ android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/configbuilder_bgsource" - android:textAppearance="?android:attr/textAppearanceMedium" + android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="bold" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:layout_marginLeft="5dp" /> + android:layout_marginLeft="5dp" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:layout_marginLeft="5dp" /> + android:layout_marginLeft="5dp" /> + android:layout_marginLeft="5dp" /> + android:layout_marginLeft="5dp" /> + android:layout_marginLeft="5dp" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> + android:layout_height="match_parent" + android:orientation="vertical"> + android:paddingLeft="10dp" + android:textAppearance="?android:attr/textAppearanceMedium" /> diff --git a/app/src/main/res/layout/tempbasals_item.xml b/app/src/main/res/layout/tempbasals_item.xml index a938be11b8..796865e343 100644 --- a/app/src/main/res/layout/tempbasals_item.xml +++ b/app/src/main/res/layout/tempbasals_item.xml @@ -16,11 +16,22 @@ android:orientation="vertical"> + android:orientation="horizontal"> + + + + android:textColor="@color/cardItemLabel" /> + android:textColor="@color/cardItemLabel" /> + android:textColor="@color/cardItemLabel" /> + android:textColor="@color/cardItemLabel" /> + android:paddingRight="5dp" + android:text="E" + android:textColor="@color/colorSetExtendedButton" /> @@ -81,19 +92,20 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" + android:paddingLeft="10dp" android:paddingRight="5dp" android:text="@string/tempbasals_realduration_label_string" - android:textAppearance="?android:attr/textAppearanceMedium" - android:textStyle="bold" - android:paddingLeft="10dp" /> + + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textStyle="bold" /> + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textStyle="bold" /> + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textStyle="bold" /> + + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:text="0.12 U" + android:textStyle="bold" /> diff --git a/app/src/main/res/layout/treatments_fragment.xml b/app/src/main/res/layout/treatments_fragment.xml index 3c991d1fab..3d6a4d45ec 100644 --- a/app/src/main/res/layout/treatments_fragment.xml +++ b/app/src/main/res/layout/treatments_fragment.xml @@ -5,31 +5,31 @@ tools:context=".plugins.Treatments.TreatmentsFragment"> + android:layout_height="match_parent" + android:orientation="vertical"> + android:paddingLeft="10dp" + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:paddingLeft="10dp" + android:textAppearance="?android:attr/textAppearanceMedium" /> +