Avoid Crash in csv Export

Fix Translator if null objects sent
Add again @SerializedName removed in Temporaytarget and TherapyEvent
This commit is contained in:
Philoul 2021-10-16 12:35:47 +02:00
parent b10501e7b0
commit 58a6cd3c02
3 changed files with 59 additions and 4 deletions

View file

@ -114,7 +114,7 @@ class Translator @Inject internal constructor(
else -> ""
}
fun translate(meterType: TherapyEvent.MeterType): String = when (meterType) {
fun translate(meterType: TherapyEvent.MeterType?): String = when (meterType) {
TherapyEvent.MeterType.FINGER -> resourceHelper.gs(R.string.glucosetype_finger)
TherapyEvent.MeterType.SENSOR -> resourceHelper.gs(R.string.glucosetype_sensor)
TherapyEvent.MeterType.MANUAL -> resourceHelper.gs(R.string.manual)
@ -122,7 +122,7 @@ class Translator @Inject internal constructor(
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(type: TherapyEvent.Type): String = when (type) {
fun translate(type: TherapyEvent.Type?): String = when (type) {
TherapyEvent.Type.FINGER_STICK_BG_VALUE -> resourceHelper.gs(R.string.careportal_bgcheck)
TherapyEvent.Type.SNACK_BOLUS -> resourceHelper.gs(R.string.careportal_snackbolus)
TherapyEvent.Type.MEAL_BOLUS -> resourceHelper.gs(R.string.careportal_mealbolus)
@ -173,7 +173,7 @@ class Translator @Inject internal constructor(
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(reason: TemporaryTarget.Reason): String = when (reason) {
fun translate(reason: TemporaryTarget.Reason?): String = when (reason) {
TemporaryTarget.Reason.CUSTOM -> resourceHelper.gs(R.string.custom)
TemporaryTarget.Reason.HYPOGLYCEMIA -> resourceHelper.gs(R.string.hypo)
TemporaryTarget.Reason.EATING_SOON -> resourceHelper.gs(R.string.eatingsoon)
@ -184,7 +184,7 @@ class Translator @Inject internal constructor(
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(reason: OfflineEvent.Reason): String = when (reason) {
fun translate(reason: OfflineEvent.Reason?): String = when (reason) {
OfflineEvent.Reason.SUSPEND -> resourceHelper.gs(R.string.uel_suspend)
OfflineEvent.Reason.DISABLE_LOOP -> resourceHelper.gs(R.string.disableloop)
OfflineEvent.Reason.DISCONNECT_PUMP -> resourceHelper.gs(R.string.uel_disconnect)

View file

@ -5,6 +5,7 @@ import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import info.nightscout.androidaps.database.TABLE_TEMPORARY_TARGETS
import info.nightscout.androidaps.database.embedments.InterfaceIDs
import info.nightscout.androidaps.database.interfaces.DBEntryWithTimeAndDuration
@ -62,11 +63,17 @@ data class TemporaryTarget(
interfaceIDs.nightscoutId != null
enum class Reason(val text: String) {
@SerializedName("Custom")
CUSTOM("Custom"),
@SerializedName("Hypo")
HYPOGLYCEMIA("Hypo"),
@SerializedName("Activity")
ACTIVITY("Activity"),
@SerializedName("Eating Soon")
EATING_SOON("Eating Soon"),
@SerializedName("Automation")
AUTOMATION("Automation"),
@SerializedName("Wear")
WEAR("Wear")
;

View file

@ -5,6 +5,7 @@ import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import info.nightscout.androidaps.database.TABLE_THERAPY_EVENTS
import info.nightscout.androidaps.database.embedments.InterfaceIDs
import info.nightscout.androidaps.database.interfaces.DBEntryWithTimeAndDuration
@ -73,8 +74,11 @@ data class TherapyEvent(
}
enum class MeterType(val text: String) {
@SerializedName("Finger")
FINGER("Finger"),
@SerializedName("Sensor")
SENSOR("Sensor"),
@SerializedName("Manual")
MANUAL("Manual")
;
@ -87,55 +91,99 @@ data class TherapyEvent(
@Suppress("unused")
enum class Type(val text: String, val nsNative: Boolean = false) {
@SerializedName("Site Change")
CANNULA_CHANGE("Site Change", nsNative = true),
@SerializedName("Insulin Change")
INSULIN_CHANGE("Insulin Change", nsNative = true),
@SerializedName("Pump Battery Change")
PUMP_BATTERY_CHANGE("Pump Battery Change", nsNative = true),
@SerializedName("Sensor Change")
SENSOR_CHANGE("Sensor Change", nsNative = true),
@SerializedName("Sensor Start")
SENSOR_STARTED("Sensor Start", nsNative = true),
@SerializedName("Sensor Stop")
SENSOR_STOPPED("Sensor Stop", nsNative = true),
@SerializedName("BG Check")
FINGER_STICK_BG_VALUE("BG Check", nsNative = true),
@SerializedName("Exercise")
EXERCISE("Exercise", nsNative = true),
@SerializedName("Announcement")
ANNOUNCEMENT("Announcement", nsNative = true),
@SerializedName("Question")
QUESTION("Question", nsNative = true),
@SerializedName("Note")
NOTE("Note", nsNative = true),
@SerializedName("OpenAPS Offline")
APS_OFFLINE("OpenAPS Offline", nsNative = true),
@SerializedName("D.A.D. Alert")
DAD_ALERT("D.A.D. Alert", nsNative = true),
@SerializedName("Mbg")
NS_MBG("Mbg", nsNative = true),
// Used but not as a Therapy Event (use constants only)
@SerializedName("Carb Correction")
CARBS_CORRECTION("Carb Correction", nsNative = true),
@SerializedName("Bolus Wizard")
BOLUS_WIZARD("Bolus Wizard", nsNative = true),
@SerializedName("Correction Bolus")
CORRECTION_BOLUS("Correction Bolus", nsNative = true),
@SerializedName("Meal Bolus")
MEAL_BOLUS("Meal Bolus", nsNative = true),
@SerializedName("Combo Bolus")
COMBO_BOLUS("Combo Bolus", nsNative = true),
@SerializedName("Temporary Target")
TEMPORARY_TARGET("Temporary Target", nsNative = true),
@SerializedName("Temporary Target Cancel")
TEMPORARY_TARGET_CANCEL("Temporary Target Cancel", nsNative = true),
@SerializedName("Profile Switch")
PROFILE_SWITCH("Profile Switch", nsNative = true),
@SerializedName("Snack Bolus")
SNACK_BOLUS("Snack Bolus", nsNative = true),
@SerializedName("Temp Basal")
TEMPORARY_BASAL("Temp Basal", nsNative = true),
@SerializedName("Temp Basal Start")
TEMPORARY_BASAL_START("Temp Basal Start", nsNative = true),
@SerializedName("Temp Basal End")
TEMPORARY_BASAL_END("Temp Basal End", nsNative = true),
// Not supported by NS
@SerializedName("Tube Change")
TUBE_CHANGE("Tube Change"),
@SerializedName("Falling Asleep")
FALLING_ASLEEP("Falling Asleep"),
@SerializedName("Battery Empty")
BATTERY_EMPTY("Battery Empty"),
@SerializedName("Reservoir Empty")
RESERVOIR_EMPTY("Reservoir Empty"),
@SerializedName("Occlusion")
OCCLUSION("Occlusion"),
@SerializedName("Pump Stopped")
PUMP_STOPPED("Pump Stopped"),
@SerializedName("Pump Started")
PUMP_STARTED("Pump Started"),
@SerializedName("Pump Paused")
PUMP_PAUSED("Pump Paused"),
@SerializedName("Waking Up")
WAKING_UP("Waking Up"),
@SerializedName("Sickness")
SICKNESS("Sickness"),
@SerializedName("Stress")
STRESS("Stress"),
@SerializedName("Pre Period")
PRE_PERIOD("Pre Period"),
@SerializedName("Alcohol")
ALCOHOL("Alcohol"),
@SerializedName("Cortisone")
CORTISONE("Cortisone"),
@SerializedName("Feeling Low")
FEELING_LOW("Feeling Low"),
@SerializedName("Feeling High")
FEELING_HIGH("Feeling High"),
@SerializedName("Leaking Infusion Set")
LEAKING_INFUSION_SET("Leaking Infusion Set"),
// Default
@SerializedName("<none>")
NONE("<none>")
;