UserEntryPresentationHelper
This commit is contained in:
parent
60f51cfab9
commit
7db2e112ee
7 changed files with 116 additions and 59 deletions
|
@ -42,6 +42,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
@Inject lateinit var translator: Translator
|
@Inject lateinit var translator: Translator
|
||||||
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
@Inject lateinit var userEntryPresentationHelper: UserEntryPresentationHelper
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -112,9 +113,9 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
val current = entries[position]
|
val current = entries[position]
|
||||||
holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp)
|
holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp)
|
||||||
holder.binding.action.text = translator.translate(current.action)
|
holder.binding.action.text = translator.translate(current.action)
|
||||||
holder.binding.action.setTextColor(resourceHelper.gc(current.action.colorGroup.colorId()))
|
holder.binding.action.setTextColor(resourceHelper.gc(userEntryPresentationHelper.colorId(current.action.colorGroup)))
|
||||||
if (current.s != "") {
|
if (current.remark != "") {
|
||||||
holder.binding.s.text = current.s
|
holder.binding.s.text = current.remark
|
||||||
holder.binding.s.visibility = View.VISIBLE
|
holder.binding.s.visibility = View.VISIBLE
|
||||||
} else
|
} else
|
||||||
holder.binding.s.visibility = View.GONE
|
holder.binding.s.visibility = View.GONE
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ClassicPrefsFormat @Inject constructor(
|
||||||
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
|
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
|
||||||
dateUtil.timeString(entry.utcOffset) + ";" +
|
dateUtil.timeString(entry.utcOffset) + ";" +
|
||||||
csvString(entry.action) + ";" +
|
csvString(entry.action) + ";" +
|
||||||
csvString(entry.s) + ";" +
|
csvString(entry.remark) + ";" +
|
||||||
valueWithUnitToCsv(value)
|
valueWithUnitToCsv(value)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +104,7 @@ class ClassicPrefsFormat @Inject constructor(
|
||||||
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
|
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
|
||||||
dateUtil.timeString(entry.utcOffset) + ";" +
|
dateUtil.timeString(entry.utcOffset) + ";" +
|
||||||
csvString(entry.action) + ";" +
|
csvString(entry.action) + ";" +
|
||||||
csvString(entry.s) + ";;"
|
csvString(entry.remark) + ";;"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils.extensions
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.core.R
|
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.*
|
|
||||||
|
|
||||||
fun ColorGroup.colorId(): Int {
|
|
||||||
return when (this) {
|
|
||||||
ColorGroup.InsulinTreatment -> R.color.basal
|
|
||||||
ColorGroup.CarbTreatment -> R.color.carbs
|
|
||||||
ColorGroup.TT -> R.color.tempTargetConfirmation
|
|
||||||
ColorGroup.Profile -> R.color.white
|
|
||||||
ColorGroup.Loop -> R.color.loopClosed
|
|
||||||
ColorGroup.Careportal -> R.color.high
|
|
||||||
ColorGroup.Pump -> R.color.iob
|
|
||||||
ColorGroup.Aaps -> R.color.defaulttext
|
|
||||||
else -> R.color.defaulttext
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package info.nightscout.androidaps.utils.extensions
|
||||||
|
|
||||||
|
import dagger.Reusable
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.core.R
|
||||||
|
import info.nightscout.androidaps.database.entities.Translator
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry.ColorGroup
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry.Units
|
||||||
|
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Reusable
|
||||||
|
class UserEntryPresentationHelper @Inject constructor(
|
||||||
|
private val translator: Translator,
|
||||||
|
private val profileFunction: ProfileFunction,
|
||||||
|
private val resourceHelper: ResourceHelper,
|
||||||
|
private val dateUtil: DateUtil
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun colorId(colorGroup: ColorGroup): Int = when (colorGroup) {
|
||||||
|
ColorGroup.InsulinTreatment -> R.color.basal
|
||||||
|
ColorGroup.CarbTreatment -> R.color.carbs
|
||||||
|
ColorGroup.TT -> R.color.tempTargetConfirmation
|
||||||
|
ColorGroup.Profile -> R.color.white
|
||||||
|
ColorGroup.Loop -> R.color.loopClosed
|
||||||
|
ColorGroup.Careportal -> R.color.high
|
||||||
|
ColorGroup.Pump -> R.color.iob
|
||||||
|
ColorGroup.Aaps -> R.color.defaulttext
|
||||||
|
else -> R.color.defaulttext
|
||||||
|
}
|
||||||
|
|
||||||
|
fun listToPresentationString(list: List<XXXValueWithUnit>) =
|
||||||
|
list.joinToString(separator = " ", transform = this::toPresentationString)
|
||||||
|
|
||||||
|
private fun toPresentationString(valueWithUnit: XXXValueWithUnit): String = when (valueWithUnit) {
|
||||||
|
is XXXValueWithUnit.Gram -> "${valueWithUnit.value} ${translator.translate(Units.G)}"
|
||||||
|
is XXXValueWithUnit.Hour -> "${valueWithUnit.value} ${translator.translate(Units.H)}"
|
||||||
|
is XXXValueWithUnit.Minute -> "${valueWithUnit.value} ${translator.translate(Units.G)}"
|
||||||
|
is XXXValueWithUnit.Percent -> "${valueWithUnit.value} ${translator.translate(Units.Percent)}"
|
||||||
|
is XXXValueWithUnit.Insulin -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(UserEntry.Units.U)
|
||||||
|
is XXXValueWithUnit.UnitPerHour -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(UserEntry.Units.U_H)
|
||||||
|
is XXXValueWithUnit.SimpleInt -> valueWithUnit.value.toString()
|
||||||
|
is XXXValueWithUnit.SimpleString -> valueWithUnit.value
|
||||||
|
is XXXValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map(this::toPresentationString))
|
||||||
|
is XXXValueWithUnit.TherapyEventMeterType -> translator.translate(valueWithUnit.value)
|
||||||
|
is XXXValueWithUnit.TherapyEventTTReason -> translator.translate(valueWithUnit.value)
|
||||||
|
is XXXValueWithUnit.TherapyEventType -> translator.translate(valueWithUnit.value)
|
||||||
|
is XXXValueWithUnit.Timestamp -> dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value)
|
||||||
|
|
||||||
|
is XXXValueWithUnit.Mgdl -> {
|
||||||
|
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(Units.Mg_Dl)
|
||||||
|
else DecimalFormatter.to1Decimal(valueWithUnit.value / Constants.MMOLL_TO_MGDL) + translator.translate(Units.Mmol_L)
|
||||||
|
}
|
||||||
|
|
||||||
|
is XXXValueWithUnit.Mmoll -> {
|
||||||
|
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(Units.Mmol_L)
|
||||||
|
else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + translator.translate(Units.Mg_Dl)
|
||||||
|
}
|
||||||
|
|
||||||
|
XXXValueWithUnit.UNKNOWN -> ""
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,8 @@ data class UserEntry(
|
||||||
override var timestamp: Long,
|
override var timestamp: Long,
|
||||||
override var utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong(),
|
override var utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong(),
|
||||||
var action: Action,
|
var action: Action,
|
||||||
var s: String,
|
var remark: String,
|
||||||
|
val sources: Sources,
|
||||||
var values: MutableList<ValueWithUnit>
|
var values: MutableList<ValueWithUnit>
|
||||||
) : DBEntry, DBEntryWithTime {
|
) : DBEntry, DBEntryWithTime {
|
||||||
enum class Action (val colorGroup: ColorGroup) {
|
enum class Action (val colorGroup: ColorGroup) {
|
||||||
|
|
|
@ -46,39 +46,6 @@ sealed class XXXValueWithUnit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<XXXValueWithUnit>.toPresentationString(translator: Translator) =
|
|
||||||
joinToString(separator = " ") { it.toPresentationString(translator) }
|
|
||||||
|
|
||||||
// TODO Move to destination module, then uncomment
|
|
||||||
fun XXXValueWithUnit.toPresentationString(translator: Translator) : String = when(this){
|
|
||||||
is XXXValueWithUnit.Gram -> "$value ${translator.translate(UserEntry.Units.G)}"
|
|
||||||
is XXXValueWithUnit.Hour -> "$value ${translator.translate(UserEntry.Units.H)}"
|
|
||||||
is XXXValueWithUnit.Minute -> "$value ${translator.translate(UserEntry.Units.G)}"
|
|
||||||
is XXXValueWithUnit.Percent -> "$value ${translator.translate(UserEntry.Units.Percent)}"
|
|
||||||
is XXXValueWithUnit.Insulin -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U)
|
|
||||||
is XXXValueWithUnit.UnitPerHour -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U_H)
|
|
||||||
is XXXValueWithUnit.SimpleInt -> value.toString()
|
|
||||||
is XXXValueWithUnit.SimpleString -> value
|
|
||||||
is XXXValueWithUnit.StringResource -> "" //resourceHelper.gs(value, params.map { it.toPresentationString(translator) }) // recursively resolve params
|
|
||||||
is XXXValueWithUnit.TherapyEventMeterType -> translator.translate(value)
|
|
||||||
is XXXValueWithUnit.TherapyEventTTReason -> translator.translate(value)
|
|
||||||
is XXXValueWithUnit.TherapyEventType -> translator.translate(value)
|
|
||||||
is XXXValueWithUnit.Timestamp -> "" // TODO dateUtil.dateAndTimeAndSecondsString(value)
|
|
||||||
is XXXValueWithUnit.Mgdl -> {
|
|
||||||
// if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mg_Dl)
|
|
||||||
// else DecimalFormatter.to1Decimal(value/Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mmol_L)
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
is XXXValueWithUnit.Mmoll -> {
|
|
||||||
// if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mmol_L)
|
|
||||||
// else DecimalFormatter.to1Decimal(value * Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mg_Dl)
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
XXXValueWithUnit.UNKNOWN -> ""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -105,3 +72,43 @@ interface Translator {
|
||||||
fun translate(type: TherapyEvent.Type): String
|
fun translate(type: TherapyEvent.Type): String
|
||||||
fun translate(reason: TemporaryTarget.Reason): String
|
fun translate(reason: TemporaryTarget.Reason): String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class Sources(val text: String) {
|
||||||
|
@SerializedName("TreatmentDialog") TreatmentDialog ("TreatmentDialog"),
|
||||||
|
@SerializedName("InsulinDialog") InsulinDialog ("InsulinDialog"),
|
||||||
|
@SerializedName("CarbDialog") CarbDialog ("CarbDialog"),
|
||||||
|
@SerializedName("WizardDialog") WizardDialog ("WizardDialog"),
|
||||||
|
@SerializedName("QuickWizard") QuickWizard ("QuickWizard"),
|
||||||
|
@SerializedName("ExtendedBolusDialog") ExtendedBolusDialog ("ExtendedBolusDialog"),
|
||||||
|
@SerializedName("TTDialog") TTDialog ("TTDialog"),
|
||||||
|
@SerializedName("ProfileSwitchDialog") ProfileSwitchDialog ("ProfileSwitchDialog"),
|
||||||
|
@SerializedName("LoopDialog") LoopDialog ("LoopDialog"),
|
||||||
|
@SerializedName("TempBasalDialog") TempBasalDialog ("TempBasalDialog"),
|
||||||
|
@SerializedName("CalibrationDialog") CalibrationDialog ("CalibrationDialog"),
|
||||||
|
@SerializedName("FillDialog") FillDialog ("FillDialog"),
|
||||||
|
@SerializedName("BgCheck") BgCheck ("BgCheck"),
|
||||||
|
@SerializedName("SensorInsert") SensorInsert ("SensorInsert"),
|
||||||
|
@SerializedName("BatteryChange") BatteryChange ("BatteryChange"),
|
||||||
|
@SerializedName("Note") Note ("Note"),
|
||||||
|
@SerializedName("Exercise") Exercise ("Exercise"),
|
||||||
|
@SerializedName("Question") Question ("Question"),
|
||||||
|
@SerializedName("Announcement") Announcement ("Announcement"),
|
||||||
|
@SerializedName("Actions") Actions ("Actions"), //From Actions plugin
|
||||||
|
@SerializedName("Automation") Automation ("Automation"), //From Automation plugin
|
||||||
|
@SerializedName("LocalProfile") LocalProfile ("LocalProfile"), //From LocalProfile plugin
|
||||||
|
@SerializedName("Loop") Loop ("Loop"), //From Loop plugin
|
||||||
|
@SerializedName("Maintenance") Maintenance ("Maintenance"), //From Maintenance plugin
|
||||||
|
@SerializedName("NSClient") NSClient ("NSClient"), //From NSClient plugin
|
||||||
|
@SerializedName("Pump") Pump ("Pump"), //From Pump plugin (for example from pump history)
|
||||||
|
@SerializedName("SMS") SMS ("SMS"), //From SMS plugin
|
||||||
|
@SerializedName("Treatments") Treatments ("Treatments"), //From Treatments plugin
|
||||||
|
@SerializedName("Wear") Wear ("Wear"), //From Wear plugin
|
||||||
|
@SerializedName("Food") Food ("Food"), //From Food 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ class UserEntryTransaction(
|
||||||
database.userEntryDao.insert(UserEntry(
|
database.userEntryDao.insert(UserEntry(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
action = action,
|
action = action,
|
||||||
s = s,
|
remark = s,
|
||||||
values = values
|
values = values
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue