Merge pull request #2962 from MilosKozak/oh-nullsafety

OH null safety
This commit is contained in:
AdrianLxM 2020-09-12 13:49:22 +02:00 committed by GitHub
commit 5924be585e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -157,31 +157,35 @@ class OpenHumansUploader @Inject constructor(
super.onStop() super.onStop()
} }
fun enqueueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") { fun enqueueBGReading(bgReading: BgReading?) = bgReading?.let {
put("date", bgReading.date) insertQueueItem("BgReadings") {
put("isValid", bgReading.isValid) put("date", bgReading.date)
put("value", bgReading.value) put("isValid", bgReading.isValid)
put("direction", bgReading.direction) put("value", bgReading.value)
put("raw", bgReading.raw) put("direction", bgReading.direction)
put("source", bgReading.source) put("raw", bgReading.raw)
put("nsId", bgReading._id) put("source", bgReading.source)
put("nsId", bgReading._id)
}
} }
@JvmOverloads @JvmOverloads
fun enqueueTreatment(treatment: Treatment, deleted: Boolean = false) = insertQueueItem("Treatments") { fun enqueueTreatment(treatment: Treatment?, deleted: Boolean = false) = treatment?.let {
put("date", treatment.date) insertQueueItem("Treatments") {
put("isValid", treatment.isValid) put("date", treatment.date)
put("source", treatment.source) put("isValid", treatment.isValid)
put("nsId", treatment._id) put("source", treatment.source)
put("boluscalc", treatment.boluscalc) put("nsId", treatment._id)
put("carbs", treatment.carbs) put("boluscalc", treatment.boluscalc)
put("dia", treatment.dia) put("carbs", treatment.carbs)
put("insulin", treatment.insulin) put("dia", treatment.dia)
put("insulinInterfaceID", treatment.insulinInterfaceID) put("insulin", treatment.insulin)
put("isSMB", treatment.isSMB) put("insulinInterfaceID", treatment.insulinInterfaceID)
put("mealBolus", treatment.mealBolus) put("isSMB", treatment.isSMB)
put("bolusCalcJson", treatment.getBoluscalc()) put("mealBolus", treatment.mealBolus)
put("isDeletion", deleted) put("bolusCalcJson", treatment.getBoluscalc())
put("isDeletion", deleted)
}
} }
@JvmOverloads @JvmOverloads
@ -240,34 +244,38 @@ class OpenHumansUploader @Inject constructor(
} }
@JvmOverloads @JvmOverloads
fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") { fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal?, deleted: Boolean = false) = temporaryBasal?.let {
put("date", temporaryBasal.date) insertQueueItem("TemporaryBasals") {
put("isValid", temporaryBasal.isValid) put("date", temporaryBasal.date)
put("source", temporaryBasal.source) put("isValid", temporaryBasal.isValid)
put("nsId", temporaryBasal._id) put("source", temporaryBasal.source)
put("pumpId", temporaryBasal.pumpId) put("nsId", temporaryBasal._id)
put("durationInMinutes", temporaryBasal.durationInMinutes) put("pumpId", temporaryBasal.pumpId)
put("durationInMinutes", temporaryBasal.durationInMinutes) put("durationInMinutes", temporaryBasal.durationInMinutes)
put("isAbsolute", temporaryBasal.isAbsolute) put("durationInMinutes", temporaryBasal.durationInMinutes)
put("percentRate", temporaryBasal.percentRate) put("isAbsolute", temporaryBasal.isAbsolute)
put("absoluteRate", temporaryBasal.absoluteRate) put("percentRate", temporaryBasal.percentRate)
put("isDeletion", deleted) put("absoluteRate", temporaryBasal.absoluteRate)
put("isDeletion", deleted)
}
} }
@JvmOverloads @JvmOverloads
fun enqueueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") { fun enqueueTempTarget(tempTarget: TempTarget?, deleted: Boolean = false) = tempTarget?.let {
put("date", tempTarget.date) insertQueueItem("TempTargets") {
put("isValid", tempTarget.isValid) put("date", tempTarget.date)
put("source", tempTarget.source) put("isValid", tempTarget.isValid)
put("nsId", tempTarget._id) put("source", tempTarget.source)
put("low", tempTarget.low) put("nsId", tempTarget._id)
put("high", tempTarget.high) put("low", tempTarget.low)
put("reason", tempTarget.reason) put("high", tempTarget.high)
put("durationInMinutes", tempTarget.durationInMinutes) put("reason", tempTarget.reason)
put("isDeletion", deleted) put("durationInMinutes", tempTarget.durationInMinutes)
put("isDeletion", deleted)
}
} }
fun enqueueSMBData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, smbAllowed: Boolean, smbAlwaysAllowed: Boolean, result: JSONObject) = insertQueueItem("APSData") { fun enqueueSMBData(profile: JSONObject?, glucoseStatus: JSONObject?, iobData: JSONArray?, mealData: JSONObject?, currentTemp: JSONObject?, autosensData: JSONObject?, smbAllowed: Boolean, smbAlwaysAllowed: Boolean, result: JSONObject?) = insertQueueItem("APSData") {
put("algorithm", "SMB") put("algorithm", "SMB")
put("profile", profile) put("profile", profile)
put("glucoseStatus", glucoseStatus) put("glucoseStatus", glucoseStatus)
@ -280,7 +288,7 @@ class OpenHumansUploader @Inject constructor(
put("result", result) put("result", result)
} }
fun enqueueAMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, result: JSONObject) = insertQueueItem("APSData") { fun enqueueAMAData(profile: JSONObject?, glucoseStatus: JSONObject?, iobData: JSONArray?, mealData: JSONObject?, currentTemp: JSONObject?, autosensData: JSONObject?, result: JSONObject?) = insertQueueItem("APSData") {
put("algorithm", "AMA") put("algorithm", "AMA")
put("profile", profile) put("profile", profile)
put("glucoseStatus", glucoseStatus) put("glucoseStatus", glucoseStatus)
@ -291,16 +299,6 @@ class OpenHumansUploader @Inject constructor(
put("result", result) put("result", result)
} }
fun enqueueMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONObject, mealData: JSONObject, currentTemp: JSONObject, result: JSONObject) = insertQueueItem("APSData") {
put("algorithm", "MA")
put("profile", profile)
put("glucoseStatus", glucoseStatus)
put("iobData", iobData)
put("mealData", mealData)
put("currentTemp", currentTemp)
put("result", result)
}
private fun insertQueueItem(file: String, structureVersion: Int = 1, generator: JSONObject.() -> Unit) { private fun insertQueueItem(file: String, structureVersion: Int = 1, generator: JSONObject.() -> Unit) {
if (oAuthTokens != null && this.isEnabled(PluginType.GENERAL)) { if (oAuthTokens != null && this.isEnabled(PluginType.GENERAL)) {
try { try {