Add Converter, companion object and unknow string

This commit is contained in:
Philoul 2021-02-21 22:46:43 +01:00
parent b4f1996717
commit dec7232d42
4 changed files with 15 additions and 3 deletions

View file

@ -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_PUMP_DISCONNECT -> R.string.uel_sms_pump_disconnect
this == UserEntry.Action.SMS_SMS -> R.string.uel_sms_sms this == UserEntry.Action.SMS_SMS -> R.string.uel_sms_sms
this == UserEntry.Action.SMS_TT -> R.string.uel_sms_tt this == UserEntry.Action.SMS_TT -> R.string.uel_sms_tt
else -> R.string.uel_sms_tt else -> R.string.uel_unknown
} }
} }

View file

@ -419,6 +419,7 @@
<string name="uel_sms_pump_disconnect">SMS PUMP DISCONNECT</string> <string name="uel_sms_pump_disconnect">SMS PUMP DISCONNECT</string>
<string name="uel_sms_sms">SMS SMS</string> <string name="uel_sms_sms">SMS SMS</string>
<string name="uel_sms_tt">SMS TT</string> <string name="uel_sms_tt">SMS TT</string>
<string name="uel_unknown">UNKNOWN</string>
<plurals name="days"> <plurals name="days">
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>

View file

@ -10,6 +10,12 @@ import org.json.JSONObject
class Converters { class Converters {
@TypeConverter
fun fromAction(action: UserEntry.Action?) = action?.name
@TypeConverter
fun toAction(action: String?) = action?.let { UserEntry.Action.valueOf(it) }
@TypeConverter @TypeConverter
fun fromBolusType(bolusType: Bolus.Type?) = bolusType?.name fun fromBolusType(bolusType: Bolus.Type?) = bolusType?.name

View file

@ -115,6 +115,12 @@ data class UserEntry(
@SerializedName("SMS_PUMP_CONNECT") SMS_PUMP_CONNECT, @SerializedName("SMS_PUMP_CONNECT") SMS_PUMP_CONNECT,
@SerializedName("SMS_PUMP_DISCONNECT") SMS_PUMP_DISCONNECT, @SerializedName("SMS_PUMP_DISCONNECT") SMS_PUMP_DISCONNECT,
@SerializedName("SMS_SMS") SMS_SMS, @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
}
} }
} }