Merge branch 'meallink_ValueWithUnit' of https://github.com/Philoul/AndroidAPS into meallink_ValueWithUnit

This commit is contained in:
AdrianLxM 2021-04-03 21:34:41 +02:00
commit d62456f2e2
14 changed files with 106 additions and 58 deletions

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.Food
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction
import info.nightscout.androidaps.databinding.FoodFragmentBinding
import info.nightscout.androidaps.databinding.FoodItemBinding
@ -75,7 +76,8 @@ class FoodFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener {
context?.let { context ->
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", {
uel.log(Action.FOOD, Sources.Food)
uel.log(Action.FOOD, Sources.Food,
XXXValueWithUnit.StringResource(R.string.refresheventsfromnightscout))
disposable += Completable.fromAction { repository.deleteAllFoods() }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)

View file

@ -1,13 +1,14 @@
package info.nightscout.androidaps;
import info.nightscout.androidaps.database.entities.XXXValueWithUnit;
import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 07.06.2016.
*/
public class Constants {
public static final String MGDL = "mg/dl"; // This is Nightscout's representation
public static final String MMOL = "mmol";
public static final String MGDL = XXXValueWithUnit.MGDL; // This is Nightscout's representation
public static final String MMOL = XXXValueWithUnit.MMOL;
public static final double MMOLL_TO_MGDL = 18; // 18.0182;
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;

View file

@ -207,6 +207,49 @@ class Translator @Inject internal constructor(
Sources.ConfigBuilder -> TODO()
Sources.Overview -> TODO()
Sources.Stats -> TODO()
Sources.TreatmentDialog -> TODO()
Sources.InsulinDialog -> TODO()
Sources.CarbDialog -> TODO()
Sources.WizardDialog -> TODO()
Sources.QuickWizard -> TODO()
Sources.ExtendedBolusDialog -> TODO()
Sources.TTDialog -> TODO()
Sources.ProfileSwitchDialog -> TODO()
Sources.LoopDialog -> TODO()
Sources.TempBasalDialog -> TODO()
Sources.CalibrationDialog -> TODO()
Sources.FillDialog -> TODO()
Sources.BgCheck -> TODO()
Sources.SensorInsert -> TODO()
Sources.BatteryChange -> TODO()
Sources.Note -> TODO()
Sources.Exercise -> TODO()
Sources.Question -> TODO()
Sources.Announcement -> TODO()
Sources.Actions -> TODO()
Sources.BG -> TODO()
Sources.LocalProfile -> TODO()
Sources.Maintenance -> TODO()
Sources.NSProfile -> TODO()
Sources.Objectives -> TODO()
Sources.Dana -> TODO()
Sources.DanaR -> TODO()
Sources.DanaRC -> TODO()
Sources.DanaRv2 -> TODO()
Sources.DanaRS -> TODO()
Sources.Insight -> TODO()
Sources.Combo -> TODO()
Sources.Medtronic -> TODO()
Sources.Omnipod -> TODO()
Sources.OmnipodEros -> TODO()
Sources.OmnipodDash -> TODO()
Sources.MDI -> TODO()
Sources.VirtualPump -> TODO()
Sources.Treatments -> TODO()
Sources.Food -> TODO()
Sources.ConfigBuilder -> TODO()
Sources.Overview -> TODO()
Sources.Stats -> TODO()
*/
Sources.Automation -> resourceHelper.gs(R.string.automation)
Sources.Loop -> resourceHelper.gs(R.string.loop)

View file

@ -22,13 +22,14 @@ class UserEntryPresentationHelper @Inject constructor(
) {
fun colorId(colorGroup: ColorGroup): Int = when (colorGroup) {
ColorGroup.InsulinTreatment -> R.color.basal
ColorGroup.InsulinTreatment -> R.color.iob
ColorGroup.BasalTreatment -> 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.Pump -> R.color.loopDisconnected
ColorGroup.Aaps -> R.color.defaulttext
else -> R.color.defaulttext
}
@ -63,6 +64,19 @@ class UserEntryPresentationHelper @Inject constructor(
Sources.NSProfile -> R.drawable.ic_nightscout_profile
Sources.Objectives -> R.drawable.ic_graduation
Sources.Pump -> R.drawable.ic_generic_icon
Sources.Dana -> R.drawable.ic_danars_128
Sources.DanaR -> R.drawable.ic_danars_128
Sources.DanaRC -> R.drawable.ic_danars_128
Sources.DanaRv2 -> R.drawable.ic_danars_128
Sources.DanaRS -> R.drawable.ic_danars_128
Sources.Insight -> R.drawable.ic_insight_128
Sources.Combo -> R.drawable.ic_combo_128
Sources.Medtronic -> R.drawable.ic_veo_128
Sources.Omnipod -> R.drawable.ic_pod_128
Sources.OmnipodEros -> R.drawable.ic_pod_128
Sources.OmnipodDash -> R.drawable.ic_pod_128
Sources.MDI -> R.drawable.ic_ict
Sources.VirtualPump -> R.drawable.ic_virtual_pump
Sources.SMS -> R.drawable.ic_sms
Sources.Treatments -> R.drawable.ic_treatments
Sources.Wear -> R.drawable.ic_watch

View file

@ -110,7 +110,7 @@ class DanaFragment : DaggerFragment() {
binding.btconnection.setOnLongClickListener {
activity?.let {
OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing)) {
uel.log(Action.CLEAR_PAIRING_KEYS, Sources.Pump)
uel.log(Action.CLEAR_PAIRING_KEYS, Sources.Dana)
(activePlugin.activePump as DanaPumpInterface).clearPairing()
}
}

View file

@ -26,7 +26,7 @@ data class UserEntry(
SUPERBOLUS_TBR (ColorGroup.InsulinTreatment),
CARBS (ColorGroup.CarbTreatment),
EXTENDED_CARBS (ColorGroup.CarbTreatment),
TEMP_BASAL (ColorGroup.InsulinTreatment),
TEMP_BASAL (ColorGroup.BasalTreatment),
TT (ColorGroup.TT),
NEW_PROFILE (ColorGroup.Profile),
CLONE_PROFILE (ColorGroup.Profile),
@ -44,8 +44,8 @@ data class UserEntry(
SUSPEND (ColorGroup.Loop),
HW_PUMP_ALLOWED (ColorGroup.Pump),
CLEAR_PAIRING_KEYS (ColorGroup.Pump),
ACCEPTS_TEMP_BASAL (ColorGroup.InsulinTreatment),
CANCEL_TEMP_BASAL (ColorGroup.InsulinTreatment),
ACCEPTS_TEMP_BASAL (ColorGroup.BasalTreatment),
CANCEL_TEMP_BASAL (ColorGroup.BasalTreatment),
CANCEL_EXTENDED_BOLUS (ColorGroup.InsulinTreatment),
CANCEL_TT (ColorGroup.TT),
CAREPORTAL (ColorGroup.Careportal),
@ -60,7 +60,7 @@ data class UserEntry(
BG_REMOVED (ColorGroup.Careportal),
CAREPORTAL_REMOVED (ColorGroup.Careportal),
EXTENDED_BOLUS_REMOVED (ColorGroup.InsulinTreatment),
FOOD_REMOVED (ColorGroup.Careportal),
FOOD_REMOVED (ColorGroup.CarbTreatment),
PROFILE_REMOVED (ColorGroup.Profile),
PROFILE_SWITCH_REMOVED (ColorGroup.Profile),
RESTART_EVENTS_REMOVED (ColorGroup.Aaps),
@ -87,7 +87,7 @@ data class UserEntry(
OTP_EXPORT (ColorGroup.Aaps),
OTP_RESET (ColorGroup.Aaps),
STOP_SMS (ColorGroup.Aaps),
FOOD (ColorGroup.Careportal),
FOOD (ColorGroup.CarbTreatment),
EXPORT_CSV (ColorGroup.Aaps),
UNKNOWN (ColorGroup.Aaps)
;
@ -127,6 +127,19 @@ data class UserEntry(
NSProfile, //From NSProfile plugin
Objectives, //From Objectives plugin
Pump, //To update with one Source per pump
Dana, //Only one UserEntry in Common module Dana
DanaR, //No entry currently
DanaRC, //No entry currently
DanaRv2, //No entry currently
DanaRS, //No entry currently
Insight, //No entry currently
Combo, //No entry currently
Medtronic, //No entry currently
Omnipod, //No entry currently
OmnipodEros, //No entry currently
OmnipodDash, //No entry currently
MDI, //No entry currently
VirtualPump, //No entry currently
SMS, //From SMS plugin
Treatments, //From Treatments plugin
Wear, //From Wear plugin
@ -144,6 +157,7 @@ data class UserEntry(
enum class ColorGroup() {
InsulinTreatment,
BasalTreatment,
CarbTreatment,
TT,
Profile,

View file

@ -38,59 +38,33 @@ sealed class ValueWithUnit {
fun value(): Any? {
return when(this) {
is Gram -> this.value
is Hour -> this.value
is Insulin -> this.value
is Mgdl -> this.value
is Minute -> this.value
is Mmoll -> this.value
is Percent -> this.value
is SimpleInt -> this.value
is SimpleString -> this.value
is StringResource -> this.value
is Gram -> this.value
is Hour -> this.value
is Insulin -> this.value
is Mgdl -> this.value
is Minute -> this.value
is Mmoll -> this.value
is Percent -> this.value
is SimpleInt -> this.value
is SimpleString -> this.value
is StringResource -> this.value
is TherapyEventMeterType -> this.value
is TherapyEventTTReason -> this.value
is TherapyEventType -> this.value
is Timestamp -> this.value
is UnitPerHour -> this.value
UNKNOWN -> null
is TherapyEventTTReason -> this.value
is TherapyEventType -> this.value
is Timestamp -> this.value
is UnitPerHour -> this.value
UNKNOWN -> null
}
}
companion object {
const val MGDL = "mg/dl" // This is Nightscout's representation
const val MMOL = "mmol"
fun fromGlucoseUnit(value: Double, string: String): ValueWithUnit? = when (string) {
"mg/dl", "mgdl" -> Mgdl(value)
"mmol", "mmol/l" -> Mmoll(value)
else -> null
MGDL, "mgdl" -> Mgdl(value)
MMOL, "mmol/l" -> Mmoll(value)
else -> null
}
}
}
/***
* Idea: Leverage sealed classes for units
* Advantage: it is clear what type of data a Unit contains. Still we are exhaustive on when
*
* The condition "condition" that is used to check if an item should be logged can be replaced by .takeIf { condition }.
* The value then would not have to be handled but the logging could simply discard null value.
*
* [x] new sealed classes
* [x] use entry type directly, not String
* [ ] database
* [x] generate presentation string
* [ ] update fragment
* [ ] generate csv
*
*/
// just do develop in this file. Remove when done.
/*
interface Translator {
fun translate(units: UserEntry.Units): String
fun translate(meterType: TherapyEvent.MeterType): String
fun translate(type: TherapyEvent.Type): String
fun translate(reason: TemporaryTarget.Reason): String
}
*/