Fix Constants.MGDL and Constants.MMOL
Fix .addMigrations(migration3to4) (I hope)
This commit is contained in:
parent
8798be0c34
commit
a2c3ec3a7f
|
@ -7,8 +7,8 @@ import info.nightscout.androidaps.database.entities.UserEntry.*;
|
|||
* Created by mike on 07.06.2016.
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String MGDL = Units.Mg_Dl.name(); // This is Nightscout's representation
|
||||
public static final String MMOL = Units.Mmol_L.name();
|
||||
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 double MMOLL_TO_MGDL = 18; // 18.0182;
|
||||
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;
|
||||
|
|
|
@ -3,13 +3,12 @@ package info.nightscout.androidaps.utils.extensions
|
|||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.database.entities.UserEntry
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
||||
fun UserEntry.Units.stringId(): Int {
|
||||
return when {
|
||||
this == UserEntry.Units.Mg_Dl -> R.string.mgdl
|
||||
this == UserEntry.Units.Mg_Dl -> R.string.mgdl
|
||||
this == UserEntry.Units.Mmol_L -> R.string.mmol
|
||||
this == UserEntry.Units.U -> R.string.insulin_unit_shortname
|
||||
this == UserEntry.Units.U -> R.string.insulin_unit_shortname
|
||||
this == UserEntry.Units.U_H -> R.string.profile_ins_units_per_hour
|
||||
this == UserEntry.Units.G -> R.string.shortgram
|
||||
this == UserEntry.Units.M -> R.string.shortminute
|
||||
|
@ -17,20 +16,4 @@ fun UserEntry.Units.stringId(): Int {
|
|||
this == UserEntry.Units.Percent -> R.string.shortpercent
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun UserEntry.Units.stringkey(): String {
|
||||
return when {
|
||||
this == UserEntry.Units.Mg_Dl -> Constants.MGDL
|
||||
this == UserEntry.Units.Mmol_L -> Constants.MMOL
|
||||
this == UserEntry.Units.U -> UserEntry.Units.U.name
|
||||
this == UserEntry.Units.U_H -> UserEntry.Units.U_H.name
|
||||
this == UserEntry.Units.G -> UserEntry.Units.G.name
|
||||
this == UserEntry.Units.M -> UserEntry.Units.M.name
|
||||
this == UserEntry.Units.H -> UserEntry.Units.H.name
|
||||
this == UserEntry.Units.Percent -> "%"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun UserEntry.Units.Companion(source: String?) = UserEntry.Units.values().firstOrNull { it.stringkey() == source } ?: UserEntry.Units.None
|
||||
}
|
|
@ -38,7 +38,7 @@ open class DatabaseModule {
|
|||
private val migration3to4 = object : Migration(3, 4) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS userEntry")
|
||||
database.execSQL("CREATE TABLE userEntry (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `utcOffset` INTEGER NOT NULL, `action` TEXT NOT NULL, `s` TEXT NOT NULL, `d1` TEXT NOT NULL, `d2` TEXT NOT NULL, `i1` TEXT NOT NULL, `i2` TEXT NOT NULL)")
|
||||
database.execSQL("CREATE TABLE userEntry (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `utcOffset` INTEGER NOT NULL, `action` TEXT NOT NULL, `s` TEXT NOT NULL, `values` TEXT NOT NULL)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -124,26 +124,33 @@ data class UserEntry(
|
|||
constructor(ivalue:Int?, unit:Units) : this(0.0, ivalue ?:0, 0, "", unit)
|
||||
constructor(lvalue:Long?, unit:Units) : this(0.0,0, lvalue ?:0, "", unit)
|
||||
constructor(svalue:String?, unit:Units) : this(0.0,0, 0, svalue ?:"", unit)
|
||||
constructor(dvalue:Double?, unit:String) : this(dvalue ?:0.0,0, 0, "", Units.fromString(unit))
|
||||
constructor(dvalue:Double?, unit:String) : this(dvalue ?:0.0,0, 0, "", Units.fromText(unit))
|
||||
fun value() : Any {
|
||||
if (!dValue.equals(0.0)) return dValue
|
||||
if (!iValue.equals(0)) return iValue
|
||||
if (!lValue.equals(0)) return lValue
|
||||
return sValue
|
||||
}
|
||||
}
|
||||
enum class Units {
|
||||
@SerializedName("None") None,
|
||||
@SerializedName("mg/dl") Mg_Dl,
|
||||
@SerializedName("mmol") Mmol_L,
|
||||
@SerializedName("Timestamp") Timestamp,
|
||||
@SerializedName("U") U,
|
||||
@SerializedName("U/h") U_H,
|
||||
@SerializedName("g") G,
|
||||
@SerializedName("m") M,
|
||||
@SerializedName("h") H,
|
||||
@SerializedName("Percent") Percent,
|
||||
@SerializedName("CPEvent") CPEvent,
|
||||
@SerializedName("TT_Reason") TT_Reason,
|
||||
@SerializedName("R_String") R_String
|
||||
enum class Units(val text: String) {
|
||||
@SerializedName("None") None (""),
|
||||
@SerializedName("Mg_Dl") Mg_Dl ("mg/dl"),
|
||||
@SerializedName("Mmol_L") Mmol_L ("mmol"),
|
||||
@SerializedName("Timestamp") Timestamp("Timestamp"),
|
||||
@SerializedName("U") U ("U"),
|
||||
@SerializedName("U_H") U_H ("U/h"),
|
||||
@SerializedName("G") G ("g"),
|
||||
@SerializedName("M") M ("m"),
|
||||
@SerializedName("H") H ("h"),
|
||||
@SerializedName("Percent") Percent ("%"),
|
||||
@SerializedName("CPEvent") CPEvent ("CPEvent"),
|
||||
@SerializedName("TT_Reason") TT_Reason ("TTReason"),
|
||||
@SerializedName("R_String") R_String ("R.string")
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromString(unit: String?) = values().firstOrNull { it.name == unit } ?: None
|
||||
fun fromText(unit: String?) = values().firstOrNull { it.text == unit } ?: None
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue