diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt index 419e63f745..d64e3ed903 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt @@ -10,9 +10,12 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.UserEntry +import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.extensions.stringId import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers @@ -26,6 +29,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() { @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var translator: Translator private val disposable = CompositeDisposable() @@ -68,13 +72,22 @@ class TreatmentsUserEntryFragment : DaggerFragment() { holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp) holder.binding.action.text = resourceHelper.gs(current.action.stringId()) if (current.s != "") holder.binding.s.text = current.s else holder.binding.s.visibility = View.GONE - /* - if (current.d1 != 0.0) holder.binding.d1.text = current.d1.toString() else holder.binding.d1.visibility = View.GONE - if (current.d2 != 0.0) holder.binding.d2.text = current.d2.toString() else holder.binding.d2.visibility = View.GONE - if (current.i1 != 0) holder.binding.i1.text = current.i1.toString() else holder.binding.i1.visibility = View.GONE - if (current.i2 != 0) holder.binding.i2.text = current.i2.toString() else holder.binding.i2.visibility = View.GONE - - */ + //holder.binding.s.text = current.toString() //for debug + var valuesWithUnitString = "" + for(v in current.values) { + when (v.unit) { + Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + " " + Units.CPEvent -> valuesWithUnitString += translator.translate(v.sValue) + " " + Units.R_String -> valuesWithUnitString += resourceHelper.gs(v.iValue) + " " + Units.Mg_Dl -> valuesWithUnitString += DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.Mg_Dl.stringId()) + " " + Units.Mmol_L -> valuesWithUnitString += DecimalFormatter.to1Decimal(v.dValue) + resourceHelper.gs(Units.Mmol_L.stringId()) + " " + Units.G -> valuesWithUnitString += DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.G.stringId()) + " " + else -> valuesWithUnitString += if (!v.value().equals(0) && !v.value().equals("")) { v.value().toString() + if (!v.unit.stringId().equals(0)) resourceHelper.gs(v.unit.stringId()) + " " else " " } else "" + } + } + if (current.values.size > 0) + holder.binding.values.visibility = View.VISIBLE + holder.binding.values.text = valuesWithUnitString } inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/app/src/main/res/layout/treatments_user_entry_item.xml b/app/src/main/res/layout/treatments_user_entry_item.xml index a3c3870c9a..1d0d65616c 100644 --- a/app/src/main/res/layout/treatments_user_entry_item.xml +++ b/app/src/main/res/layout/treatments_user_entry_item.xml @@ -1,70 +1,80 @@ - + android:layout_gravity="center" + card_view:cardBackgroundColor="?android:colorBackground"> - + android:orientation="vertical"> - + - + - + - + - + - + - + + + + + + + + + diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 4c1d556769..54a00d4ca1 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -119,7 +119,7 @@ mg/dl mmol/l g - %% + % Advanced Settings Bluetooth BT Watchdog diff --git a/database/src/main/java/info/nightscout/androidaps/database/Converters.kt b/database/src/main/java/info/nightscout/androidaps/database/Converters.kt index 04d5cb9901..3919742e6c 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/Converters.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/Converters.kt @@ -23,10 +23,7 @@ class Converters { val jsonArray = JSONArray() values.forEach { val jsonObject = JSONObject() - if (!it.dValue.equals(0.0)) jsonObject.put("dValue", it.dValue).put("unit", it.unit.name) - if (!it.iValue.equals(0)) jsonObject.put("iValue", it.iValue).put("unit", it.unit.name) - if (!it.lValue.equals(0)) jsonObject.put("lValue", it.lValue).put("unit", it.unit.name) - if (!it.sValue.equals("")) jsonObject.put("sValue", it.sValue).put("unit", it.unit.name) + jsonObject.put("dValue", it.dValue).put("iValue", it.iValue).put("lValue", it.lValue).put("sValue", it.sValue).put("unit", it.unit.name) jsonArray.put(jsonObject) } return jsonArray.toString() @@ -39,10 +36,7 @@ class Converters { val list = mutableListOf() for (i in 0 until jsonArray.length()) { val jsonObject = jsonArray.getJSONObject(i) - if (jsonObject.has("dValue")) list.add(ValueWithUnit(jsonObject.getDouble("dValue"), jsonObject.getString("unit"))) - if (jsonObject.has("iValue")) list.add(ValueWithUnit(jsonObject.getDouble("iValue"), jsonObject.getString("unit"))) - if (jsonObject.has("lValue")) list.add(ValueWithUnit(jsonObject.getDouble("lValue"), jsonObject.getString("unit"))) - if (jsonObject.has("sValue")) list.add(ValueWithUnit(jsonObject.getDouble("sValue"), jsonObject.getString("unit"))) + list.add(ValueWithUnit(jsonObject.getDouble("dValue"), jsonObject.getInt("iValue"), jsonObject.getLong("lValue"), jsonObject.getString("sValue"), Units.fromString(jsonObject.getString("unit")))) } return list }