From c3d593f7ae5d4dd66a4b3fee2dbf9ec701a19543 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 21 Mar 2021 19:14:42 +0100 Subject: [PATCH] Start implementation of Source --- .../fragments/TreatmentsUserEntryFragment.kt | 7 +++++-- .../androidaps/database/entities/UserEntry.kt | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) 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 5a7c6432f1..3859f37c83 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 @@ -111,8 +111,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() { override fun onBindViewHolder(holder: UserEntryViewHolder, position: Int) { val current = entries[position] holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp) - holder.binding.action.text = translator.translate(current.action.name) - holder.binding.action.setTextColor(resourceHelper.gc(current.action.colorGroup.colorId())) + if (current.s != "") { holder.binding.s.text = current.s holder.binding.s.visibility = View.VISIBLE @@ -121,6 +120,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() { var valuesWithUnitString = "" var rStringParam = 0 val separator = " " + var source = "" for(v in current.values) { if (rStringParam >0) rStringParam-- @@ -144,11 +144,14 @@ class TreatmentsUserEntryFragment : DaggerFragment() { -> valuesWithUnitString += DecimalFormatter.to2Decimal(v.dValue) + translator.translate(v.unit.name) + separator Units.G, Units.M, Units.H, Units.Percent -> valuesWithUnitString += v.iValue.toString() + translator.translate(v.unit.name) + separator + Units.Source -> source = separator + translator.translate(v.sValue) else -> valuesWithUnitString += if (v.iValue != 0 || v.sValue != "") { v.value().toString() + separator } else "" } } holder.binding.values.text = valuesWithUnitString.trim() holder.binding.values.visibility = if (current.values.size > 0) View.VISIBLE else View.GONE + holder.binding.action.text = translator.translate(current.action.name) + source + holder.binding.action.setTextColor(resourceHelper.gc(current.action.colorGroup.colorId())) } inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt index ff990de675..a93401b7ba 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt @@ -141,7 +141,8 @@ data class UserEntry( @SerializedName("H") H ("h"), //Int @SerializedName("Percent") Percent ("%"), //Int @SerializedName("TherapyEvent") TherapyEvent ("TherapyEvent"), //String (All enum key translated by Translator function, mainly TherapyEvent) - @SerializedName("R_String") R_String ("R.string") //Int + @SerializedName("R_String") R_String ("R.string"), //Int + @SerializedName("Source") Source ("Source") //String ; companion object { @@ -149,6 +150,23 @@ data class UserEntry( fun fromText(unit: String?) = values().firstOrNull { it.text == unit } ?: None } } + enum class Sources(val text: String) { + @SerializedName("Manual") Manual ("Manual"), //Manual entry by user, given through AAPS (default) + @SerializedName("External") External ("External"), //Manual entry by user, treatment given outside AAPS (for example Bolus with Serynge) + @SerializedName("Automation") Automation ("Automation"), //From Automation plugin + @SerializedName("Loop") Loop ("Loop"), //From Loop plugin + @SerializedName("NS") NS ("NS"), //From NSClient plugin + @SerializedName("Pump") Pump ("Pump"), //From Pump plugin (for example from pump history) + @SerializedName("SMS") SMS ("SMS"), //From SMS plugin + @SerializedName("Wear") Wear ("Wear"), //From Wear plugin + @SerializedName("Unknown") Unknown ("Unknown") //if necessary + ; + + companion object { + fun fromString(source: String?) = values().firstOrNull { it.name == source } ?: Unknown + fun fromText(source: String?) = values().firstOrNull { it.text == source } ?: Unknown + } + } enum class ColorGroup() { InsulinTreatment,