Fix Converters.kt
Initialize a first version of Layout with Card and TreamentsUserEntryFragment
This commit is contained in:
parent
df995724a7
commit
f226a03c83
4 changed files with 90 additions and 73 deletions
|
@ -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) {
|
||||
|
|
|
@ -1,70 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
android:layout_gravity="center"
|
||||
card_view:cardBackgroundColor="?android:colorBackground">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:text="1.1.2021 09:00"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="USER ENTRY"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/s"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:text="1.1.2021 09:00"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/d1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="0.0"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
<TextView
|
||||
android:id="@+id/action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="USER ENTRY"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/d2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="0.0"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/i1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="0.0"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/i2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:text="0.0"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
<TextView
|
||||
android:id="@+id/values"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:visibility="gone"
|
||||
android:text="Values with units" />
|
||||
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/s"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:ignore="HardcodedText,RtlSymmetry" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@color/list_delimiter" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
<string name="mgdl">mg/dl</string>
|
||||
<string name="mmol">mmol/l</string>
|
||||
<string name="shortgram">g</string>
|
||||
<string name="shortpercent">%%</string>
|
||||
<string name="shortpercent">%</string>
|
||||
<string name="advancedsettings_title">Advanced Settings</string>
|
||||
<string name="bluetooth">Bluetooth</string>
|
||||
<string name="btwatchdog_title">BT Watchdog</string>
|
||||
|
|
|
@ -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<UserEntry.ValueWithUnit>()
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue