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,7 +157,8 @@ class OpenHumansUploader @Inject constructor(
super.onStop() super.onStop()
} }
fun enqueueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") { fun enqueueBGReading(bgReading: BgReading?) = bgReading?.let {
insertQueueItem("BgReadings") {
put("date", bgReading.date) put("date", bgReading.date)
put("isValid", bgReading.isValid) put("isValid", bgReading.isValid)
put("value", bgReading.value) put("value", bgReading.value)
@ -166,9 +167,11 @@ class OpenHumansUploader @Inject constructor(
put("source", bgReading.source) put("source", bgReading.source)
put("nsId", bgReading._id) put("nsId", bgReading._id)
} }
}
@JvmOverloads @JvmOverloads
fun enqueueTreatment(treatment: Treatment, deleted: Boolean = false) = insertQueueItem("Treatments") { fun enqueueTreatment(treatment: Treatment?, deleted: Boolean = false) = treatment?.let {
insertQueueItem("Treatments") {
put("date", treatment.date) put("date", treatment.date)
put("isValid", treatment.isValid) put("isValid", treatment.isValid)
put("source", treatment.source) put("source", treatment.source)
@ -183,6 +186,7 @@ class OpenHumansUploader @Inject constructor(
put("bolusCalcJson", treatment.getBoluscalc()) put("bolusCalcJson", treatment.getBoluscalc())
put("isDeletion", deleted) put("isDeletion", deleted)
} }
}
@JvmOverloads @JvmOverloads
fun enqueueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") { fun enqueueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") {
@ -240,7 +244,8 @@ class OpenHumansUploader @Inject constructor(
} }
@JvmOverloads @JvmOverloads
fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") { fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal?, deleted: Boolean = false) = temporaryBasal?.let {
insertQueueItem("TemporaryBasals") {
put("date", temporaryBasal.date) put("date", temporaryBasal.date)
put("isValid", temporaryBasal.isValid) put("isValid", temporaryBasal.isValid)
put("source", temporaryBasal.source) put("source", temporaryBasal.source)
@ -253,9 +258,11 @@ class OpenHumansUploader @Inject constructor(
put("absoluteRate", temporaryBasal.absoluteRate) put("absoluteRate", temporaryBasal.absoluteRate)
put("isDeletion", deleted) put("isDeletion", deleted)
} }
}
@JvmOverloads @JvmOverloads
fun enqueueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") { fun enqueueTempTarget(tempTarget: TempTarget?, deleted: Boolean = false) = tempTarget?.let {
insertQueueItem("TempTargets") {
put("date", tempTarget.date) put("date", tempTarget.date)
put("isValid", tempTarget.isValid) put("isValid", tempTarget.isValid)
put("source", tempTarget.source) put("source", tempTarget.source)
@ -266,8 +273,9 @@ class OpenHumansUploader @Inject constructor(
put("durationInMinutes", tempTarget.durationInMinutes) put("durationInMinutes", tempTarget.durationInMinutes)
put("isDeletion", deleted) 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 {