Safe delete Units enum class in UserEntry
This commit is contained in:
parent
2a03d1d7ca
commit
8d8abd65a7
|
@ -1,14 +1,13 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Units;
|
||||
|
||||
/**
|
||||
* Created by mike on 07.06.2016.
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String MGDL = Units.Mg_Dl.getText(); // This is Nightscout's representation
|
||||
public static final String MMOL = Units.Mmol_L.getText();
|
||||
public static final String MGDL = "mg/dl"; // This is Nightscout's representation
|
||||
public static final String MMOL = "mmol";
|
||||
|
||||
public static final double MMOLL_TO_MGDL = 18; // 18.0182;
|
||||
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;
|
||||
|
|
|
@ -3,11 +3,8 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats
|
|||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.database.entities.UserEntry
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Units
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.Translator
|
||||
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.androidaps.database.entities.TemporaryTarget
|
|||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Units
|
||||
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -92,18 +92,16 @@ class Translator @Inject internal constructor(
|
|||
Action.UNKNOWN -> resourceHelper.gs(R.string.unknown)
|
||||
}
|
||||
|
||||
fun translate(units: Units): String = when(units) {
|
||||
Units.Mg_Dl -> resourceHelper.gs(R.string.mgdl)
|
||||
Units.Mmol_L -> resourceHelper.gs(R.string.mmol)
|
||||
Units.U -> resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||
Units.U_H -> resourceHelper.gs(R.string.profile_ins_units_per_hour)
|
||||
Units.G -> resourceHelper.gs(R.string.shortgram)
|
||||
Units.M -> resourceHelper.gs(R.string.shortminute)
|
||||
Units.H -> resourceHelper.gs(R.string.shorthour)
|
||||
Units.Percent -> resourceHelper.gs(R.string.shortpercent)
|
||||
Units.None -> ""
|
||||
|
||||
else -> resourceHelper.gs(R.string.unknown)
|
||||
fun translate(units: XXXValueWithUnit?): String = when(units) {
|
||||
is XXXValueWithUnit.Gram -> resourceHelper.gs(R.string.shortgram)
|
||||
is XXXValueWithUnit.Hour -> resourceHelper.gs(R.string.shorthour)
|
||||
is XXXValueWithUnit.Insulin -> resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||
is XXXValueWithUnit.Mgdl -> resourceHelper.gs(R.string.mgdl)
|
||||
is XXXValueWithUnit.Minute -> resourceHelper.gs(R.string.shortminute)
|
||||
is XXXValueWithUnit.Mmoll -> resourceHelper.gs(R.string.mmol)
|
||||
is XXXValueWithUnit.Percent -> resourceHelper.gs(R.string.shortpercent)
|
||||
is XXXValueWithUnit.UnitPerHour -> resourceHelper.gs(R.string.profile_ins_units_per_hour)
|
||||
else -> ""
|
||||
}
|
||||
|
||||
fun translate(meterType: TherapyEvent.MeterType): String = when(meterType) {
|
||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.androidaps.core.R
|
|||
import info.nightscout.androidaps.database.entities.UserEntry
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Units
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.ColorGroup
|
||||
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -85,12 +84,12 @@ class UserEntryPresentationHelper @Inject constructor(
|
|||
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.M)}"
|
||||
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.Gram -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
|
||||
is XXXValueWithUnit.Hour -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
|
||||
is XXXValueWithUnit.Minute -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
|
||||
is XXXValueWithUnit.Percent -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
|
||||
is XXXValueWithUnit.Insulin -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
|
||||
is XXXValueWithUnit.UnitPerHour -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
|
||||
is XXXValueWithUnit.SimpleInt -> valueWithUnit.value.toString()
|
||||
is XXXValueWithUnit.SimpleString -> valueWithUnit.value
|
||||
// is XXXValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map{ it.value() }.toTypedArray()) //Todo Fix StringResource with Param
|
||||
|
@ -101,13 +100,13 @@ class UserEntryPresentationHelper @Inject constructor(
|
|||
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)
|
||||
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
|
||||
else DecimalFormatter.to1Decimal(valueWithUnit.value / Constants.MMOLL_TO_MGDL) + translator.translate(valueWithUnit)
|
||||
}
|
||||
|
||||
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)
|
||||
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
|
||||
else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + translator.translate(valueWithUnit)
|
||||
}
|
||||
|
||||
XXXValueWithUnit.UNKNOWN -> ""
|
||||
|
@ -128,13 +127,13 @@ class UserEntryPresentationHelper @Inject constructor(
|
|||
csvString(R.string.careportal_note),
|
||||
csvString(R.string.ue_formated_string),
|
||||
csvString(R.string.event_time_label),
|
||||
csvString(Units.fromText(profileFunction.getUnits())),
|
||||
csvString(Units.G),
|
||||
csvString(Units.U),
|
||||
csvString(Units.U_H),
|
||||
csvString(Units.Percent),
|
||||
csvString(Units.H),
|
||||
csvString(Units.M),
|
||||
csvString(if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol ),
|
||||
csvString(R.string.shortgram),
|
||||
csvString(R.string.insulin_unit_shortname),
|
||||
csvString(R.string.profile_ins_units_per_hour),
|
||||
csvString(R.string.shortpercent),
|
||||
csvString(R.string.shorthour),
|
||||
csvString(R.string.shortminute),
|
||||
csvString(R.string.ue_none)
|
||||
) + "\n"
|
||||
|
||||
|
@ -198,7 +197,6 @@ class UserEntryPresentationHelper @Inject constructor(
|
|||
|
||||
private fun saveString(id: Int): String = if (id != 0) resourceHelper.gs(id) else ""
|
||||
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"") + "\""
|
||||
private fun csvString(unit: Units): String = "\"" + translator.translate(unit).replace("\"", "\"\"") + "\""
|
||||
private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"") + "\"" else ""
|
||||
private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"") + "\"" else ""
|
||||
}
|
|
@ -97,28 +97,6 @@ data class UserEntry(
|
|||
}
|
||||
}
|
||||
|
||||
enum class Units(val text: String) {
|
||||
None (""), //Int or String
|
||||
Mg_Dl ("mg/dl"), //Double
|
||||
Mmol_L ("mmol"), //Double
|
||||
Timestamp("Timestamp"), //long
|
||||
U ("U"), //Double
|
||||
U_H ("U/h"), //Double
|
||||
G ("g"), //Int
|
||||
M ("m"), //Int
|
||||
H ("h"), //Int
|
||||
Percent ("%"), //Int
|
||||
TherapyEvent ("TherapyEvent"), //String (All enum key translated by Translator function, mainly The
|
||||
R_String ("R.string"), //Int
|
||||
Source ("Source") //String
|
||||
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromString(unit: String?) = values().firstOrNull { it.name == unit } ?: None
|
||||
fun fromText(unit: String?) = values().firstOrNull { it.text == unit } ?: None
|
||||
}
|
||||
}
|
||||
enum class Sources() {
|
||||
TreatmentDialog,
|
||||
InsulinDialog,
|
||||
|
|
Loading…
Reference in a new issue