Move MGDL and MMOL Constants to XXXValueWithUnits

This commit is contained in:
Philoul 2021-04-03 17:56:19 +02:00
parent 8d8abd65a7
commit 82299e430b
2 changed files with 24 additions and 49 deletions

View file

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

View file

@ -58,39 +58,13 @@ sealed class XXXValueWithUnit {
} }
companion object { companion object {
const val MGDL = "mg/dl" // This is Nightscout's representation
const val MMOL = "mmol"
fun fromGlucoseUnit(value: Double, string: String): XXXValueWithUnit? = when (string) { fun fromGlucoseUnit(value: Double, string: String): XXXValueWithUnit? = when (string) {
"mg/dl", "mgdl" -> Mgdl(value) MGDL, "mgdl" -> Mgdl(value)
"mmol", "mmol/l" -> Mmoll(value) MMOL, "mmol/l" -> Mmoll(value)
else -> null 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
}
*/