Add Converter, companion object and unknow string
This commit is contained in:
parent
b4f1996717
commit
dec7232d42
4 changed files with 15 additions and 3 deletions
|
@ -98,7 +98,6 @@ fun UserEntry.Action.stringId(): Int {
|
|||
this == UserEntry.Action.SMS_PUMP_DISCONNECT -> R.string.uel_sms_pump_disconnect
|
||||
this == UserEntry.Action.SMS_SMS -> R.string.uel_sms_sms
|
||||
this == UserEntry.Action.SMS_TT -> R.string.uel_sms_tt
|
||||
else -> R.string.uel_sms_tt
|
||||
|
||||
else -> R.string.uel_unknown
|
||||
}
|
||||
}
|
|
@ -419,6 +419,7 @@
|
|||
<string name="uel_sms_pump_disconnect">SMS PUMP DISCONNECT</string>
|
||||
<string name="uel_sms_sms">SMS SMS</string>
|
||||
<string name="uel_sms_tt">SMS TT</string>
|
||||
<string name="uel_unknown">UNKNOWN</string>
|
||||
|
||||
<plurals name="days">
|
||||
<item quantity="one">%1$d day</item>
|
||||
|
|
|
@ -10,6 +10,12 @@ import org.json.JSONObject
|
|||
|
||||
class Converters {
|
||||
|
||||
@TypeConverter
|
||||
fun fromAction(action: UserEntry.Action?) = action?.name
|
||||
|
||||
@TypeConverter
|
||||
fun toAction(action: String?) = action?.let { UserEntry.Action.valueOf(it) }
|
||||
|
||||
@TypeConverter
|
||||
fun fromBolusType(bolusType: Bolus.Type?) = bolusType?.name
|
||||
|
||||
|
|
|
@ -115,6 +115,12 @@ data class UserEntry(
|
|||
@SerializedName("SMS_PUMP_CONNECT") SMS_PUMP_CONNECT,
|
||||
@SerializedName("SMS_PUMP_DISCONNECT") SMS_PUMP_DISCONNECT,
|
||||
@SerializedName("SMS_SMS") SMS_SMS,
|
||||
@SerializedName("SMS_TT") SMS_TT
|
||||
@SerializedName("SMS_TT") SMS_TT,
|
||||
@SerializedName("UNKNOWN") UNKNOWN
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromString(source: String?) = UserEntry.Action.values().firstOrNull { it.name == source } ?: UserEntry.Action.UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue