From 8f024598490f9e4e649247fc87a767c4b7916997 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 16 Jan 2020 15:46:53 +0100 Subject: [PATCH 1/2] #2369 Set event time for second event plus 1s too --- .../main/java/info/nightscout/androidaps/dialogs/FillDialog.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index 3eb4b0e379..f6ffbe6a2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -131,6 +131,7 @@ class FillDialog : DialogFragmentWithDate() { } if (insulinChange) { // add a second for case of both checked + careportalEvent.date = eventTime + 1000 careportalEvent.json = generateJson(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes).toString() careportalEvent.eventType = CareportalEvent.INSULINCHANGE NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) @@ -160,4 +161,4 @@ class FillDialog : DialogFragmentWithDate() { return data } -} \ No newline at end of file +} From a1c7aae7947e4ebad5823b1d51de73f6d5f9cbd1 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 16 Jan 2020 20:39:25 +0100 Subject: [PATCH 2/2] Refactor: dedup, method abstraction level. --- .../androidaps/dialogs/FillDialog.kt | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index f6ffbe6a2f..273d0b800d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -102,41 +102,15 @@ class FillDialog : DialogFragmentWithDate() { activity?.let { activity -> OKDialog.showConfirmation(activity, MainApp.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { if (insulinAfterConstraints > 0) { - val detailedBolusInfo = DetailedBolusInfo() - detailedBolusInfo.insulin = insulinAfterConstraints - detailedBolusInfo.context = context - detailedBolusInfo.source = Source.USER - detailedBolusInfo.isValid = false // do not count it in IOB (for pump history) - detailedBolusInfo.notes = notes - ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { - override fun run() { - if (!result.success) { - val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - MainApp.instance().startActivity(i) - } - } - }) + requestPrimeBolus(insulinAfterConstraints, notes) } - val careportalEvent = CareportalEvent() - careportalEvent.date = eventTime - careportalEvent.source = Source.USER if (siteChange) { - careportalEvent.json = generateJson(CareportalEvent.SITECHANGE, eventTime, notes).toString() - careportalEvent.eventType = CareportalEvent.SITECHANGE - NSUpload.uploadEvent(CareportalEvent.SITECHANGE, eventTime, notes) + generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes) } if (insulinChange) { // add a second for case of both checked - careportalEvent.date = eventTime + 1000 - careportalEvent.json = generateJson(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes).toString() - careportalEvent.eventType = CareportalEvent.INSULINCHANGE - NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) + generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) } - MainApp.getDbHelper().createOrUpdate(careportalEvent) }, null) } } else { @@ -148,7 +122,38 @@ class FillDialog : DialogFragmentWithDate() { return true } - fun generateJson(careportalEvent: String, time: Long, notes: String): JSONObject { + private fun requestPrimeBolus(insulin: Double, notes: String) { + val detailedBolusInfo = DetailedBolusInfo() + detailedBolusInfo.insulin = insulin + detailedBolusInfo.context = context + detailedBolusInfo.source = Source.USER + detailedBolusInfo.isValid = false // do not count it in IOB (for pump history) + detailedBolusInfo.notes = notes + ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { + override fun run() { + if (!result.success) { + val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java) + i.putExtra("soundid", R.raw.boluserror) + i.putExtra("status", result.comment) + i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + MainApp.instance().startActivity(i) + } + } + }) + } + + private fun generateCareportalEvent(eventType: String, time: Long, notes: String) { + val careportalEvent = CareportalEvent() + careportalEvent.source = Source.USER + careportalEvent.date = time + careportalEvent.json = generateJson(eventType, time, notes).toString() + careportalEvent.eventType = eventType + MainApp.getDbHelper().createOrUpdate(careportalEvent) + NSUpload.uploadEvent(eventType, time, notes) + } + + private fun generateJson(careportalEvent: String, time: Long, notes: String): JSONObject { val data = JSONObject() try { data.put("eventType", careportalEvent)