diff --git a/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt index d53f06e67c..ca26266f8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt @@ -16,13 +16,12 @@ class StatsActivity : NoSplashAppCompatActivity() { @Inject lateinit var tirCalculator: TirCalculator @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activityMonitor: ActivityMonitor - @Inject lateinit var dateUtil: DateUtil override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_stats) - stats_tdds.text = tddCalculator.stats(dateUtil) + stats_tdds.text = tddCalculator.stats() stats_tir.text = tirCalculator.stats() stats_activity.text = activityMonitor.stats() diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt index 8797bcfe70..ff3e361a9b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -31,7 +31,6 @@ class SurveyActivity : NoSplashAppCompatActivity() { @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var activityMonitor: ActivityMonitor @Inject lateinit var defaultProfile: DefaultProfile - @Inject lateinit var dateUtil: DateUtil override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -43,7 +42,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { val profileList = profileStore?.getProfileList() ?: return survey_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList) - survey_tdds.text = tddCalculator.stats(dateUtil) + survey_tdds.text = tddCalculator.stats() survey_tir.text = tirCalculator.stats() survey_activity.text = activityMonitor.stats() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 73effb19d8..28abd8eb60 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -170,7 +170,7 @@ class CarbsDialog : DialogFragmentWithDate() { eventTime -= eventTime % 1000 val time = eventTime + timeOffset * 1000 * 60 if (timeOffset != 0) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(time)) val duration = overview_carbs_duration.value.toInt() if (duration > 0) actions.add(resourceHelper.gs(R.string.duration) + ": " + duration + resourceHelper.gs(R.string.shorthour)) @@ -184,7 +184,7 @@ class CarbsDialog : DialogFragmentWithDate() { actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes) if (eventTimeChanged) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) { activity?.let { activity -> diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index 8a07e111b9..1eda2e060e 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -167,7 +167,7 @@ class CareDialog : DialogFragmentWithDate() { eventTime -= eventTime % 1000 if (eventTimeChanged) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) json.put("created_at", DateUtil.toISOString(eventTime)) json.put("mills", eventTime) 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 135eeb0e09..1300ee1612 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -112,7 +112,7 @@ class FillDialog : DialogFragmentWithDate() { eventTime -= eventTime % 1000 if (eventTimeChanged) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) if (insulinAfterConstraints > 0 || fill_catheter_change.isChecked || fill_cartridge_change.isChecked) { activity?.let { activity -> diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index e4fa54e2f3..f06f563874 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -145,7 +145,7 @@ class InsulinDialog : DialogFragmentWithDate() { val timeOffset = overview_insulin_time.value.toInt() val time = DateUtil.now() + T.mins(timeOffset.toLong()).msecs() if (timeOffset != 0) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(time)) val notes = notes.text.toString() if (notes.isNotEmpty()) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index 10be190380..72daeb1ad1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -98,7 +98,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { if (notes.isNotEmpty()) actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes) if (eventTimeChanged) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) activity?.let { activity -> OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 382e6359a5..9536da6928 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -23,6 +23,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var dateUtil: DateUtil private var time: Long = 0 @@ -67,7 +68,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { Mode.RUNNING_PROFILE -> { profile = treatmentsPlugin.getProfileSwitchFromHistory(time)?.profileObject profileName = treatmentsPlugin.getProfileSwitchFromHistory(time)?.customizedName - date = DateUtil.dateAndTimeString(treatmentsPlugin.getProfileSwitchFromHistory(time)?.date + date = dateUtil.dateAndTimeString(treatmentsPlugin.getProfileSwitchFromHistory(time)?.date ?: 0) profileview_datelayout.visibility = View.VISIBLE } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index 95ca3c0723..d2e9c0454f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -129,7 +129,7 @@ class TempTargetDialog : DialogFragmentWithDate() { actions.add(resourceHelper.gs(R.string.stoptemptarget)) } if (eventTimeChanged) - actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) activity?.let { activity -> OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt index ab8cae8666..f59a38d770 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt @@ -54,6 +54,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { @Inject lateinit var buildHelper: BuildHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var overviewMenus: OverviewMenus + @Inject lateinit var dateUtil: DateUtil private val disposable = CompositeDisposable() @@ -117,7 +118,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { cal.set(Calendar.MONTH, monthOfYear) cal.set(Calendar.DAY_OF_MONTH, dayOfMonth) start = cal.timeInMillis - historybrowse_date?.text = DateUtil.dateAndTimeString(start) + historybrowse_date?.text = dateUtil.dateAndTimeString(start) updateGUI("onClickDate") runCalculation("onClickDate") } @@ -236,7 +237,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { val lowLine = defaultValueHelper.determineLowLine() val highLine = defaultValueHelper.determineHighLine() - historybrowse_date?.text = DateUtil.dateAndTimeString(start) + historybrowse_date?.text = dateUtil.dateAndTimeString(start) historybrowse_zoom?.text = rangeToDisplay.toString() GlobalScope.launch(Dispatchers.Main) { @@ -248,7 +249,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { withContext(Dispatchers.Default) { val fromTime: Long = start + T.secs(100).msecs() val toTime: Long = start + T.hours(rangeToDisplay.toLong()).msecs() - aapsLogger.debug(LTag.UI, "Period: " + DateUtil.dateAndTimeString(fromTime) + " - " + DateUtil.dateAndTimeString(toTime)) + aapsLogger.debug(LTag.UI, "Period: " + dateUtil.dateAndTimeString(fromTime) + " - " + dateUtil.dateAndTimeString(toTime)) val pointer = System.currentTimeMillis() // **** In range Area **** diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt index 8334ce9567..4a81820fd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -27,9 +28,10 @@ class IobCobStaticCalculatorPlugin @Inject constructor( sensitivityOref1Plugin: SensitivityOref1Plugin, sensitivityAAPSPlugin: SensitivityAAPSPlugin, sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin, - fabricPrivacy: FabricPrivacy + fabricPrivacy: FabricPrivacy, + dateUtil: DateUtil ) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, - activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy) { + activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) { override fun onStart() { // do not attach to rxbus } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index 8463e8f133..4092f1d602 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -29,6 +29,7 @@ class LoopFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var dateUtil: DateUtil private var disposable: CompositeDisposable = CompositeDisposable() @@ -81,12 +82,12 @@ class LoopFragment : DaggerFragment() { loop_request?.text = it.request?.toSpanned() ?: "" loop_constraintsprocessed?.text = it.constraintsProcessed?.toSpanned() ?: "" loop_source?.text = it.source ?: "" - loop_lastrun?.text = DateUtil.dateAndTimeString(it.lastAPSRun) + loop_lastrun?.text = dateUtil.dateAndTimeString(it.lastAPSRun) ?: "" - loop_smbrequest_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastSMBRequest) - loop_smbexecution_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastSMBEnact) - loop_tbrrequest_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastTBRRequest) - loop_tbrexecution_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastTBREnact) + loop_smbrequest_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBRequest) + loop_smbexecution_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBEnact) + loop_tbrrequest_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBRRequest) + loop_tbrexecution_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBREnact) loop_tbrsetbypump?.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) } ?: "" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt index 342a1395f5..fcd78a9adc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt @@ -32,6 +32,7 @@ class OpenAPSAMAFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -96,7 +97,7 @@ class OpenAPSAMAFragment : DaggerFragment() { openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug } if (openAPSAMAPlugin.lastAPSRun != 0L) { - openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSAMAPlugin.lastAPSRun) + openapsma_lastrun.text = dateUtil.dateAndTimeString(openAPSAMAPlugin.lastAPSRun) } openAPSAMAPlugin.lastAutosensResult?.let { openapsma_autosensdata.text = JSONFormatter.format(it.json()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt index 95b0f7f7b8..c16a432370 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt @@ -33,6 +33,7 @@ class OpenAPSSMBFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -99,7 +100,7 @@ class OpenAPSSMBFragment : DaggerFragment() { } } if (openAPSSMBPlugin.lastAPSRun != 0L) { - openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSSMBPlugin.lastAPSRun) + openapsma_lastrun.text = dateUtil.dateAndTimeString(openAPSSMBPlugin.lastAPSRun) } openAPSSMBPlugin.lastAutosensResult?.let { openapsma_autosensdata.text = JSONFormatter.format(it.json()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt index 5fe20f2968..1e01d814f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt @@ -49,6 +49,8 @@ class ObjectivesFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var objectivesPlugin: ObjectivesPlugin @Inject lateinit var receiverStatusStore: ReceiverStatusStore + @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var sntpClient: SntpClient private val objectivesAdapter = ObjectivesAdapter() private val handler = Handler(Looper.getMainLooper()) @@ -221,7 +223,7 @@ class ObjectivesFragment : DaggerFragment() { holder.progress.addView(separator, LinearLayout.LayoutParams.MATCH_PARENT, 2) } } - holder.accomplished.text = resourceHelper.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn)) + holder.accomplished.text = resourceHelper.gs(R.string.accomplished, dateUtil.dateAndTimeString(objective.accomplishedOn)) holder.accomplished.setTextColor(-0x3e3e3f) holder.verify.setOnClickListener { receiverStatusStore.updateNetworkStatus() @@ -236,7 +238,7 @@ class ObjectivesFragment : DaggerFragment() { Thread { NtpProgressDialog().show((context as AppCompatActivity).supportFragmentManager, "NtpCheck") rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.timedetection), 0)) - SntpClient.ntpTime(object : SntpClient.Callback() { + sntpClient.ntpTime(object : SntpClient.Callback() { override fun run() { aapsLogger.debug("NTP time: $time System time: ${DateUtil.now()}") SystemClock.sleep(300) @@ -275,7 +277,7 @@ class ObjectivesFragment : DaggerFragment() { Thread { NtpProgressDialog().show((context as AppCompatActivity).supportFragmentManager, "NtpCheck") rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.timedetection), 0)) - SntpClient.ntpTime(object : SntpClient.Callback() { + sntpClient.ntpTime(object : SntpClient.Callback() { override fun run() { aapsLogger.debug("NTP time: $time System time: ${DateUtil.now()}") SystemClock.sleep(300) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index e6077e6e26..f14f7732dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -248,7 +248,7 @@ class ActionsFragment : DaggerFragment() { private fun checkPumpCustomActions() { val activePump = activePlugin.activePump - val customActions = activePump.customActions + val customActions = activePump.customActions ?: return removePumpCustomActions() for (customAction in customActions) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt index 4726eb5e95..6641286484 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt @@ -12,8 +12,11 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.T import org.json.JSONObject +import javax.inject.Inject class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) { + @Inject lateinit var dateUtil: DateUtil + var time = InputDateTime(injector) constructor(injector: HasAndroidInjector, runAt: Long) : this(injector) { @@ -57,7 +60,7 @@ class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) { override fun friendlyName(): Int = R.string.time override fun friendlyDescription(): String = - resourceHelper.gs(R.string.atspecifiedtime, DateUtil.dateAndTimeString(time.value)) + resourceHelper.gs(R.string.atspecifiedtime, dateUtil.dateAndTimeString(time.value)) override fun icon(): Optional = Optional.of(R.drawable.ic_access_alarm_24dp) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index 8cbb16a8dc..8fe577ced3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -699,7 +699,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O if (data.has("created_at")) { ret += resourceHelper.gs(R.string.event_time_label); ret += ": "; - ret += DateUtil.dateAndTimeString(eventTime); + ret += dateUtil.dateAndTimeString(eventTime); ret += "\n"; } if (data.has("enteredBy")) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 54de04db85..3187ccc924 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -90,6 +90,7 @@ public class NSClientService extends DaggerService { @Inject NSClientPlugin nsClientPlugin; @Inject BuildHelper buildHelper; @Inject Config config; + @Inject DateUtil dateUtil; private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private CompositeDisposable disposable = new CompositeDisposable(); @@ -721,7 +722,7 @@ public class NSClientService extends DaggerService { } handleNewSgv(sgvs, isDelta); } - rxBus.send(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData))); + rxBus.send(new EventNSClientNewLog("LAST", dateUtil.dateAndTimeString(latestDateInReceivedData))); } catch (JSONException e) { log.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt index 6c120fc576..faaa1b40d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt @@ -38,7 +38,8 @@ class TidepoolUploader @Inject constructor( private val resourceHelper: ResourceHelper, private val sp: SP, private val uploadChunk: UploadChunk, - private val activePlugin: ActivePluginProvider + private val activePlugin: ActivePluginProvider, + private val dateUtil: DateUtil ) { private var wl: PowerManager.WakeLock? = null @@ -233,7 +234,7 @@ class TidepoolUploader @Inject constructor( private fun uploadNext() { if (uploadChunk.getLastEnd() < DateUtil.now() - T.mins(1).msecs()) { SystemClock.sleep(3000) - aapsLogger.debug(LTag.TIDEPOOL, "Restarting doUpload. Last: " + DateUtil.dateAndTimeString(uploadChunk.getLastEnd())) + aapsLogger.debug(LTag.TIDEPOOL, "Restarting doUpload. Last: " + dateUtil.dateAndTimeString(uploadChunk.getLastEnd())) doUpload() } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt index 8ad1bdd0bc..4062f27bd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt @@ -29,7 +29,8 @@ class UploadChunk @Inject constructor( private val aapsLogger: AAPSLogger, private val profileFunction: ProfileFunction, private val treatmentsPlugin: TreatmentsPlugin, - private val activePlugin: ActivePluginProvider + private val activePlugin: ActivePluginProvider, + private val dateUtil: DateUtil ) { private val MAX_UPLOAD_SIZE = T.days(7).msecs() // don't change this @@ -51,9 +52,9 @@ class UploadChunk @Inject constructor( operator fun get(start: Long, end: Long): String { - aapsLogger.debug(LTag.TIDEPOOL, "Syncing data between: " + DateUtil.dateAndTimeString(start) + " -> " + DateUtil.dateAndTimeString(end)) + aapsLogger.debug(LTag.TIDEPOOL, "Syncing data between: " + dateUtil.dateAndTimeString(start) + " -> " + dateUtil.dateAndTimeString(end)) if (end <= start) { - aapsLogger.debug(LTag.TIDEPOOL, "End is <= start: " + DateUtil.dateAndTimeString(start) + " " + DateUtil.dateAndTimeString(end)) + aapsLogger.debug(LTag.TIDEPOOL, "End is <= start: " + dateUtil.dateAndTimeString(start) + " " + dateUtil.dateAndTimeString(end)) return "" } if (end - start > MAX_UPLOAD_SIZE) { @@ -85,11 +86,11 @@ class UploadChunk @Inject constructor( fun setLastEnd(time: Long) { if (time > getLastEnd()) { sp.putLong(R.string.key_tidepool_last_end, time) - val friendlyEnd = DateUtil.dateAndTimeString(time) + val friendlyEnd = dateUtil.dateAndTimeString(time) rxBus.send(EventTidepoolStatus(("Marking uploaded data up to $friendlyEnd"))) - aapsLogger.debug(LTag.TIDEPOOL, "Updating last end to: " + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.TIDEPOOL, "Updating last end to: " + dateUtil.dateAndTimeString(time)) } else { - aapsLogger.debug(LTag.TIDEPOOL, "Cannot set last end to: " + DateUtil.dateAndTimeString(time) + " vs " + DateUtil.dateAndTimeString(getLastEnd())) + aapsLogger.debug(LTag.TIDEPOOL, "Cannot set last end to: " + dateUtil.dateAndTimeString(time) + " vs " + dateUtil.dateAndTimeString(getLastEnd())) } } @@ -129,7 +130,7 @@ class UploadChunk @Inject constructor( } - internal fun getBgReadings(start: Long, end: Long): List { + private fun getBgReadings(start: Long, end: Long): List { val readings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, true) val selection = SensorGlucoseElement.fromBgReadings(readings) if (selection.isNotEmpty()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index fe5ac90449..c38c286122 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -69,6 +69,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat private final SensitivityAAPSPlugin sensitivityAAPSPlugin; private final SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin; private final FabricPrivacy fabricPrivacy; + private final DateUtil dateUtil; private CompositeDisposable disposable = new CompositeDisposable(); @@ -98,7 +99,8 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat SensitivityOref1Plugin sensitivityOref1Plugin, SensitivityAAPSPlugin sensitivityAAPSPlugin, SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.GENERAL) @@ -119,6 +121,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat this.sensitivityAAPSPlugin = sensitivityAAPSPlugin; this.sensitivityWeightedAveragePlugin = sensitivityWeightedAveragePlugin; this.fabricPrivacy = fabricPrivacy; + this.dateUtil = dateUtil; } @Override @@ -247,10 +250,10 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat // if close to now expect there can be some readings with time in close future (caused by wrong time setting) // so read all records bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false); - getAapsLogger().debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start)); + getAapsLogger().debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + dateUtil.dateAndTimeString(start)); } else { bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false); - getAapsLogger().debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to)); + getAapsLogger().debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + dateUtil.dateAndTimeString(start) + " End date: " + dateUtil.dateAndTimeString(to)); } } @@ -440,7 +443,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat if (limitDataToOldestAvailable) { getBGDataFrom = Math.max(oldestDataAvailable, (long) (from - T.hours(1).msecs() * (24 + dia))); if (getBGDataFrom == oldestDataAvailable) - getAapsLogger().debug(LTag.AUTOSENS, "Limiting data to oldest available temps: " + DateUtil.dateAndTimeString(oldestDataAvailable)); + getAapsLogger().debug(LTag.AUTOSENS, "Limiting data to oldest available temps: " + dateUtil.dateAndTimeString(oldestDataAvailable)); } else getBGDataFrom = (long) (from - T.hours(1).msecs() * (24 + dia)); return getBGDataFrom; @@ -675,7 +678,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat return null; } if (data.time < System.currentTimeMillis() - 11 * 60 * 1000) { - getAapsLogger().debug(LTag.AUTOSENS, "AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time)); + getAapsLogger().debug(LTag.AUTOSENS, "AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + dateUtil.dateAndTimeString(data.time)); return null; } else { getAapsLogger().debug(LTag.AUTOSENS, "AUTOSENSDATA (" + reason + ") " + data.toString()); @@ -686,7 +689,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat @Override public String lastDataTime() { if (autosensDataTable.size() > 0) - return DateUtil.dateAndTimeString(autosensDataTable.valueAt(autosensDataTable.size() - 1).time); + return dateUtil.dateAndTimeString(autosensDataTable.valueAt(autosensDataTable.size() - 1).time); else return "autosensDataTable empty"; } @@ -808,7 +811,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat } public void runCalculation(String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { - getAapsLogger().debug(LTag.AUTOSENS, "Starting calculation thread: " + from + " to " + DateUtil.dateAndTimeString(end)); + getAapsLogger().debug(LTag.AUTOSENS, "Starting calculation thread: " + from + " to " + dateUtil.dateAndTimeString(end)); if (thread == null || thread.getState() == Thread.State.TERMINATED) { if (sensitivityOref1Plugin.isEnabled()) thread = new IobCobOref1Thread(injector, from, end, bgDataReload, limitDataToOldestAvailable, cause); @@ -825,10 +828,10 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat synchronized (dataLock) { // clear up 5 min back for proper COB calculation long time = ev.getTime() - 5 * 60 * 1000L; - getAapsLogger().debug(LTag.AUTOSENS, "Invalidating cached data to: " + DateUtil.dateAndTimeString(time)); + getAapsLogger().debug(LTag.AUTOSENS, "Invalidating cached data to: " + dateUtil.dateAndTimeString(time)); for (int index = iobTable.size() - 1; index >= 0; index--) { if (iobTable.keyAt(index) > time) { - getAapsLogger().debug(LTag.AUTOSENS, "Removing from iobTable: " + DateUtil.dateAndTimeString(iobTable.keyAt(index))); + getAapsLogger().debug(LTag.AUTOSENS, "Removing from iobTable: " + dateUtil.dateAndTimeString(iobTable.keyAt(index))); iobTable.removeAt(index); } else { break; @@ -836,7 +839,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat } for (int index = absIobTable.size() - 1; index >= 0; index--) { if (absIobTable.keyAt(index) > time) { - getAapsLogger().debug(LTag.AUTOSENS, "Removing from absIobTable: " + DateUtil.dateAndTimeString(absIobTable.keyAt(index))); + getAapsLogger().debug(LTag.AUTOSENS, "Removing from absIobTable: " + dateUtil.dateAndTimeString(absIobTable.keyAt(index))); absIobTable.removeAt(index); } else { break; @@ -844,7 +847,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat } for (int index = autosensDataTable.size() - 1; index >= 0; index--) { if (autosensDataTable.keyAt(index) > time) { - getAapsLogger().debug(LTag.AUTOSENS, "Removing from autosensDataTable: " + DateUtil.dateAndTimeString(autosensDataTable.keyAt(index))); + getAapsLogger().debug(LTag.AUTOSENS, "Removing from autosensDataTable: " + dateUtil.dateAndTimeString(autosensDataTable.keyAt(index))); autosensDataTable.removeAt(index); } else { break; @@ -852,7 +855,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat } for (int index = basalDataTable.size() - 1; index >= 0; index--) { if (basalDataTable.keyAt(index) > time) { - getAapsLogger().debug(LTag.AUTOSENS, "Removing from basalDataTable: " + DateUtil.dateAndTimeString(basalDataTable.keyAt(index))); + getAapsLogger().debug(LTag.AUTOSENS, "Removing from basalDataTable: " + dateUtil.dateAndTimeString(basalDataTable.keyAt(index))); basalDataTable.removeAt(index); } else { break; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index b1762e3722..457b16716a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -68,6 +68,7 @@ public class IobCobOref1Thread extends Thread { @Inject BuildHelper buildHelper; @Inject Profiler profiler; @Inject FabricPrivacy fabricPrivacy; + @Inject DateUtil dateUtil; private final HasAndroidInjector injector; private boolean bgDataReload; @@ -122,7 +123,7 @@ public class IobCobOref1Thread extends Thread { } long prevDataTime = IobCobCalculatorPlugin.roundUpTime(bucketed_data.get(bucketed_data.size() - 3).date); - aapsLogger.debug(LTag.AUTOSENS, "Prev data time: " + DateUtil.dateAndTimeString(prevDataTime)); + aapsLogger.debug(LTag.AUTOSENS, "Prev data time: " + dateUtil.dateAndTimeString(prevDataTime)); AutosensData previous = autosensDataTable.get(prevDataTime); // start from oldest to be able sub cob for (int i = bucketed_data.size() - 4; i >= 0; i--) { @@ -378,7 +379,7 @@ public class IobCobOref1Thread extends Thread { previous = autosensData; if (bgTime < now()) autosensDataTable.put(bgTime, autosensData); - aapsLogger.debug(LTag.AUTOSENS, "Running detectSensitivity from: " + DateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + DateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + iobCobCalculatorPlugin.lastDataTime()); + aapsLogger.debug(LTag.AUTOSENS, "Running detectSensitivity from: " + dateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + dateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + iobCobCalculatorPlugin.lastDataTime()); AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime); aapsLogger.debug(LTag.AUTOSENS, "Sensitivity result: " + sensitivity.toString()); autosensData.autosensResult = sensitivity; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index d9ceb47dfc..84a02005e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -65,6 +65,7 @@ public class IobCobThread extends Thread { @Inject BuildHelper buildHelper; @Inject Profiler profiler; @Inject FabricPrivacy fabricPrivacy; + @Inject DateUtil dateUtil; private final HasAndroidInjector injector; private boolean bgDataReload; @@ -119,7 +120,7 @@ public class IobCobThread extends Thread { } long prevDataTime = IobCobCalculatorPlugin.roundUpTime(bucketed_data.get(bucketed_data.size() - 3).date); - aapsLogger.debug(LTag.AUTOSENS, "Prev data time: " + DateUtil.dateAndTimeString(prevDataTime)); + aapsLogger.debug(LTag.AUTOSENS, "Prev data time: " + dateUtil.dateAndTimeString(prevDataTime)); AutosensData previous = autosensDataTable.get(prevDataTime); // start from oldest to be able sub cob for (int i = bucketed_data.size() - 4; i >= 0; i--) { @@ -302,7 +303,7 @@ public class IobCobThread extends Thread { previous = autosensData; if (bgTime < now()) autosensDataTable.put(bgTime, autosensData); - aapsLogger.debug(LTag.AUTOSENS, "Running detectSensitivity from: " + DateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + DateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + iobCobCalculatorPlugin.lastDataTime()); + aapsLogger.debug(LTag.AUTOSENS, "Running detectSensitivity from: " + dateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + dateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + iobCobCalculatorPlugin.lastDataTime()); AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime); aapsLogger.debug(LTag.AUTOSENS, "Sensitivity result: " + sensitivity.toString()); autosensData.autosensResult = sensitivity; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index f26bacf8ec..ef64d4a690 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -14,6 +14,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged @@ -28,12 +29,14 @@ import java.text.DecimalFormat import javax.inject.Inject class LocalProfileFragment : DaggerFragment() { + @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var hardLimits: HardLimits + @Inject lateinit var dateUtil: DateUtil private var disposable: CompositeDisposable = CompositeDisposable() @@ -103,14 +106,14 @@ class LocalProfileFragment : DaggerFragment() { localprofile_name.addTextChangedListener(textWatch) localprofile_dia.setParams(localProfilePlugin.currentProfile().dia, hardLimits.MINDIA, hardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch) localprofile_dia.tag = "LP_DIA" - TimeListEdit(context, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.nsprofileview_ic_label), localProfilePlugin.currentProfile().ic, null, hardLimits.MINIC, hardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save) - basalView = TimeListEdit(context, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.nsprofileview_ic_label), localProfilePlugin.currentProfile().ic, null, hardLimits.MINIC, hardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save) + basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) if (units == Constants.MGDL) { - TimeListEdit(context, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label), localProfilePlugin.currentProfile().isf, null, hardLimits.MINISF, hardLimits.MAXISF, 1.0, DecimalFormat("0"), save) - TimeListEdit(context, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label), localProfilePlugin.currentProfile().isf, null, hardLimits.MINISF, hardLimits.MAXISF, 1.0, DecimalFormat("0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save) } else { - TimeListEdit(context, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label), localProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(hardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save) - TimeListEdit(context, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label), localProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(hardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save) } // Spinner @@ -187,10 +190,10 @@ class LocalProfileFragment : DaggerFragment() { localprofile_units.text = resourceHelper.gs(R.string.units_colon) + " " + (if (localProfilePlugin.currentProfile().mgdl) resourceHelper.gs(R.string.mgdl) else resourceHelper.gs(R.string.mmol)) localprofile_dia.setParams(localProfilePlugin.currentProfile().dia, MIN_DIA, 12.0, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch) localprofile_dia.tag = "LP_DIA" - TimeListEdit(context, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.nsprofileview_ic_label) + ":", localProfilePlugin.currentProfile().ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save) - TimeListEdit(context, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label) + ":", localProfilePlugin.currentProfile().isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save) - basalView = TimeListEdit(context, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) - TimeListEdit(context, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label) + ":", localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, 3.0, 200.0, 0.1, DecimalFormat("0.0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.nsprofileview_ic_label) + ":", localProfilePlugin.currentProfile().ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.nsprofileview_isf_label) + ":", localProfilePlugin.currentProfile().isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save) + basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) + TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.nsprofileview_target_label) + ":", localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, 3.0, 200.0, 0.1, DecimalFormat("0.0"), save) updateGUI() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index f4dd6a48df..0bb38acb76 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -65,6 +65,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI protected ResourceHelper resourceHelper; protected CommandQueueProvider commandQueue; protected SP sp; + protected DateUtil dateUtil; /* protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false) @@ -92,7 +93,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI ActivePluginProvider activePlugin, SP sp, Context context, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + DateUtil dateUtil ) { super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue); @@ -107,7 +109,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI pumpDescription.setPumpDescription(pumpType); this.pumpType = pumpType; - + this.dateUtil = dateUtil; } @@ -345,14 +347,14 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } ExtendedBolus eb = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis()); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index 623ecae9ef..bec19c7d1f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.resources.ResourceHelper; /** @@ -45,6 +46,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re @Inject MedtronicUtil medtronicUtil; @Inject AAPSLogger aapsLogger; @Inject RileyLinkServiceData rileyLinkServiceData; + @Inject DateUtil dateUtil; TextView connectionStatus; TextView configuredAddress; @@ -148,7 +150,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re rileyLinkServiceData.lastGoodFrequency)); if (medtronicPumpStatus.lastConnection != 0) - this.lastDeviceContact.setText(StringUtil.toDateTimeString(new LocalDateTime( + this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime( medtronicPumpStatus.lastDataTime))); else this.lastDeviceContact.setText(resourceHelper.gs(R.string.common_never)); @@ -182,7 +184,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re rileyLinkServiceData.lastGoodFrequency)); if (omnipodPumpStatus.lastConnection != 0) - this.lastDeviceContact.setText(StringUtil.toDateTimeString(new LocalDateTime( + this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime( omnipodPumpStatus.lastDataTime))); else this.lastDeviceContact.setText(resourceHelper.gs(R.string.common_never)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java index f8f79c821a..8a3ff18207 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java @@ -34,6 +34,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re @Inject RileyLinkUtil rileyLinkUtil; @Inject ResourceHelper resourceHelper; + @Inject DateUtil dateUtil; RecyclerView recyclerView; RecyclerViewAdapter recyclerViewAdapter; @@ -136,7 +137,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re RLHistoryItem item = historyList.get(position); if (item != null) { - holder.timeView.setText(DateUtil.dateAndTimeAndSecondsString(item.getDateTime().toDateTime().getMillis())); + holder.timeView.setText(dateUtil.dateAndTimeAndSecondsString(item.getDateTime().toDateTime().getMillis())); holder.typeView.setText(item.getSource().getDesc()); holder.valueView.setText(item.getDescription(resourceHelper)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java index f7d86e5774..cc9533e669 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java @@ -84,8 +84,8 @@ public class StringUtil { } - public static String toDateTimeString(LocalDateTime localDateTime) { - return DateUtil.dateAndTimeAndSecondsString(localDateTime.toDateTime().getMillis()); + public static String toDateTimeString(DateUtil dateUtil, LocalDateTime localDateTime) { + return dateUtil.dateAndTimeAndSecondsString(localDateTime.toDateTime().getMillis()); //return localDateTime.toString("dd.MM.yyyy HH:mm:ss"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 4fe2815bdc..50a94b0ca9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -59,6 +59,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump protected RxBusWrapper rxBus; protected TreatmentsPlugin treatmentsPlugin; protected SP sp; + protected DateUtil dateUtil; protected AbstractDanaRPlugin( HasAndroidInjector injector, @@ -69,7 +70,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump CommandQueueProvider commandQueue, RxBusWrapper rxBus, TreatmentsPlugin treatmentsPlugin, - SP sp + SP sp, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.PUMP) @@ -85,6 +87,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump this.rxBus = rxBus; this.treatmentsPlugin = treatmentsPlugin; this.sp = sp; + this.dateUtil = dateUtil; } @Override @@ -349,19 +352,19 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump status.put("timestamp", DateUtil.toISOString(pump.getLastConnection())); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); if (pump.getLastBolusTime() != 0) { - extended.put("LastBolus", DateUtil.dateAndTimeString(pump.getLastBolusTime())); + extended.put("LastBolus", dateUtil.dateAndTimeString(pump.getLastBolusTime())); extended.put("LastBolusAmount", pump.getLastBolusAmount()); } TemporaryBasal tb = treatmentsPlugin.getRealTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } ExtendedBolus eb = treatmentsPlugin.getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); } extended.put("BaseBasalRate", getBaseBasalRate()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java index 95fdc80829..e1f06d4017 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -58,9 +59,10 @@ public class DanaRPlugin extends AbstractDanaRPlugin { TreatmentsPlugin treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, - DanaRPump danaRPump + DanaRPump danaRPump, + DateUtil dateUtil ) { - super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp); + super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp, dateUtil); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt index 288e10ef9d..18ffab8460 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt @@ -47,6 +47,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { @Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Inject lateinit var danaRSPlugin: DanaRSPlugin @Inject lateinit var commandQueue: CommandQueueProvider + @Inject lateinit var dateUtil: DateUtil private val disposable = CompositeDisposable() @@ -143,7 +144,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { val record = historyList[position] - holder.time.text = DateUtil.dateAndTimeString(record.recordDate) + holder.time.text = dateUtil.dateAndTimeString(record.recordDate) holder.value.text = DecimalFormatter.to2Decimal(record.recordValue) holder.stringValue.text = record.stringRecordValue holder.bolusType.text = record.bolusType diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt index a81408b381..dd4c59cee4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* import javax.inject.Inject @@ -27,7 +28,8 @@ class MessageHashTableR @Inject constructor( configBuilderPlugin: ConfigBuilderPlugin, commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, - injector: HasAndroidInjector + injector: HasAndroidInjector, + dateUtil: DateUtil ) : MessageHashTableBase { var messages: HashMap = HashMap() @@ -39,11 +41,11 @@ class MessageHashTableR @Inject constructor( put(MsgBolusProgress(aapsLogger, resourceHelper, rxBus, danaRPump)) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin, injector)) // 0x0205 CMD_PUMP_EXERCISE_MODE - put(MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)) // 0x0207 CMD_PUMP_EXPANS_INS_I + put(MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)) // 0x0207 CMD_PUMP_EXPANS_INS_I put(MsgStatusBasic(aapsLogger, danaRPump)) // 0x020A CMD_PUMP_INITVIEW_I put(MsgStatus(aapsLogger, danaRPump)) // 0x020B CMD_PUMP_STATUS // 0x0301 CMD_PUMPINIT_TIME_INFO - put(MsgInitConnStatusTime(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue)) + put(MsgInitConnStatusTime(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, dateUtil)) put(MsgInitConnStatusBolus(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0302 CMD_PUMPINIT_BOLUS_INFO put(MsgInitConnStatusBasic(aapsLogger, danaRPump)) // 0x0303 CMD_PUMPINIT_INIT_INFO put(MsgInitConnStatusOption(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin)) // 0x0304 CMD_PUMPINIT_OPTION @@ -55,15 +57,15 @@ class MessageHashTableR @Inject constructor( put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT - put(MsgHistoryBolus(aapsLogger, rxBus)) // 0x3101 CMD_HISTORY_MEAL_INS - put(MsgHistoryDailyInsulin(aapsLogger, rxBus)) // 0x3102 CMD_HISTORY_DAY_INS - put(MsgHistoryGlucose(aapsLogger, rxBus)) // 0x3104 CMD_HISTORY_GLUCOSE - put(MsgHistoryAlarm(aapsLogger, rxBus)) // 0x3105 CMD_HISTORY_ALARM - put(MsgHistoryError(aapsLogger, rxBus)) // 0x3106 CMD_HISTORY_ERROR - put(MsgHistoryCarbo(aapsLogger, rxBus)) // 0x3107 CMD_HISTORY_CARBOHY - put(MsgHistoryRefill(aapsLogger, rxBus)) // 0x3108 CMD_HISTORY_REFILL - put(MsgHistorySuspend(aapsLogger, rxBus)) // 0x3109 CMD_HISTORY_SUSPEND - put(MsgHistoryBasalHour(aapsLogger, rxBus)) // 0x310A CMD_HISTORY_BASAL_HOUR + put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS + put(MsgHistoryDailyInsulin(aapsLogger, rxBus, dateUtil)) // 0x3102 CMD_HISTORY_DAY_INS + put(MsgHistoryGlucose(aapsLogger, rxBus, dateUtil)) // 0x3104 CMD_HISTORY_GLUCOSE + put(MsgHistoryAlarm(aapsLogger, rxBus, dateUtil)) // 0x3105 CMD_HISTORY_ALARM + put(MsgHistoryError(aapsLogger, rxBus, dateUtil)) // 0x3106 CMD_HISTORY_ERROR + put(MsgHistoryCarbo(aapsLogger, rxBus, dateUtil)) // 0x3107 CMD_HISTORY_CARBOHY + put(MsgHistoryRefill(aapsLogger, rxBus, dateUtil)) // 0x3108 CMD_HISTORY_REFILL + put(MsgHistorySuspend(aapsLogger, rxBus, dateUtil)) // 0x3109 CMD_HISTORY_SUSPEND + put(MsgHistoryBasalHour(aapsLogger, rxBus, dateUtil)) // 0x310A CMD_HISTORY_BASAL_HOUR put(MsgHistoryDone(aapsLogger, danaRPump)) // 0x31F1 CMD_HISTORY_DONT_USED // 0x3202 CMD_SETTING_V_BASAL_INS_I put(MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin)) @@ -74,7 +76,7 @@ class MessageHashTableR @Inject constructor( put(MsgSettingBasalProfileAll(aapsLogger, danaRPump)) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL put(MsgSettingShippingInfo(aapsLogger, danaRPump)) // 0x3207 CMD_SETTING_V_SHIPPING_I put(MsgSettingGlucose(aapsLogger, danaRPump)) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY - put(MsgSettingPumpTime(aapsLogger, danaRPump)) // 0x320A CMD_SETTING_V_TIME_I + put(MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)) // 0x320A CMD_SETTING_V_TIME_I put(MsgSettingUserOptions(aapsLogger, danaRPump)) // 0x320B CMD_SETTING_V_USER_OPTIONS put(MsgSettingActiveProfile(aapsLogger, danaRPump)) // 0x320C CMD_SETTING_V_PROFILE_NUMBER put(MsgSettingProfileRatiosAll(aapsLogger, danaRPump)) // 0x320D CMD_SETTING_V_CIR_CF_VALUE @@ -83,9 +85,9 @@ class MessageHashTableR @Inject constructor( put(MsgSetUserOptions(aapsLogger, danaRPump)) // 0x330B CMD_SETTING_USER_OPTIONS_S put(MsgSetActivateBasalProfile(aapsLogger, 0.toByte())) // 0x330C CMD_SETTING_PROFILE_NUMBER_S put(MsgHistoryAllDone(aapsLogger, danaRPump)) // 0x41F1 CMD_HISTORY_ALL_DONE - put(MsgHistoryAll(aapsLogger, rxBus)) // 0x41F2 CMD_HISTORY_ALL + put(MsgHistoryAll(aapsLogger, rxBus, dateUtil)) // 0x41F2 CMD_HISTORY_ALL put(MsgHistoryNewDone(aapsLogger, danaRPump)) // 0x42F1 CMD_HISTORY_NEW_DONE - put(MsgHistoryNew(aapsLogger, rxBus)) // 0x42F2 CMD_HISTORY_NEW + put(MsgHistoryNew(aapsLogger, rxBus, dateUtil)) // 0x42F2 CMD_HISTORY_NEW // 0xF0F1 CMD_PUMP_CHECK_VALUE put(MsgCheckValue(aapsLogger, danaRPump, danaRPlugin)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.kt index 142d0fea04..97c942fbf1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryAlarm( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3105) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt index 8c50099756..8b953a15f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt @@ -10,7 +10,8 @@ import info.nightscout.androidaps.utils.DateUtil open class MsgHistoryAll( val aapsLogger: AAPSLogger, - val rxBus: RxBusWrapper + val rxBus: RxBusWrapper, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -138,6 +139,6 @@ open class MsgHistoryAll( 17.toByte() -> failed = true } MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord) - rxBus.send(EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType)) + rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType)) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.kt index 2f235f38d1..87bfbbc870 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryBasalHour( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x310A) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.kt index 26e1506eac..693d56d462 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryBolus( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3101) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.kt index 8650e251a8..23e060d2a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryCarbo( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3107) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.kt index 60c1fffd14..5a978fc0ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryDailyInsulin( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3102) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.kt index 50d6cb9051..8883a704a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryError( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3106) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.kt index 07e2354f18..4f717dded1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryGlucose( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3104) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.kt index 0bf49cc612..b271f4f915 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryNew( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x42F2) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.kt index d77d0fbca7..24bb799db8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistoryRefill( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3108) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.kt index d3f947f77d..bd116ed709 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.kt @@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class MsgHistorySuspend( aapsLogger: AAPSLogger, - rxBus: RxBusWrapper -) : MsgHistoryAll(aapsLogger, rxBus) { + rxBus: RxBusWrapper, + dateUtil: DateUtil +) : MsgHistoryAll(aapsLogger, rxBus, dateUtil) { init { SetCommand(0x3109) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.kt index 1ff8eb0e9b..7d1ded9f8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.kt @@ -24,7 +24,8 @@ class MsgInitConnStatusTime( private val danaRPlugin: DanaRPlugin, private val danaRKoreanPlugin: DanaRKoreanPlugin, private val configBuilderPlugin: ConfigBuilderPlugin, - private val commandQueue: CommandQueueProvider + private val commandQueue: CommandQueueProvider, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -54,7 +55,7 @@ class MsgInitConnStatusTime( } val time = dateTimeSecFromBuff(bytes, 0) val versionCode = intFromBuff(bytes, 6, 1) - aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + dateUtil.dateAndTimeString(time)) aapsLogger.debug(LTag.PUMPCOMM, "Version code: $versionCode") } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.kt index 70971c431e..0fcdcd5589 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.kt @@ -7,13 +7,14 @@ import java.util.* class MsgSetTime( private val aapsLogger: AAPSLogger, + private val dateUtil: DateUtil, time: Date ) : MessageBase() { init { SetCommand(0x330a) AddParamDateTime(time) - aapsLogger.debug(LTag.PUMPCOMM, "New message: time:" + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.PUMPCOMM, "New message: time:" + dateUtil.dateAndTimeString(time)) } override fun handleMessage(bytes: ByteArray) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt index df356ca744..b8c9af91f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt @@ -8,7 +8,8 @@ import java.util.* class MsgSettingPumpTime( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -25,7 +26,7 @@ class MsgSettingPumpTime( intFromBuff(bytes, 1, 1), intFromBuff(bytes, 0, 1) ).time - aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time) + " Phone time: " + Date()) + aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + dateUtil.dateAndTimeString(time) + " Phone time: " + Date()) danaRPump.pumpTime = time } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.kt index 448b45346a..b7151d8add 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.kt @@ -14,7 +14,8 @@ class MsgStatusBolusExtended( private val injector: HasAndroidInjector, private val aapsLogger: AAPSLogger, private val danaRPump: DanaRPump, - private val activePlugin: ActivePluginProvider + private val activePlugin: ActivePluginProvider, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -48,7 +49,7 @@ class MsgStatusBolusExtended( aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus amount: $extendedBolusAmount") aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus so far in minutes: $extendedBolusSoFarInMinutes") aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus absolute rate: $extendedBolusAbsoluteRate") - aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus start: " + DateUtil.dateAndTimeString(extendedBolusStart)) + aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus start: " + dateUtil.dateAndTimeString(extendedBolusStart)) aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: $extendedBolusRemainingMinutes") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java index a72d813199..b6b707381f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java @@ -62,6 +62,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService { @Inject ResourceHelper resourceHelper; @Inject DanaRPump danaRPump; @Inject FabricPrivacy fabricPrivacy; + @Inject DateUtil dateUtil; private CompositeDisposable disposable = new CompositeDisposable(); @@ -228,31 +229,31 @@ public abstract class AbstractDanaRExecutionService extends DaggerService { MessageBase msg = null; switch (type) { case RecordTypes.RECORD_TYPE_ALARM: - msg = new MsgHistoryAlarm(aapsLogger, rxBus); + msg = new MsgHistoryAlarm(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_BASALHOUR: - msg = new MsgHistoryBasalHour(aapsLogger, rxBus); + msg = new MsgHistoryBasalHour(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_BOLUS: - msg = new MsgHistoryBolus(aapsLogger, rxBus); + msg = new MsgHistoryBolus(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_CARBO: - msg = new MsgHistoryCarbo(aapsLogger, rxBus); + msg = new MsgHistoryCarbo(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_DAILY: - msg = new MsgHistoryDailyInsulin(aapsLogger, rxBus); + msg = new MsgHistoryDailyInsulin(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_ERROR: - msg = new MsgHistoryError(aapsLogger, rxBus); + msg = new MsgHistoryError(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_GLUCOSE: - msg = new MsgHistoryGlucose(aapsLogger, rxBus); + msg = new MsgHistoryGlucose(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_REFILL: - msg = new MsgHistoryRefill(aapsLogger, rxBus); + msg = new MsgHistoryRefill(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_SUSPEND: - msg = new MsgHistorySuspend(aapsLogger, rxBus); + msg = new MsgHistorySuspend(aapsLogger, rxBus, dateUtil); break; } danaRPump.setHistoryDoneReceived(false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 510ba70578..f027216839 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -14,18 +14,19 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.dialogs.BolusProgressDialog; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; +import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; -import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; @@ -63,10 +64,8 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal; import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; @@ -143,7 +142,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { MsgStatus statusMsg = new MsgStatus(aapsLogger, danaRPump); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(aapsLogger, danaRPump); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin, injector); - MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin); + MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil); MsgCheckValue checkValue = new MsgCheckValue(aapsLogger, danaRPump, danaRPlugin); if (danaRPump.isNewPump()) { @@ -187,7 +186,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll(aapsLogger, danaRPump)); mSerialIOThread.sendMessage(new MsgSettingUserOptions(aapsLogger, danaRPump)); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump @@ -200,8 +199,8 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds"); if (Math.abs(timeDiff) > 10) { - mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, new Date())); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, dateUtil, new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds"); } @@ -252,7 +251,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(aapsLogger, constraintChecker, insulin, (byte) (durationInHalfHours & 0xFF))); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; } @@ -261,7 +260,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop(aapsLogger)); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; } @@ -350,7 +349,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { t.insulin = danaRPump.getLastBolusAmount(); aapsLogger.debug(LTag.PUMP, "Used bolus amount from history: " + danaRPump.getLastBolusAmount()); } else { - aapsLogger.debug(LTag.PUMP, "Bolus amount in history too old: " + DateUtil.dateAndTimeString(danaRPump.getLastBolusTime())); + aapsLogger.debug(LTag.PUMP, "Bolus amount in history too old: " + dateUtil.dateAndTimeString(danaRPump.getLastBolusTime())); } synchronized (o) { o.notify(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java index 57d14c36b4..580e7c4ad3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -60,10 +61,10 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { ConstraintChecker constraintChecker, TreatmentsPlugin treatmentsPlugin, SP sp, - CommandQueueProvider commandQueue - + CommandQueueProvider commandQueue, + DateUtil dateUtil ) { - super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp); + super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp, dateUtil); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt index 7c8f5ca33b..882ab11739 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.comm.* import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* import javax.inject.Inject @@ -28,6 +29,7 @@ class MessageHashTableRKorean @Inject constructor( configBuilderPlugin: ConfigBuilderPlugin, commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, + dateUtil: DateUtil, injector: HasAndroidInjector ) : MessageHashTableBase { @@ -39,10 +41,10 @@ class MessageHashTableRKorean @Inject constructor( put(MsgBolusProgress(aapsLogger, resourceHelper, rxBus, danaRPump)) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin, injector)) // 0x0205 CMD_PUMP_EXERCISE_MODE - put(MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)) // 0x0207 CMD_PUMP_EXPANS_INS_I + put(MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)) // 0x0207 CMD_PUMP_EXPANS_INS_I put(MsgStatusBasic_k(aapsLogger, danaRPump)) // 0x020A CMD_PUMP_INITVIEW_I put(MsgStatus_k(aapsLogger, danaRPump)) // 0x020B CMD_PUMP_STATUS - put(MsgInitConnStatusTime_k(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue)) // 0x0301 CMD_PUMPINIT_TIME_INFO + put(MsgInitConnStatusTime_k(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, dateUtil)) // 0x0301 CMD_PUMPINIT_TIME_INFO put(MsgInitConnStatusBolus_k(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin)) // 0x0302 CMD_PUMPINIT_BOLUS_INFO put(MsgInitConnStatusBasic_k(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0303 CMD_PUMPINIT_INIT_INFO put(MsgSetTempBasalStart(aapsLogger, 0, 0)) // 0x0401 CMD_PUMPSET_EXERCISE_S @@ -53,11 +55,11 @@ class MessageHashTableRKorean @Inject constructor( put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT - put(MsgHistoryBolus(aapsLogger, rxBus)) // 0x3101 CMD_HISTORY_MEAL_INS - put(MsgHistoryDailyInsulin(aapsLogger, rxBus)) // 0x3102 CMD_HISTORY_DAY_INS - put(MsgHistoryGlucose(aapsLogger, rxBus)) // 0x3104 CMD_HISTORY_GLUCOSE - put(MsgHistoryAlarm(aapsLogger, rxBus)) // 0x3105 CMD_HISTORY_ALARM - put(MsgHistoryCarbo(aapsLogger, rxBus)) // 0x3107 CMD_HISTORY_CARBOHY + put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS + put(MsgHistoryDailyInsulin(aapsLogger, rxBus, dateUtil)) // 0x3102 CMD_HISTORY_DAY_INS + put(MsgHistoryGlucose(aapsLogger, rxBus, dateUtil)) // 0x3104 CMD_HISTORY_GLUCOSE + put(MsgHistoryAlarm(aapsLogger, rxBus, dateUtil)) // 0x3105 CMD_HISTORY_ALARM + put(MsgHistoryCarbo(aapsLogger, rxBus, dateUtil)) // 0x3107 CMD_HISTORY_CARBOHY put(MsgSettingBasal_k(aapsLogger, danaRPump, danaRKoreanPlugin)) // 0x3202 CMD_SETTING_V_BASAL_INS_I put(MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin)) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I put(MsgSettingProfileRatios(aapsLogger, danaRPump)) // 0x3204 CMD_SETTING_V_CCC_I @@ -65,11 +67,11 @@ class MessageHashTableRKorean @Inject constructor( put(MsgSettingBasalProfileAll_k(aapsLogger, danaRPump)) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL put(MsgSettingShippingInfo(aapsLogger, danaRPump)) // 0x3207 CMD_SETTING_V_SHIPPING_I put(MsgSettingGlucose(aapsLogger, danaRPump)) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY - put(MsgSettingPumpTime(aapsLogger, danaRPump)) // 0x320A CMD_SETTING_V_TIME_I + put(MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)) // 0x320A CMD_SETTING_V_TIME_I put(MsgSetSingleBasalProfile(aapsLogger, rxBus, resourceHelper, Array(24) { 0.0 })) // 0x3302 CMD_SETTING_BASAL_INS_S - put(MsgHistoryAll(aapsLogger, rxBus)) // 0x41F2 CMD_HISTORY_ALL + put(MsgHistoryAll(aapsLogger, rxBus, dateUtil)) // 0x41F2 CMD_HISTORY_ALL put(MsgHistoryNewDone(aapsLogger, danaRPump)) // 0x42F1 CMD_HISTORY_NEW_DONE - put(MsgHistoryNew(aapsLogger, rxBus)) // 0x42F2 CMD_HISTORY_NEW + put(MsgHistoryNew(aapsLogger, rxBus, dateUtil)) // 0x42F2 CMD_HISTORY_NEW put(MsgCheckValue_k(aapsLogger, danaRPump, danaRKoreanPlugin)) // 0xF0F1 CMD_PUMP_CHECK_VALUE } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.kt index 77402e0389..78575809a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.kt @@ -25,7 +25,8 @@ class MsgInitConnStatusTime_k( private val danaRPlugin: DanaRPlugin, private val danaRKoreanPlugin: DanaRKoreanPlugin, private val configBuilderPlugin: ConfigBuilderPlugin, - private val commandQueue: CommandQueueProvider + private val commandQueue: CommandQueueProvider, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -55,7 +56,7 @@ class MsgInitConnStatusTime_k( val versionCode2 = intFromBuff(bytes, 7, 1) val versionCode3 = intFromBuff(bytes, 8, 1) val versionCode4 = intFromBuff(bytes, 9, 1) - aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + dateUtil.dateAndTimeString(time)) aapsLogger.debug(LTag.PUMPCOMM, "Version code1: $versionCode1") aapsLogger.debug(LTag.PUMPCOMM, "Version code2: $versionCode2") aapsLogger.debug(LTag.PUMPCOMM, "Version code3: $versionCode3") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index 96de7ad78d..0a0b0ce4c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -75,6 +75,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { @Inject MessageHashTableRKorean messageHashTableRKorean; @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject DateUtil dateUtil; public DanaRKoreanExecutionService() { } @@ -132,7 +133,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { //MsgStatus_k statusMsg = new MsgStatus_k(); MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k(aapsLogger, danaRPump); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin, injector); - MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin); + MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil); MsgCheckValue_k checkValue = new MsgCheckValue_k(aapsLogger, danaRPump, danaRKoreanPlugin); if (danaRPump.isNewPump()) { @@ -172,7 +173,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingGlucose(aapsLogger, danaRPump)); mSerialIOThread.sendMessage(new MsgSettingProfileRatios(aapsLogger, danaRPump)); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump @@ -187,8 +188,8 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (Math.abs(timeDiff) > 10) { waitForWholeMinute(); // Dana can set only whole minute // add 10sec to be sure we are over minute (will be cutted off anyway) - mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, new Date(DateUtil.now() + T.secs(10).msecs()))); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, dateUtil, new Date(DateUtil.now() + T.secs(10).msecs()))); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds"); } @@ -239,7 +240,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(aapsLogger, constraintChecker, insulin, (byte) (durationInHalfHours & 0xFF))); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; } @@ -248,7 +249,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop(aapsLogger)); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin)); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 8d5b8093b9..293faf8621 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -81,6 +81,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR private final CommandQueueProvider commandQueue; private final DanaRPump danaRPump; private final DetailedBolusInfoStorage detailedBolusInfoStorage; + private final DateUtil dateUtil; private static DanaRSService danaRSService; @@ -113,7 +114,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR SP sp, CommandQueueProvider commandQueue, DanaRPump danaRPump, - DetailedBolusInfoStorage detailedBolusInfoStorage + DetailedBolusInfoStorage detailedBolusInfoStorage, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.PUMP) @@ -134,6 +136,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR this.commandQueue = commandQueue; this.danaRPump = danaRPump; this.detailedBolusInfoStorage = detailedBolusInfoStorage; + this.dateUtil = dateUtil; pumpDescription.setPumpDescription(PumpType.DanaRS); } @@ -720,19 +723,19 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR status.put("timestamp", DateUtil.toISOString(pump.getLastConnection())); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); if (pump.getLastBolusTime() != 0) { - extended.put("LastBolus", DateUtil.dateAndTimeString(pump.getLastBolusTime())); + extended.put("LastBolus", dateUtil.dateAndTimeString(pump.getLastBolusTime())); extended.put("LastBolusAmount", pump.getLastBolusAmount()); } TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } ExtendedBolus eb = treatmentsPlugin.getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); } extended.put("BaseBasalRate", getBaseBasalRate()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index 3e64372fc7..0a4c81314d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -49,7 +49,7 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_Basal_Set_Suspend_Off(aapsLogger)) put(DanaRS_Packet_Basal_Set_Suspend_On(aapsLogger)) put(DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger)) - put(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + put(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)) put(DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)) put(DanaRS_Packet_Bolus_Get_Initial_Bolus(aapsLogger)) put(DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)) @@ -59,7 +59,7 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_Bolus_Get_Extended_Bolus(aapsLogger, danaRPump)) put(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) put(DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) + put(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump, dateUtil)) put(DanaRS_Packet_Bolus_Set_Bolus_Option(aapsLogger)) put(DanaRS_Packet_Bolus_Set_Initial_Bolus(aapsLogger)) put(DanaRS_Packet_Bolus_Set_CIR_CF_Array(aapsLogger)) @@ -77,33 +77,33 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger)) - put(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) + put(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump, dateUtil)) put(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) - put(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger)) + put(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, dateUtil)) put(DanaRS_Packet_Option_Set_User_Option(aapsLogger, danaRPump)) //put(new DanaRS_Packet_History_()); - put(DanaRS_Packet_History_Alarm(aapsLogger, rxBus)) - put(DanaRS_Packet_History_All_History(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Basal(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Bolus(aapsLogger, rxBus)) + put(DanaRS_Packet_History_Alarm(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_All_History(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Basal(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Bolus(aapsLogger, rxBus, dateUtil)) put(DanaRS_Packet_Review_Bolus_Avg(aapsLogger)) - put(DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Daily(aapsLogger, rxBus)) - put(DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump)) + put(DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Daily(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump, dateUtil)) put(DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)) - put(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)) + put(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil)) put(DanaRS_Packet_General_Get_Today_Delivery_Total(aapsLogger, danaRPump)) put(DanaRS_Packet_General_Get_User_Time_Change_Flag(aapsLogger)) - put(DanaRS_Packet_History_Prime(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Refill(aapsLogger, rxBus)) + put(DanaRS_Packet_History_Prime(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Refill(aapsLogger, rxBus, dateUtil)) put(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger)) put(DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(aapsLogger)) - put(DanaRS_Packet_History_Suspend(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus)) + put(DanaRS_Packet_History_Suspend(aapsLogger, rxBus, dateUtil)) + put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus, dateUtil)) // APS put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, injector, dateUtil, 0)) - put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) + put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, 0, 0, 0, 0)) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index a3b57d12ef..cb26675222 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -52,7 +52,7 @@ open class DanaRS_Packet_APS_History_Events( hour = cal[Calendar.HOUR_OF_DAY] min = cal[Calendar.MINUTE] sec = cal[Calendar.SECOND] - aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(cal.timeInMillis)) + aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(cal.timeInMillis)) danaRSPlugin.apsHistoryDone = false } @@ -83,7 +83,7 @@ open class DanaRS_Packet_APS_History_Events( val status: String when (recordCode.toInt()) { DanaRPump.TEMPSTART -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT TEMPSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min") temporaryBasal.percentRate = param1 temporaryBasal.durationInMinutes = param2 activePlugin.activeTreatments.addToHistoryTempBasal(temporaryBasal) @@ -91,13 +91,13 @@ open class DanaRS_Packet_APS_History_Events( } DanaRPump.TEMPSTOP -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime)) + aapsLogger.debug(LTag.PUMPCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime)) activePlugin.activeTreatments.addToHistoryTempBasal(temporaryBasal) status = "TEMPSTOP " + dateUtil.timeString(datetime) } DanaRPump.EXTENDEDSTART -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") extendedBolus.insulin = param1 / 100.0 extendedBolus.durationInMinutes = param2 activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus) @@ -105,7 +105,7 @@ open class DanaRS_Packet_APS_History_Events( } DanaRPump.EXTENDEDSTOP -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus) status = "EXTENDEDSTOP " + dateUtil.timeString(datetime) } @@ -118,7 +118,7 @@ open class DanaRS_Packet_APS_History_Events( detailedBolusInfo.pumpId = datetime detailedBolusInfo.insulin = param1 / 100.0 val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) - aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "BOLUS " + dateUtil.timeString(datetime) } @@ -130,12 +130,12 @@ open class DanaRS_Packet_APS_History_Events( detailedBolusInfo.pumpId = datetime detailedBolusInfo.insulin = param1 / 100.0 val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) - aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "DUALBOLUS " + dateUtil.timeString(datetime) } DanaRPump.DUALEXTENDEDSTART -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") extendedBolus.insulin = param1 / 100.0 extendedBolus.durationInMinutes = param2 activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus) @@ -143,33 +143,33 @@ open class DanaRS_Packet_APS_History_Events( } DanaRPump.DUALEXTENDEDSTOP -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus) status = "DUALEXTENDEDSTOP " + dateUtil.timeString(datetime) } DanaRPump.SUSPENDON -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDON (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") status = "SUSPENDON " + dateUtil.timeString(datetime) } DanaRPump.SUSPENDOFF -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") status = "SUSPENDOFF " + dateUtil.timeString(datetime) } DanaRPump.REFILL -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT REFILL (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") status = "REFILL " + dateUtil.timeString(datetime) } DanaRPump.PRIME -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIME (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") status = "PRIME " + dateUtil.timeString(datetime) } DanaRPump.PROFILECHANGE -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h") status = "PROFILECHANGE " + dateUtil.timeString(datetime) } @@ -180,17 +180,17 @@ open class DanaRS_Packet_APS_History_Events( emptyCarbsInfo.source = Source.PUMP emptyCarbsInfo.pumpId = datetime val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(emptyCarbsInfo, false) - aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") + aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") status = "CARBS " + dateUtil.timeString(datetime) } DanaRPump.PRIMECANNULA -> { - aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIMECANNULA(" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIMECANNULA(" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") status = "PRIMECANNULA " + dateUtil.timeString(datetime) } else -> { - aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) + aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) status = "UNKNOWN " + dateUtil.timeString(datetime) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt index 266554d3be..f513e6c7ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt @@ -9,6 +9,7 @@ import java.util.* class DanaRS_Packet_APS_Set_Event_History( private val aapsLogger: AAPSLogger, + private val dateUtil: DateUtil, private var packetType: Int, private var time: Long, private var param1: Int, @@ -18,7 +19,7 @@ class DanaRS_Packet_APS_Set_Event_History( init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY if ((packetType == DanaRPump.CARBS || packetType == DanaRPump.BOLUS) && param1 <= 0) this.param1 = 0 - aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + DateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2) + aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + dateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2) } override fun getRequestParams(): ByteArray { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt index fdc5c16480..7a2f523da8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt @@ -9,7 +9,8 @@ import kotlin.math.ceil class DanaRS_Packet_Basal_Get_Temporary_Basal_State( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : DanaRS_Packet() { init { @@ -35,7 +36,7 @@ class DanaRS_Packet_Basal_Get_Temporary_Basal_State( aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: " + danaRPump.tempBasalPercent) aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal remaining min: $tempBasalRemainingMin") aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal total sec: " + danaRPump.tempBasalTotalSec) - aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal start: " + DateUtil.dateAndTimeString(tempBasalStart)) + aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal start: " + dateUtil.dateAndTimeString(tempBasalStart)) } override fun getFriendlyName(): String { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt index e6c8121506..a78bf0c525 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt @@ -9,7 +9,8 @@ import java.util.* class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : DanaRS_Packet() { init { @@ -48,7 +49,7 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( aapsLogger.debug(LTag.PUMPCOMM, "Result: $error") aapsLogger.debug(LTag.PUMPCOMM, "BolusType: $bolusType") aapsLogger.debug(LTag.PUMPCOMM, "Initial bolus amount: " + danaRPump.initialBolusAmount + " U") - aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeString(danaRPump.lastBolusTime)) + aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + dateUtil.dateAndTimeString(danaRPump.lastBolusTime)) aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount) aapsLogger.debug(LTag.PUMPCOMM, "Max bolus: " + danaRPump.maxBolus + " U") aapsLogger.debug(LTag.PUMPCOMM, "Bolus step: " + danaRPump.bolusStep + " U") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt index b8e7e6bb53..a9b1b2df62 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt @@ -9,7 +9,8 @@ import java.util.* class DanaRS_Packet_General_Get_More_Information( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : DanaRS_Packet() { init { @@ -52,7 +53,7 @@ class DanaRS_Packet_General_Get_More_Information( aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits.toString() + " U") aapsLogger.debug(LTag.PUMPCOMM, "Is extended in progress: " + danaRPump.isExtendedInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: " + danaRPump.extendedBolusRemainingMinutes) - aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeAndSecondsString(lastBolusTime.time)) + aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + dateUtil.dateAndTimeAndSecondsString(lastBolusTime.time)) aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt index 00ebd4118a..6a60ea523a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt @@ -8,7 +8,8 @@ import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_General_Get_Shipping_Information( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : DanaRS_Packet() { init { @@ -31,7 +32,7 @@ class DanaRS_Packet_General_Get_Shipping_Information( dataSize = 3 danaRPump.shippingCountry = asciiStringFromBuff(data, dataIndex, dataSize) aapsLogger.debug(LTag.PUMPCOMM, "Serial number: " + danaRPump.serialNumber) - aapsLogger.debug(LTag.PUMPCOMM, "Shipping date: " + DateUtil.dateAndTimeString(danaRPump.shippingDate)) + aapsLogger.debug(LTag.PUMPCOMM, "Shipping date: " + dateUtil.dateAndTimeString(danaRPump.shippingDate)) aapsLogger.debug(LTag.PUMPCOMM, "Shipping country: " + danaRPump.shippingCountry) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt index e8da961028..dd62bc2136 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt @@ -13,6 +13,7 @@ import java.util.* abstract class DanaRS_Packet_History_( protected val aapsLogger: AAPSLogger, protected val rxBus: RxBusWrapper, + protected val dateUtil: DateUtil, protected val from: Long ) : DanaRS_Packet() { @@ -36,7 +37,7 @@ abstract class DanaRS_Packet_History_( hour = cal[Calendar.HOUR_OF_DAY] min = cal[Calendar.MINUTE] sec = cal[Calendar.SECOND] - aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(cal.timeInMillis)) + aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(cal.timeInMillis)) } override fun getRequestParams(): ByteArray { @@ -85,7 +86,7 @@ abstract class DanaRS_Packet_History_( val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1)) val paramByte8 = historyCode.toByte() val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF) - aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + DateUtil.dateAndTimeString(datetimewihtsec) + " Code: " + historyCode + " Value: " + value) + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec) + " Code: " + historyCode + " Value: " + value) val danaRHistoryRecord = DanaRHistoryRecord() danaRHistoryRecord.setBytes(data) // danaRHistoryRecord.recordCode is different from DanaR codes @@ -197,7 +198,7 @@ abstract class DanaRS_Packet_History_( } } MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord) - rxBus.send(EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType)) + rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType)) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt index 9b0c7ef4c6..360499cc21 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Alarm @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt index a8010b2127..8f6343604b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_All_History( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt index 0ac22574d5..e3268bcf1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Basal @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt index 6ebbeaed53..7235137871 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Blood_Glucose @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt index 47996fc8c6..1d7950e8b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Bolus @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt index 1084434962..03b84489cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Carbohydrate @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt index 93e974728d..74f3894e79 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Daily @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt index 0306e6f129..9d283e905c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Prime @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt index 672c5e2cc4..637fb1be0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Refill @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt index 9868cd10a4..3d35ec35dc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Suspend @JvmOverloads constructor( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt index b185748495..31258ea1b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt @@ -4,12 +4,14 @@ import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil class DanaRS_Packet_History_Temporary( aapsLogger: AAPSLogger, rxBus: RxBusWrapper, + dateUtil: DateUtil, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(aapsLogger, rxBus, dateUtil, from) { init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt index 2b18603d11..297804469c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt @@ -9,7 +9,8 @@ import java.util.* class DanaRS_Packet_Option_Get_Pump_Time( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : DanaRS_Packet() { init { @@ -39,7 +40,7 @@ class DanaRS_Packet_Option_Get_Pump_Time( val time = Date(100 + year, month - 1, day, hour, min, sec) danaRPump.pumpTime = time.time failed = year == month && month == day && day == hour && hour == min && min == sec && sec == 1 - aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + dateUtil.dateAndTimeString(time)) } override fun handleMessageNotReceived() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt index ec1a44c789..6739c50f57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt @@ -8,6 +8,7 @@ import java.util.* class DanaRS_Packet_Option_Set_Pump_Time( private val aapsLogger: AAPSLogger, + private val dateUtil: DateUtil, private var time: Long = 0 ) : DanaRS_Packet() { @@ -15,7 +16,7 @@ class DanaRS_Packet_Option_Set_Pump_Time( init { opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME - aapsLogger.debug(LTag.PUMPCOMM, "Setting pump time " + DateUtil.dateAndTimeString(time)) + aapsLogger.debug(LTag.PUMPCOMM, "Setting pump time " + dateUtil.dateAndTimeString(time)) } override fun getRequestParams(): ByteArray { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index 5122f012f8..359294ca00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -167,9 +167,9 @@ public class DanaRSService extends DaggerService { rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus))); bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)); // last bolus, bolusStep, maxBolus + bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump, dateUtil)); // last bolus, bolusStep, maxBolus rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)); danaRPump.setLastConnection(System.currentTimeMillis()); @@ -184,7 +184,7 @@ public class DanaRSService extends DaggerService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))); - bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump, dateUtil)); long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; if (danaRPump.getPumpTime() == 0) { @@ -198,7 +198,7 @@ public class DanaRSService extends DaggerService { long now = System.currentTimeMillis(); if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !pump.isInitialized()) { rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))); - bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)); // serial no + bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil)); // serial no bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)); // firmware bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)); bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)); // isExtendedEnabled @@ -228,13 +228,13 @@ public class DanaRSService extends DaggerService { return; } else { if (danaRPump.getProtocol() >= 6) { - bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now())); + bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, dateUtil, DateUtil.now())); } else { waitForWholeMinute(); // Dana can set only whole minute // add 10sec to be sure we are over minute (will be cutted off anyway) - bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs())); + bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, dateUtil, DateUtil.now() + T.secs(10).msecs())); } - bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump, dateUtil)); timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds"); } @@ -276,7 +276,7 @@ public class DanaRSService extends DaggerService { aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history"); } else { msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, injector, dateUtil, lastHistoryFetched); - aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)); + aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(lastHistoryFetched)); } bleComm.sendMessage(msg); while (!danaRSPlugin.apsHistoryDone && bleComm.isConnected()) { @@ -315,7 +315,7 @@ public class DanaRSService extends DaggerService { if (carbs > 0) { // MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); #### // bleComm.sendMessage(msg); - DanaRS_Packet_APS_Set_Event_History msgSetHistoryEntry_v2 = new DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, carbtime, carbs, 0); + DanaRS_Packet_APS_Set_Event_History msgSetHistoryEntry_v2 = new DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, carbtime, carbs, 0); bleComm.sendMessage(msgSetHistoryEntry_v2); lastHistoryFetched = Math.min(lastHistoryFetched, carbtime - T.mins(1).msecs()); } @@ -370,7 +370,7 @@ public class DanaRSService extends DaggerService { public void run() { // reread bolus status rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)); // last bolus + bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump, dateUtil)); // last bolus bolusingEvent.setPercent(100); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.disconnecting))); } @@ -403,7 +403,7 @@ public class DanaRSService extends DaggerService { rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, percent, durationInHours)); SystemClock.sleep(200); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -417,7 +417,7 @@ public class DanaRSService extends DaggerService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -436,7 +436,7 @@ public class DanaRSService extends DaggerService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -446,7 +446,7 @@ public class DanaRSService extends DaggerService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -493,31 +493,31 @@ public class DanaRSService extends DaggerService { DanaRS_Packet_History_ msg = null; switch (type) { case RecordTypes.RECORD_TYPE_ALARM: - msg = new DanaRS_Packet_History_Alarm(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Alarm(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_PRIME: - msg = new DanaRS_Packet_History_Prime(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Prime(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_BASALHOUR: - msg = new DanaRS_Packet_History_Basal(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Basal(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_BOLUS: - msg = new DanaRS_Packet_History_Bolus(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Bolus(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_CARBO: - msg = new DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_DAILY: - msg = new DanaRS_Packet_History_Daily(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Daily(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_GLUCOSE: - msg = new DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_REFILL: - msg = new DanaRS_Packet_History_Refill(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Refill(aapsLogger, rxBus, dateUtil); break; case RecordTypes.RECORD_TYPE_SUSPEND: - msg = new DanaRS_Packet_History_Suspend(aapsLogger, rxBus); + msg = new DanaRS_Packet_History_Suspend(aapsLogger, rxBus, dateUtil); break; } if (msg != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index 9a88ce28f3..72df8b9e68 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -66,9 +66,10 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { TreatmentsPlugin treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, - DetailedBolusInfoStorage detailedBolusInfoStorage + DetailedBolusInfoStorage detailedBolusInfoStorage, + DateUtil dateUtil ) { - super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp); + super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp, dateUtil); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt index f02062e05b..8833ea6b3f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt @@ -47,11 +47,11 @@ class MessageHashTableRv2 @Inject constructor( put(MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)) // 0x0104 CMD_MEALINS_START_DATA_SPEED put(MsgBolusProgress(aapsLogger, resourceHelper, rxBus, danaRPump)) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING - put(MsgStatusTempBasal_v2(aapsLogger, danaRPump)) // 0x0205 CMD_PUMP_EXERCISE_MODE + put(MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil)) // 0x0205 CMD_PUMP_EXERCISE_MODE put(MsgStatusBolusExtended_v2(aapsLogger, danaRPump)) // 0x0207 CMD_PUMP_EXPANS_INS_I put(MsgStatusBasic(aapsLogger, danaRPump)) // 0x020A CMD_PUMP_INITVIEW_I put(MsgStatus(aapsLogger, danaRPump)) // 0x020B CMD_PUMP_STATUS - put(MsgInitConnStatusTime(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue)) // 0x0301 CMD_PUMPINIT_TIME_INFO + put(MsgInitConnStatusTime(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, dateUtil)) // 0x0301 CMD_PUMPINIT_TIME_INFO put(MsgInitConnStatusBolus(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0302 CMD_PUMPINIT_BOLUS_INFO put(MsgInitConnStatusBasic(aapsLogger, danaRPump)) // 0x0303 CMD_PUMPINIT_INIT_INFO put(MsgInitConnStatusOption(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin)) // 0x0304 CMD_PUMPINIT_OPTION @@ -63,15 +63,15 @@ class MessageHashTableRv2 @Inject constructor( put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT - put(MsgHistoryBolus(aapsLogger, rxBus)) // 0x3101 CMD_HISTORY_MEAL_INS - put(MsgHistoryDailyInsulin(aapsLogger, rxBus)) // 0x3102 CMD_HISTORY_DAY_INS - put(MsgHistoryGlucose(aapsLogger, rxBus)) // 0x3104 CMD_HISTORY_GLUCOSE - put(MsgHistoryAlarm(aapsLogger, rxBus)) // 0x3105 CMD_HISTORY_ALARM - put(MsgHistoryError(aapsLogger, rxBus)) // 0x3106 CMD_HISTORY_ERROR - put(MsgHistoryCarbo(aapsLogger, rxBus)) // 0x3107 CMD_HISTORY_CARBOHY - put(MsgHistoryRefill(aapsLogger, rxBus)) // 0x3108 CMD_HISTORY_REFILL - put(MsgHistorySuspend(aapsLogger, rxBus)) // 0x3109 CMD_HISTORY_SUSPEND - put(MsgHistoryBasalHour(aapsLogger, rxBus)) // 0x310A CMD_HISTORY_BASAL_HOUR + put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS + put(MsgHistoryDailyInsulin(aapsLogger, rxBus, dateUtil)) // 0x3102 CMD_HISTORY_DAY_INS + put(MsgHistoryGlucose(aapsLogger, rxBus, dateUtil)) // 0x3104 CMD_HISTORY_GLUCOSE + put(MsgHistoryAlarm(aapsLogger, rxBus, dateUtil)) // 0x3105 CMD_HISTORY_ALARM + put(MsgHistoryError(aapsLogger, rxBus, dateUtil)) // 0x3106 CMD_HISTORY_ERROR + put(MsgHistoryCarbo(aapsLogger, rxBus, dateUtil)) // 0x3107 CMD_HISTORY_CARBOHY + put(MsgHistoryRefill(aapsLogger, rxBus, dateUtil)) // 0x3108 CMD_HISTORY_REFILL + put(MsgHistorySuspend(aapsLogger, rxBus, dateUtil)) // 0x3109 CMD_HISTORY_SUSPEND + put(MsgHistoryBasalHour(aapsLogger, rxBus, dateUtil)) // 0x310A CMD_HISTORY_BASAL_HOUR put(MsgHistoryDone(aapsLogger, danaRPump)) // 0x31F1 CMD_HISTORY_DONT_USED put(MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin)) // 0x3202 CMD_SETTING_V_BASAL_INS_I put(MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin)) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I @@ -80,7 +80,7 @@ class MessageHashTableRv2 @Inject constructor( put(MsgSettingBasalProfileAll(aapsLogger, danaRPump)) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL put(MsgSettingShippingInfo(aapsLogger, danaRPump)) // 0x3207 CMD_SETTING_V_SHIPPING_I put(MsgSettingGlucose(aapsLogger, danaRPump)) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY - put(MsgSettingPumpTime(aapsLogger, danaRPump)) // 0x320A CMD_SETTING_V_TIME_I + put(MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)) // 0x320A CMD_SETTING_V_TIME_I put(MsgSettingUserOptions(aapsLogger, danaRPump)) // 0x320B CMD_SETTING_V_USER_OPTIONS put(MsgSettingActiveProfile(aapsLogger, danaRPump)) // 0x320C CMD_SETTING_V_PROFILE_NUMBER put(MsgSettingProfileRatiosAll(aapsLogger, danaRPump)) // 0x320D CMD_SETTING_V_CIR_CF_VALUE @@ -89,9 +89,9 @@ class MessageHashTableRv2 @Inject constructor( put(MsgSetUserOptions(aapsLogger, danaRPump)) // 0x330B CMD_SETTING_USER_OPTIONS_S put(MsgSetActivateBasalProfile(aapsLogger, 0.toByte())) // 0x330C CMD_SETTING_PROFILE_NUMBER_S put(MsgHistoryAllDone(aapsLogger, danaRPump)) // 0x41F1 CMD_HISTORY_ALL_DONE - put(MsgHistoryAll(aapsLogger, rxBus)) // 0x41F2 CMD_HISTORY_ALL + put(MsgHistoryAll(aapsLogger, rxBus, dateUtil)) // 0x41F2 CMD_HISTORY_ALL put(MsgHistoryNewDone(aapsLogger, danaRPump)) // 0x42F1 CMD_HISTORY_NEW_DONE - put(MsgHistoryNew(aapsLogger, rxBus)) // 0x42F2 CMD_HISTORY_NEW + put(MsgHistoryNew(aapsLogger, rxBus, dateUtil)) // 0x42F2 CMD_HISTORY_NEW put(MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue)) // 0xF0F1 CMD_PUMP_CHECK_VALUE put(MsgStatusAPS_v2(aapsLogger, danaRPump)) // 0xE001 CMD_PUMPSTATUS_APS put(MsgSetAPSTempBasalStart_v2(aapsLogger, 0, false, false)) // 0xE002 CMD_PUMPSET_APSTEMP diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.kt index 4f07a49ff9..7b11695910 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.kt @@ -75,7 +75,7 @@ class MsgHistoryEvents_v2 constructor( val status: String when (recordCode.toInt()) { DanaRPump.TEMPSTART -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min") temporaryBasal.percentRate = param1 temporaryBasal.durationInMinutes = param2 treatmentsPlugin.addToHistoryTempBasal(temporaryBasal) @@ -83,13 +83,13 @@ class MsgHistoryEvents_v2 constructor( } DanaRPump.TEMPSTOP -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime)) + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime)) treatmentsPlugin.addToHistoryTempBasal(temporaryBasal) status = "TEMPSTOP " + dateUtil.timeString(datetime) } DanaRPump.EXTENDEDSTART -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") extendedBolus.insulin = param1 / 100.0 extendedBolus.durationInMinutes = param2 treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus) @@ -97,7 +97,7 @@ class MsgHistoryEvents_v2 constructor( } DanaRPump.EXTENDEDSTOP -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus) status = "EXTENDEDSTOP " + dateUtil.timeString(datetime) } @@ -110,7 +110,7 @@ class MsgHistoryEvents_v2 constructor( detailedBolusInfo.pumpId = datetime detailedBolusInfo.insulin = param1 / 100.0 val newRecord = treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false) - aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "BOLUS " + dateUtil.timeString(datetime) } @@ -122,12 +122,12 @@ class MsgHistoryEvents_v2 constructor( detailedBolusInfo.pumpId = datetime detailedBolusInfo.insulin = param1 / 100.0 val newRecord = treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false) - aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "DUALBOLUS " + dateUtil.timeString(datetime) } DanaRPump.DUALEXTENDEDSTART -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") extendedBolus.insulin = param1 / 100.0 extendedBolus.durationInMinutes = param2 treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus) @@ -135,33 +135,33 @@ class MsgHistoryEvents_v2 constructor( } DanaRPump.DUALEXTENDEDSTOP -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus) status = "DUALEXTENDEDSTOP " + dateUtil.timeString(datetime) } DanaRPump.SUSPENDON -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDON (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") status = "SUSPENDON " + dateUtil.timeString(datetime) } DanaRPump.SUSPENDOFF -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") status = "SUSPENDOFF " + dateUtil.timeString(datetime) } DanaRPump.REFILL -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT REFILL (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") status = "REFILL " + dateUtil.timeString(datetime) } DanaRPump.PRIME -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PRIME (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") status = "PRIME " + dateUtil.timeString(datetime) } DanaRPump.PROFILECHANGE -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h") + aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h") status = "PROFILECHANGE " + dateUtil.timeString(datetime) } @@ -172,12 +172,12 @@ class MsgHistoryEvents_v2 constructor( emptyCarbsInfo.source = Source.PUMP emptyCarbsInfo.pumpId = datetime val newRecord = treatmentsPlugin.addToHistoryTreatment(emptyCarbsInfo, false) - aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") + aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") status = "CARBS " + dateUtil.timeString(datetime) } else -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) + aapsLogger.debug(LTag.PUMPBTCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) status = "UNKNOWN " + dateUtil.timeString(datetime) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.kt index ac21c3f533..e4668fcd2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.kt @@ -9,8 +9,8 @@ import kotlin.math.ceil class MsgStatusTempBasal_v2( private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump - + private val danaRPump: DanaRPump, + private val dateUtil: DateUtil ) : MessageBase() { init { @@ -37,7 +37,7 @@ class MsgStatusTempBasal_v2( aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: $tempBasalPercent") aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal remaining min: $tempBasalRemainingMin") aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal total sec: $tempBasalTotalSec") - aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal start: " + DateUtil.dateAndTimeString(tempBasalStart)) + aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal start: " + dateUtil.dateAndTimeString(tempBasalStart)) } private fun getDateFromTempBasalSecAgo(tempBasalAgoSecs: Int): Long { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index ba2729c672..1433d3727f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -16,19 +16,20 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.activities.ErrorHelperActivity; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.dialogs.BolusProgressDialog; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; +import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; -import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; @@ -72,7 +73,6 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetAPSTempBasalSt import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetHistoryEntry_v2; import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusBolusExtended_v2; import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusTempBasal_v2; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; @@ -159,7 +159,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(aapsLogger, danaRPump); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(aapsLogger, danaRPump); - MsgStatusTempBasal_v2 tempStatusMsg = new MsgStatusTempBasal_v2(aapsLogger, danaRPump); + MsgStatusTempBasal_v2 tempStatusMsg = new MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil); MsgStatusBolusExtended_v2 exStatusMsg = new MsgStatusBolusExtended_v2(aapsLogger, danaRPump); MsgCheckValue_v2 checkValue = new MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue); @@ -191,7 +191,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump @@ -222,8 +222,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } else { waitForWholeMinute(); // Dana can set only whole minute // add 10sec to be sure we are over minute (will be cutted off anyway) - mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, new Date(DateUtil.now() + T.secs(10).msecs()))); - mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgSetTime(aapsLogger, dateUtil, new Date(DateUtil.now() + T.secs(10).msecs()))); + mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil)); timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds"); } @@ -274,7 +274,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(aapsLogger, percent, durationInHours)); - mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -289,7 +289,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(aapsLogger, percent, durationInMinutes == 15, durationInMinutes == 30)); - mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -309,7 +309,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(aapsLogger, percent, durationInMinutes == 15, durationInMinutes == 30)); - mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -319,7 +319,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return false; rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop(aapsLogger)); - mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump)); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil)); loadEvents(); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; @@ -450,7 +450,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { return new PumpEnactResult(injector).success(false); SystemClock.sleep(300); MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, rxBus, treatmentsPlugin, injector, dateUtil, lastHistoryFetched); - aapsLogger.debug(LTag.PUMP, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)); + aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(lastHistoryFetched)); mSerialIOThread.sendMessage(msg); while (!danaRv2Plugin.eventsLoadingDone && mRfcommSocket.isConnected()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index b147d01b10..d44470bad1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -150,6 +150,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, private final CommandQueueProvider commandQueue; private final ProfileFunction profileFunction; private final Context context; + private final DateUtil dateUtil; public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert"; @@ -209,7 +210,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, CommandQueueProvider commandQueue, ProfileFunction profileFunction, Context context, - Config config + Config config, + DateUtil dateUtil ) { super(new PluginDescription() .pluginName(R.string.insight_local) @@ -229,6 +231,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, this.commandQueue = commandQueue; this.profileFunction = profileFunction; this.context = context; + this.dateUtil = dateUtil; pumpDescription = new PumpDescription(); pumpDescription.setPumpDescription(PumpType.AccuChekInsightBluetooth); @@ -996,13 +999,13 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } ExtendedBolus eb = treatmentsPlugin.getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)); extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); } extended.put("BaseBasalRate", getBaseBasalRate()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 9d4b89675e..95a3f68c12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -84,6 +84,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButt import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -136,7 +137,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter MedtronicPumpStatus medtronicPumpStatus, MedtronicHistoryData medtronicHistoryData, RileyLinkServiceData rileyLinkServiceData, - ServiceTaskExecutor serviceTaskExecutor + ServiceTaskExecutor serviceTaskExecutor, + DateUtil dateUtil ) { super(new PluginDescription() // @@ -147,7 +149,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter .preferencesId(R.xml.pref_medtronic) .description(R.string.description_pump_medtronic), // PumpType.Medtronic_522_722, // we default to most basic model, correct model from config is loaded later - injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy + injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil ); this.rileyLinkUtil = rileyLinkUtil; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/RileyLinkStatusDeviceMedtronic.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/RileyLinkStatusDeviceMedtronic.java index 2a7ffa2ce4..616f033799 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/RileyLinkStatusDeviceMedtronic.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/RileyLinkStatusDeviceMedtronic.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.resources.ResourceHelper; /** @@ -32,6 +33,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; public class RileyLinkStatusDeviceMedtronic extends DaggerFragment implements RefreshableInterface { @Inject ResourceHelper resourceHelper; + @Inject DateUtil dateUtil; // @BindView(R.id.rileylink_history_list) ListView listView; @@ -153,7 +155,7 @@ public class RileyLinkStatusDeviceMedtronic extends DaggerFragment implements Re } RLHistoryItem item = historyItemList.get(i); - viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime())); + viewHolder.itemTime.setText(StringUtil.toDateTimeString(dateUtil, item.getDateTime())); viewHolder.itemSource.setText("Riley Link"); // for now viewHolder.itemDescription.setText(item.getDescription(resourceHelper)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 62adc49855..7f958a725c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -73,6 +73,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefres import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.TimeChangeType; @@ -136,7 +137,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump CommandQueueProvider commandQueue, FabricPrivacy fabricPrivacy, RileyLinkServiceData rileyLinkServiceData, - ServiceTaskExecutor serviceTaskExecutor) { + ServiceTaskExecutor serviceTaskExecutor, + DateUtil dateUtil + ) { super(new PluginDescription() // .mainType(PluginType.PUMP) // @@ -146,7 +149,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump .preferencesId(R.xml.pref_omnipod) // .description(R.string.description_pump_omnipod), // PumpType.Insulet_Omnipod, - injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy + injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil ); this.rileyLinkServiceData = rileyLinkServiceData; this.serviceTaskExecutor = serviceTaskExecutor; @@ -232,8 +235,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump ActivePluginProvider activePlugin, info.nightscout.androidaps.utils.sharedPreferences.SP sp, CommandQueueProvider commandQueue, - FabricPrivacy fabricPrivacy) { - super(pluginDescription, pumpType, injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy); + FabricPrivacy fabricPrivacy, + DateUtil dateUtil + ) { + super(pluginDescription, pumpType, injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil); // this.rileyLinkUtil = rileyLinkUtil; // this.medtronicUtil = medtronicUtil; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java index 22bd4293fe..5664b1b539 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java @@ -36,6 +36,7 @@ public class PodSessionState extends PodState { @Inject AAPSLogger aapsLogger; @Inject SP sp; @Inject OmnipodUtil omnipodUtil; + @Inject DateUtil dateUtil; private final Map configuredAlerts; private transient PodStateChangedHandler stateChangedHandler; @@ -112,7 +113,7 @@ public class PodSessionState extends PodState { } public String getExpiryDateAsString() { - return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate()); + return expiresAt == null ? "???" : dateUtil.dateAndTimeString(expiresAt.toDate()); } public FirmwareVersion getPiVersion() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index 9dbaea4025..3db377a230 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -52,7 +52,8 @@ class VirtualPumpPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val treatmentsPlugin: TreatmentsPlugin, commandQueue: CommandQueueProvider, - private val config: Config + private val config: Config, + private val dateUtil: DateUtil ) : PumpPluginBase(PluginDescription() .mainType(PluginType.PUMP) .fragmentClass(VirtualPumpFragment::class.java.name) @@ -356,13 +357,13 @@ class VirtualPumpPlugin @Inject constructor( val tb = treatmentsPlugin.getTempBasalFromHistory(now) if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)) - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)) + extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)) extended.put("TempBasalRemaining", tb.plannedRemainingMinutes) } val eb = treatmentsPlugin.getExtendedBolusFromHistory(now) if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()) - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)) + extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)) extended.put("ExtendedBolusRemaining", eb.plannedRemainingMinutes) } status.put("timestamp", DateUtil.toISOString(now)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java index 317a25bdf9..fc527bab94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java @@ -38,7 +38,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { private SP sp; private ProfileFunction profileFunction; - private ResourceHelper resourceHelper; + private DateUtil dateUtil; @Inject public SensitivityAAPSPlugin( @@ -46,7 +46,8 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { AAPSLogger aapsLogger, ResourceHelper resourceHelper, SP sp, - ProfileFunction profileFunction + ProfileFunction profileFunction, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.SENSITIVITY) @@ -58,6 +59,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { ); this.sp = sp; this.profileFunction = profileFunction; + this.dateUtil = dateUtil; } @NonNull @Override @@ -66,9 +68,9 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { String age = sp.getString(R.string.key_age, ""); int defaultHours = 24; - if (age.equals(resourceHelper.gs(R.string.key_adult))) defaultHours = 24; - if (age.equals(resourceHelper.gs(R.string.key_teenage))) defaultHours = 4; - if (age.equals(resourceHelper.gs(R.string.key_child))) defaultHours = 4; + if (age.equals(getResourceHelper().gs(R.string.key_adult))) defaultHours = 24; + if (age.equals(getResourceHelper().gs(R.string.key_teenage))) defaultHours = 4; + if (age.equals(getResourceHelper().gs(R.string.key_child))) defaultHours = 4; int hoursForDetection = sp.getInt(R.string.key_openapsama_autosens_period, defaultHours); Profile profile = profileFunction.getProfile(); @@ -85,7 +87,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { AutosensData current = iobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already if (current == null) { - getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + DateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); + getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + dateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); return new AutosensResult(); } @@ -116,7 +118,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { + if (new ProfileSwitch(getInjector()).isEvent5minBack(profileSwitches, autosensData.time, true)) { deviationsArray.clear(); pastSensitivity += "(PROFILESWITCH)"; } @@ -172,7 +174,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { sensResult, deviationsArray.size()); getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: " - + DateUtil.dateAndTimeString(toTime) + + + dateUtil.dateAndTimeString(toTime) + " ratio: " + output.ratio + " mealCOB: " + current.cob); getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: deviations " + Arrays.toString(deviations)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java index 97fb1a68bc..5740c7a5d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java @@ -35,7 +35,8 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; @Singleton public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { - private ProfileFunction profileFunction; + private final ProfileFunction profileFunction; + private final DateUtil dateUtil; @Inject public SensitivityOref1Plugin( @@ -43,7 +44,8 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { AAPSLogger aapsLogger, ResourceHelper resourceHelper, SP sp, - ProfileFunction profileFunction + ProfileFunction profileFunction, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.SENSITIVITY) @@ -56,6 +58,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { injector, aapsLogger, resourceHelper, sp ); this.profileFunction = profileFunction; + this.dateUtil = dateUtil; } @Override @@ -79,7 +82,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { // the current AutosensData current = iobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already if (current == null) { - getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + DateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); + getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + dateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); return new AutosensResult(); } @@ -125,7 +128,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { + if (new ProfileSwitch(getInjector()).isEvent5minBack(profileSwitches, autosensData.time, true)) { deviationsArray.clear(); pastSensitivity += "(PROFILESWITCH)"; } @@ -241,7 +244,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { sensResultArray.get(key) + comparison, deviationsHour.get(key).size()); getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: " - + DateUtil.dateAndTimeString(toTime) + + + dateUtil.dateAndTimeString(toTime) + " ratio: " + output.ratio + " mealCOB: " + current.cob); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java index d2128791d8..27b1820735 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java @@ -32,7 +32,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin { private SP sp; - private ResourceHelper resourceHelper; + private DateUtil dateUtil; private ProfileFunction profileFunction; @Inject @@ -41,7 +41,8 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin AAPSLogger aapsLogger, ResourceHelper resourceHelper, SP sp, - ProfileFunction profileFunction + ProfileFunction profileFunction, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.SENSITIVITY) @@ -52,7 +53,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin injector, aapsLogger, resourceHelper, sp ); this.sp = sp; - this.resourceHelper = resourceHelper; + this.dateUtil = dateUtil; this.profileFunction = profileFunction; } @@ -62,9 +63,9 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin String age = sp.getString(R.string.key_age, ""); int defaultHours = 24; - if (age.equals(resourceHelper.gs(R.string.key_adult))) defaultHours = 24; - if (age.equals(resourceHelper.gs(R.string.key_teenage))) defaultHours = 4; - if (age.equals(resourceHelper.gs(R.string.key_child))) defaultHours = 4; + if (age.equals(getResourceHelper().gs(R.string.key_adult))) defaultHours = 24; + if (age.equals(getResourceHelper().gs(R.string.key_teenage))) defaultHours = 4; + if (age.equals(getResourceHelper().gs(R.string.key_child))) defaultHours = 4; int hoursForDetection = sp.getInt(R.string.key_openapsama_autosens_period, defaultHours); if (autosensDataTable == null || autosensDataTable.size() < 4) { @@ -74,7 +75,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin AutosensData current = iobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already if (current == null) { - getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + DateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); + getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + dateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); return new AutosensResult(); } @@ -117,7 +118,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { + if (new ProfileSwitch(getInjector()).isEvent5minBack(profileSwitches, autosensData.time, true)) { data.clear(); pastSensitivity += "(PROFILESWITCH)"; } @@ -145,10 +146,10 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin } if (data.size() == 0) { - getAapsLogger().debug(LTag.AUTOSENS, "Data size: " + data.size() + " fromTime: " + DateUtil.dateAndTimeString(fromTime) + " toTime: " + DateUtil.dateAndTimeString(toTime)); + getAapsLogger().debug(LTag.AUTOSENS, "Data size: " + data.size() + " fromTime: " + dateUtil.dateAndTimeString(fromTime) + " toTime: " + dateUtil.dateAndTimeString(toTime)); return new AutosensResult(); } else { - getAapsLogger().debug(LTag.AUTOSENS, "Data size: " + data.size() + " fromTime: " + DateUtil.dateAndTimeString(fromTime) + " toTime: " + DateUtil.dateAndTimeString(toTime)); + getAapsLogger().debug(LTag.AUTOSENS, "Data size: " + data.size() + " fromTime: " + dateUtil.dateAndTimeString(fromTime) + " toTime: " + dateUtil.dateAndTimeString(toTime)); } double weightedsum = 0; @@ -192,7 +193,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin sensResult, data.size()); getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: " - + DateUtil.dateAndTimeString(toTime) + + + dateUtil.dateAndTimeString(toTime) + " ratio: " + output.ratio + " mealCOB: " + current.cob); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index 97b28f9dab..b01ba8d470 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -12,17 +12,16 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.db.BgReading -import info.nightscout.androidaps.db.DatabaseHelper import info.nightscout.androidaps.interfaces.DatabaseHelperInterface -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished import info.nightscout.androidaps.plugins.source.BGSourceFragment.RecyclerViewAdapter.BgReadingsViewHolder import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -34,6 +33,7 @@ class BGSourceFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var dateUtil: DateUtil @Inject lateinit var databaseHelper: DatabaseHelperInterface private val disposable = CompositeDisposable() @@ -84,7 +84,7 @@ class BGSourceFragment : DaggerFragment() { val bgReading = bgReadings[position] holder.ns.visibility = if (NSUpload.isIdValid(bgReading._id)) View.VISIBLE else View.GONE holder.invalid.visibility = if (!bgReading.isValid) View.VISIBLE else View.GONE - holder.date.text = DateUtil.dateAndTimeString(bgReading.date) + holder.date.text = dateUtil.dateAndTimeString(bgReading.date) holder.value.text = bgReading.valueToUnitsToString(profileFunction.getUnits()) holder.direction.text = bgReading.directionToSymbol(databaseHelper) holder.remove.tag = bgReading @@ -106,7 +106,7 @@ class BGSourceFragment : DaggerFragment() { remove.setOnClickListener { v: View -> val bgReading = v.tag as BgReading activity?.let { activity -> - val text = DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(profileFunction.getUnits()) + val text = dateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(profileFunction.getUnits()) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { bgReading.isValid = false MainApp.getDbHelper().update(bgReading) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt index 91683b3f4f..6b0021fbcf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt @@ -28,7 +28,8 @@ class EversensePlugin @Inject constructor( injector: HasAndroidInjector, private val sp: SP, resourceHelper: ResourceHelper, - aapsLogger: AAPSLogger + aapsLogger: AAPSLogger, + private val dateUtil: DateUtil ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -50,7 +51,7 @@ class EversensePlugin @Inject constructor( if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress")) if (bundle.containsKey("glucoseLevel")) aapsLogger.debug(LTag.BGSOURCE, "glucoseLevel: " + bundle.getInt("glucoseLevel")) if (bundle.containsKey("glucoseTrendDirection")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTrendDirection: " + bundle.getString("glucoseTrendDirection")) - if (bundle.containsKey("glucoseTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("glucoseTimestamp"))) + if (bundle.containsKey("glucoseTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamp: " + dateUtil.dateAndTimeString(bundle.getLong("glucoseTimestamp"))) if (bundle.containsKey("batteryLevel")) aapsLogger.debug(LTag.BGSOURCE, "batteryLevel: " + bundle.getString("batteryLevel")) if (bundle.containsKey("signalStrength")) aapsLogger.debug(LTag.BGSOURCE, "signalStrength: " + bundle.getString("signalStrength")) if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) @@ -58,7 +59,7 @@ class EversensePlugin @Inject constructor( if (bundle.containsKey("transmitterModelNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterModelNumber: " + bundle.getString("transmitterModelNumber")) if (bundle.containsKey("transmitterSerialNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterSerialNumber: " + bundle.getString("transmitterSerialNumber")) if (bundle.containsKey("transmitterAddress")) aapsLogger.debug(LTag.BGSOURCE, "transmitterAddress: " + bundle.getString("transmitterAddress")) - if (bundle.containsKey("sensorInsertionTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "sensorInsertionTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("sensorInsertionTimestamp"))) + if (bundle.containsKey("sensorInsertionTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "sensorInsertionTimestamp: " + dateUtil.dateAndTimeString(bundle.getLong("sensorInsertionTimestamp"))) if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) if (bundle.containsKey("transmitterConnectionState")) aapsLogger.debug(LTag.BGSOURCE, "transmitterConnectionState: " + bundle.getString("transmitterConnectionState")) if (bundle.containsKey("glucoseLevels")) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt index aa498105a6..daf570edc2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt @@ -70,7 +70,7 @@ class NSClientSourcePlugin @Inject constructor( private fun storeSgv(sgvJson: JSONObject) { val nsSgv = NSSgv(sgvJson) - val bgReading = BgReading(nsSgv) + val bgReading = BgReading(injector, nsSgv) MainApp.getDbHelper().createIfNotExists(bgReading, "NS") detectSource(safeGetString(sgvJson, "device", "none"), safeGetLong(sgvJson, "mills")) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index 698db2c81f..f83e522b30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -76,6 +76,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface private final ProfileFunction profileFunction; private final ActivePluginProvider activePlugin; private final FabricPrivacy fabricPrivacy; + private final DateUtil dateUtil; private CompositeDisposable disposable = new CompositeDisposable(); @@ -100,7 +101,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface SP sp, ProfileFunction profileFunction, ActivePluginProvider activePlugin, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + DateUtil dateUtil ) { super(new PluginDescription() .mainType(PluginType.TREATMENT) @@ -119,6 +121,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface this.profileFunction = profileFunction; this.activePlugin = activePlugin; this.fabricPrivacy = fabricPrivacy; + this.dateUtil = dateUtil; } @Override @@ -339,7 +342,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface last = t.date; } } - getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + DateUtil.dateAndTimeString(last)); + getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + dateUtil.dateAndTimeString(last)); return last; } @@ -354,7 +357,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface last = t.date; } } - getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + DateUtil.dateAndTimeString(last)); + getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + dateUtil.dateAndTimeString(last)); return last; } @@ -643,7 +646,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (!allowUpdate && !creatOrUpdateResult.success) { getAapsLogger().error("Treatment could not be added to DB", new Exception()); - String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, DateUtil.dateAndTimeString(treatment.date)); + String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date)); Intent i = new Intent(context, ErrorHelperActivity.class); i.putExtra("soundid", R.raw.error); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt index 673f9bdc23..63574ea8d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt @@ -42,6 +42,7 @@ class TreatmentsBolusFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -109,7 +110,7 @@ class TreatmentsBolusFragment : DaggerFragment() { override fun onBindViewHolder(holder: TreatmentsViewHolder, position: Int) { val profile = profileFunction.getProfile() ?: return val t = treatments[position] - holder.date.text = DateUtil.dateAndTimeString(t.date) + holder.date.text = dateUtil.dateAndTimeString(t.date) holder.insulin.text = resourceHelper.gs(R.string.formatinsulinunits, t.insulin) holder.carbs.text = resourceHelper.gs(R.string.format_carbs, t.carbs.toInt()) val iob = t.iobCalc(System.currentTimeMillis(), profile.dia) @@ -158,7 +159,7 @@ class TreatmentsBolusFragment : DaggerFragment() { val text = resourceHelper.gs(R.string.configbuilder_insulin) + ": " + resourceHelper.gs(R.string.formatinsulinunits, treatment.insulin) + "\n" + resourceHelper.gs(R.string.carbs) + ": " + resourceHelper.gs(R.string.format_carbs, treatment.carbs.toInt()) + "\n" + - resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(treatment.date) + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(treatment.date) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { if (treatment.source == Source.PUMP) { treatment.isValid = false diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt index d7a5e99496..9307238211 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt @@ -38,6 +38,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var translator: Translator + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -106,7 +107,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { override fun onBindViewHolder(holder: CareportalEventsViewHolder, position: Int) { val careportalEvent = careportalEventList[position] holder.ns.visibility = if (NSUpload.isIdValid(careportalEvent._id)) View.VISIBLE else View.GONE - holder.date.text = DateUtil.dateAndTimeString(careportalEvent.date) + holder.date.text = dateUtil.dateAndTimeString(careportalEvent.date) holder.duration.text = if (careportalEvent.durationInMsec() == 0L) "" else DateUtil.niceTimeScalar(careportalEvent.durationInMsec(), resourceHelper) holder.note.text = careportalEvent.notes holder.type.text = translator.translate(careportalEvent.eventType) @@ -132,7 +133,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { activity?.let { activity -> val text = resourceHelper.gs(R.string.careportal_newnstreatment_eventtype) + ": " + translator.translate(careportalEvent.eventType) + "\n" + resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + careportalEvent.notes + "\n" + - resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(careportalEvent.date) + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(careportalEvent.date) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { if (NSUpload.isIdValid(careportalEvent._id)) NSUpload.removeCareportalEntryFromNS(careportalEvent._id) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt index 175fb81c97..d2dcd632ea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt @@ -64,7 +64,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { holder.ph.visibility = if (extendedBolus.source == Source.PUMP) View.VISIBLE else View.GONE holder.ns.visibility = if (NSUpload.isIdValid(extendedBolus._id)) View.VISIBLE else View.GONE if (extendedBolus.isEndingEvent) { - holder.date.text = DateUtil.dateAndTimeString(extendedBolus.date) + holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) holder.duration.text = resourceHelper.gs(R.string.cancel) holder.insulin.text = "" holder.realDuration.text = "" @@ -73,8 +73,8 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { holder.ratio.text = "" } else { @SuppressLint("SetTextI18n") - if (extendedBolus.isInProgress) holder.date.text = DateUtil.dateAndTimeString(extendedBolus.date) - else holder.date.text = DateUtil.dateAndTimeString(extendedBolus.date) + " - " + dateUtil.timeString(extendedBolus.end()) + if (extendedBolus.isInProgress) holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) + else holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) + " - " + dateUtil.timeString(extendedBolus.end()) holder.duration.text = resourceHelper.gs(R.string.format_mins, extendedBolus.durationInMinutes) holder.insulin.text = resourceHelper.gs(R.string.formatinsulinunits, extendedBolus.insulin) @@ -113,7 +113,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { showConfirmation(it, resourceHelper.gs(R.string.removerecord), """ ${resourceHelper.gs(R.string.extended_bolus)} - ${resourceHelper.gs(R.string.date)}: ${DateUtil.dateAndTimeString(extendedBolus.date)} + ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.date)} """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface, _: Int -> val id = extendedBolus._id if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt index d45d547ef0..77934e304c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt @@ -43,6 +43,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { @Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -95,7 +96,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { val profileSwitch = profileSwitchList[position] holder.ph.visibility = (profileSwitch.source == Source.PUMP).toVisibility() holder.ns.visibility = NSUpload.isIdValid(profileSwitch._id).toVisibility() - holder.date.text = DateUtil.dateAndTimeString(profileSwitch.date) + holder.date.text = dateUtil.dateAndTimeString(profileSwitch.date) if (!profileSwitch.isEndingEvent) { holder.duration.text = resourceHelper.gs(R.string.format_mins, profileSwitch.durationInMinutes) } else { @@ -132,7 +133,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { activity?.let { activity -> OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), resourceHelper.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName + - "\n" + resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(profileSwitch.date), Runnable { + "\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { val id = profileSwitch._id if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) else UploadQueue.removeID("dbAdd", id) @@ -141,10 +142,10 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { } R.id.profileswitch_clone -> activity?.let { activity -> - OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date), Runnable { + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { profileSwitch.profileObject?.let { val nonCustomized = it.convertToNonCustomizedProfile() - localProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(localProfilePlugin.rawProfile, nonCustomized, profileSwitch.customizedName + " " + DateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_"))) + localProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(localProfilePlugin.rawProfile, nonCustomized, profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_"))) rxBus.send(EventLocalProfileChanged()) } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java index 8e1e6fb663..7df7db72be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java @@ -78,13 +78,13 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE); if (!tempTarget.isEndingEvent()) { - holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + dateUtil.timeString(tempTarget.originalEnd())); + holder.date.setText(dateUtil.dateAndTimeString(tempTarget.date) + " - " + dateUtil.timeString(tempTarget.originalEnd())); holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min"); holder.low.setText(tempTarget.lowValueToUnitsToString(units)); holder.high.setText(tempTarget.highValueToUnitsToString(units)); holder.reason.setText(tempTarget.reason); } else { - holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date)); + holder.date.setText(dateUtil.dateAndTimeString(tempTarget.date)); holder.duration.setText(R.string.cancel); holder.low.setText(""); holder.high.setText(""); @@ -142,7 +142,7 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { final TempTarget tempTarget = (TempTarget) v.getTag(); OKDialog.showConfirmation(getContext(), resourceHelper.gs(R.string.removerecord), resourceHelper.gs(R.string.careportal_temporarytarget) + ": " + tempTarget.friendlyDescription(profileFunction.getUnits(), resourceHelper) + - "\n" + DateUtil.dateAndTimeString(tempTarget.date), + "\n" + dateUtil.dateAndTimeString(tempTarget.date), (dialog, id) -> { final String _id = tempTarget._id; if (NSUpload.isIdValid(_id)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt index 99764c73bf..4ff6b15950 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -44,6 +44,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -88,7 +89,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { holder.ph.visibility = if (tempBasal.source == Source.PUMP) View.VISIBLE else View.GONE holder.ns.visibility = if (NSUpload.isIdValid(tempBasal._id)) View.VISIBLE else View.GONE if (tempBasal.isEndingEvent) { - holder.date.text = DateUtil.dateAndTimeString(tempBasal.date) + holder.date.text = dateUtil.dateAndTimeString(tempBasal.date) holder.duration.text = resourceHelper.gs(R.string.cancel) holder.absolute.text = "" holder.percent.text = "" @@ -100,10 +101,10 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { holder.iob.setTextColor(holder.netRatio.currentTextColor) } else { if (tempBasal.isInProgress) { - holder.date.text = DateUtil.dateAndTimeString(tempBasal.date) + holder.date.text = dateUtil.dateAndTimeString(tempBasal.date) holder.date.setTextColor(resourceHelper.gc(R.color.colorActive)) } else { - holder.date.text = DateUtil.dateAndTimeRangeString(tempBasal.date, tempBasal.end()) + holder.date.text = dateUtil.dateAndTimeRangeString(tempBasal.date, tempBasal.end()) holder.date.setTextColor(holder.netRatio.currentTextColor) } holder.duration.text = resourceHelper.gs(R.string.format_mins, tempBasal.durationInMinutes) @@ -160,7 +161,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { showConfirmation(it, resourceHelper.gs(R.string.removerecord), """ ${resourceHelper.gs(R.string.pump_tempbasal_label)}: ${tempBasal.toStringFull()} - ${resourceHelper.gs(R.string.date)}: ${DateUtil.dateAndTimeString(tempBasal.date)} + ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.date)} """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface?, _: Int -> val id = tempBasal._id diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt index a52a23bd09..f18ae1db9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt @@ -17,6 +17,7 @@ class CommandSMBBolus( callback: Callback? ) : Command(injector, CommandType.SMB_BOLUS, callback) { + @Inject lateinit var dateUtil: DateUtil @Inject lateinit var activePlugin: ActivePluginProvider override fun execute() { @@ -29,7 +30,7 @@ class CommandSMBBolus( r = activePlugin.activePump.deliverTreatment(detailedBolusInfo) } else { r = PumpEnactResult(injector).enacted(false).success(false).comment("SMB request too old") - aapsLogger.debug(LTag.PUMPQUEUE, "SMB bolus canceled. deliverAt: " + DateUtil.dateAndTimeString(detailedBolusInfo.deliverAt)) + aapsLogger.debug(LTag.PUMPQUEUE, "SMB bolus canceled. deliverAt: " + dateUtil.dateAndTimeString(detailedBolusInfo.deliverAt)) } aapsLogger.debug(LTag.PUMPQUEUE, "Result success: ${r.success} enacted: ${r.enacted}") callback?.result(r)?.run() diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index 4ca7055636..a3dda44325 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -39,6 +39,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var receiverStatusStore: ReceiverStatusStore @Inject lateinit var config: Config + @Inject lateinit var dateUtil: DateUtil companion object { private val KEEP_ALIVE_MILLISECONDS = T.mins(5).msecs() @@ -117,7 +118,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { val lastConnection = pump.lastDataTime() val isStatusOutdated = lastConnection + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis() val isBasalOutdated = abs(profile.basal - pump.baseBasalRate) > pump.pumpDescription.basalStep - aapsLogger.debug(LTag.CORE, "Last connection: " + DateUtil.dateAndTimeString(lastConnection)) + aapsLogger.debug(LTag.CORE, "Last connection: " + dateUtil.dateAndTimeString(lastConnection)) // sometimes keep alive broadcast stops // as as workaround test if readStatus was requested before an alarm is generated if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt index 77a269712f..eff444aa6e 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt @@ -30,7 +30,8 @@ class LocalAlertUtils @Inject constructor( private val activePlugin: ActivePluginProvider, private val profileFunction: ProfileFunction, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, - private val config: Config + private val config: Config, + private val dateUtil: DateUtil ) { fun missedReadingsThreshold(): Long { @@ -46,7 +47,7 @@ class LocalAlertUtils @Inject constructor( val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis() if (config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true) && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { - aapsLogger.debug(LTag.CORE, "Generating pump unreachable alarm. lastConnection: " + DateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated) + aapsLogger.debug(LTag.CORE, "Generating pump unreachable alarm. lastConnection: " + dateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated) val n = Notification(Notification.PUMP_UNREACHABLE, resourceHelper.gs(R.string.pump_unreachable), Notification.URGENT) n.soundId = R.raw.alarm sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java b/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java index 38ef842f8d..0bfa1cbd0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java @@ -23,6 +23,10 @@ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; +import javax.inject.Inject; +import javax.inject.Singleton; + +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; @@ -38,31 +42,42 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; * } * */ +@Singleton public class SntpClient { - private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.CORE); + private final AAPSLogger aapsLogger; + private final DateUtil dateUtil; + + //private final int REFERENCE_TIME_OFFSET = 16; + private final int ORIGINATE_TIME_OFFSET = 24; + private final int RECEIVE_TIME_OFFSET = 32; + private final int TRANSMIT_TIME_OFFSET = 40; + private final int NTP_PACKET_SIZE = 48; - //private static final int REFERENCE_TIME_OFFSET = 16; - private static final int ORIGINATE_TIME_OFFSET = 24; - private static final int RECEIVE_TIME_OFFSET = 32; - private static final int TRANSMIT_TIME_OFFSET = 40; - private static final int NTP_PACKET_SIZE = 48; + private final int NTP_PORT = 123; + private final int NTP_MODE_CLIENT = 3; + private final int NTP_VERSION = 3; - private static final int NTP_PORT = 123; - private static final int NTP_MODE_CLIENT = 3; - private static final int NTP_VERSION = 3; + @Inject + public SntpClient( + AAPSLogger aapsLogger, + DateUtil dateUtil + ) { + this.aapsLogger = aapsLogger; + this.dateUtil = dateUtil; + } // Number of seconds between Jan 1, 1900 and Jan 1, 1970 // 70 years plus 17 leap days - private static final long OFFSET_1900_TO_1970 = ((365L * 70L) + 17L) * 24L * 60L * 60L; + private final long OFFSET_1900_TO_1970 = ((365L * 70L) + 17L) * 24L * 60L * 60L; // system time computed from NTP server response - private static long mNtpTime; + private long mNtpTime; // value of SystemClock.elapsedRealtime() corresponding to mNtpTime - private static long mNtpTimeReference; + private long mNtpTimeReference; // round trip time in milliseconds - private static long mRoundTripTime; + private long mRoundTripTime; public static abstract class Callback implements Runnable { public boolean networkConnected = false; @@ -70,7 +85,7 @@ public class SntpClient { public long time = 0; } - public static synchronized void ntpTime(final Callback callback, boolean isConnected) { + public synchronized void ntpTime(final Callback callback, boolean isConnected) { callback.networkConnected = isConnected; if (callback.networkConnected) { new Thread(() -> doNtpTime(callback)).start(); @@ -79,11 +94,11 @@ public class SntpClient { } } - static void doNtpTime(final Callback callback) { - log.debug("Time detection started"); + void doNtpTime(final Callback callback) { + aapsLogger.debug("Time detection started"); callback.success = requestTime("time.google.com", 5000); callback.time = getNtpTime() + SystemClock.elapsedRealtime() - getNtpTimeReference(); - log.debug("Time detection ended: " + callback.success + " " + DateUtil.dateAndTimeString(getNtpTime())); + aapsLogger.debug("Time detection ended: " + callback.success + " " + dateUtil.dateAndTimeString(getNtpTime())); callback.run(); } @@ -94,7 +109,7 @@ public class SntpClient { * @param timeout network timeout in milliseconds. * @return true if the transaction was successful. */ - private static synchronized boolean requestTime(String host, int timeout) { + private synchronized boolean requestTime(String host, int timeout) { try { DatagramSocket socket = new DatagramSocket(); socket.setSoTimeout(timeout); @@ -144,7 +159,7 @@ public class SntpClient { mNtpTimeReference = responseTicks; mRoundTripTime = roundTripTime; } catch (Exception e) { - log.debug("request time failed: " + e); + aapsLogger.debug("request time failed: " + e); return false; } @@ -156,7 +171,7 @@ public class SntpClient { * * @return time value computed from NTP server response. */ - private static long getNtpTime() { + private long getNtpTime() { return mNtpTime; } @@ -166,7 +181,7 @@ public class SntpClient { * * @return reference clock corresponding to the NTP time. */ - private static long getNtpTimeReference() { + private long getNtpTimeReference() { return mNtpTimeReference; } @@ -182,7 +197,7 @@ public class SntpClient { /** * Reads an unsigned 32 bit big endian number from the given offset in the buffer. */ - private static long read32(byte[] buffer, int offset) { + private long read32(byte[] buffer, int offset) { byte b0 = buffer[offset]; byte b1 = buffer[offset + 1]; byte b2 = buffer[offset + 2]; @@ -201,7 +216,7 @@ public class SntpClient { * Reads the NTP time stamp at the given offset in the buffer and returns * it as a system time (milliseconds since January 1, 1970). */ - private static long readTimeStamp(byte[] buffer, int offset) { + private long readTimeStamp(byte[] buffer, int offset) { long seconds = read32(buffer, offset); long fraction = read32(buffer, offset + 4); return ((seconds - OFFSET_1900_TO_1970) * 1000) + ((fraction * 1000L) / 0x100000000L); @@ -211,7 +226,7 @@ public class SntpClient { * Writes system time (milliseconds since January 1, 1970) as an NTP time stamp * at the given offset in the buffer. */ - private static void writeTimeStamp(byte[] buffer, int offset, long time) { + private void writeTimeStamp(byte[] buffer, int offset, long time) { long seconds = time / 1000L; long milliseconds = time - seconds * 1000L; seconds += OFFSET_1900_TO_1970; diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index 892f9b2667..3386dd9235 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -29,6 +29,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; /** @@ -36,7 +37,8 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; */ public class TimeListEdit { - private static Logger log = StacktraceLoggerWrapper.getLogger(TimeListEdit.class); + private final AAPSLogger aapsLogger; + private final DateUtil dateUtil; private final int ONEHOURINSECONDS = 60 * 60; @@ -65,8 +67,14 @@ public class TimeListEdit { private int inflatedUntil = -1; - public TimeListEdit(Context context, View view, int resLayoutId, String tagPrefix, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) { + public TimeListEdit( + Context context, + AAPSLogger aapsLogger, + DateUtil dateUtil, + View view, int resLayoutId, String tagPrefix, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) { this.context = context; + this.aapsLogger = aapsLogger; + this.dateUtil = dateUtil; this.view = view; this.resLayoutId = resLayoutId; this.tagPrefix = tagPrefix; @@ -281,7 +289,7 @@ public class TimeListEdit { ArrayList timeListValues = new ArrayList<>(); int pos = 0; for (int t = previous + ONEHOURINSECONDS; t < next; t += ONEHOURINSECONDS) { - timeList.add(DateUtil.timeStringFromSeconds(t)); + timeList.add(dateUtil.timeStringFromSeconds(t)); timeListValues.add(t); if (secondsFromMidnight == t) posInList = pos; pos++; @@ -311,7 +319,7 @@ public class TimeListEdit { return time; } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } return 0; } @@ -323,7 +331,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } return 0d; } @@ -336,7 +344,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } return 0d; @@ -362,7 +370,7 @@ public class TimeListEdit { data2.put(index, newObject2); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } @@ -383,7 +391,7 @@ public class TimeListEdit { // add new object editItem(index, timeAsSeconds, value1, value2); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } @@ -396,7 +404,7 @@ public class TimeListEdit { private void log() { for (int i = 0; i < data1.length(); i++) { - log.debug(i + ": @" + DateUtil.timeStringFromSeconds(secondFromMidnight(i)) + " " + value1(i) + (data2 != null ? " " + value2(i) : "")); + aapsLogger.debug(i + ": @" + dateUtil.timeStringFromSeconds(secondFromMidnight(i)) + " " + value1(i) + (data2 != null ? " " + value2(i) : "")); } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt index 6d4895f1f3..6ee3024fc6 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt @@ -31,8 +31,9 @@ class TddCalculator @Inject constructor( val sp: SP, val activePlugin: ActivePluginProvider, val profileFunction: ProfileFunction, - fabricPrivacy: FabricPrivacy -) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, fabricPrivacy) { + fabricPrivacy: FabricPrivacy, + private val dateUtil: DateUtil +) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, fabricPrivacy, dateUtil) { init { service = TreatmentService(injector) // plugin is not started @@ -85,18 +86,18 @@ class TddCalculator @Inject constructor( return totalTdd } - fun stats(dateUtil: DateUtil): Spanned { + fun stats(): Spanned { val tdds = calculate(7) val averageTdd = averageTDD(tdds) return HtmlHelper.fromHtml( "" + resourceHelper.gs(R.string.tdd) + ":
" + - toText(tdds, dateUtil) + + toText(tdds) + "" + resourceHelper.gs(R.string.average) + ":
" + averageTdd.toText(resourceHelper, tdds.size()) ) } - private fun toText(tdds: LongSparseArray, dateUtil: DateUtil): String { + private fun toText(tdds: LongSparseArray): String { var t = "" for (i in 0 until tdds.size()) { t += "${tdds.valueAt(i).toText(resourceHelper, dateUtil)}
" diff --git a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 188266fbb3..7542f104e7 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -26,6 +27,7 @@ open class TestBaseWithProfile : TestBase() { @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var defaultValueHelper: DefaultValueHelper + @Mock lateinit var dateUtil: DateUtil val rxBus = RxBusWrapper() @@ -37,12 +39,14 @@ open class TestBaseWithProfile : TestBase() { it.resourceHelper = resourceHelper it.rxBus = rxBus it.fabricPrivacy = fabricPrivacy + it.configInterface = Config() } if (it is ProfileSwitch) { it.treatmentsPlugin = treatmentsPlugin it.aapsLogger = aapsLogger it.rxBus = rxBus it.resourceHelper = resourceHelper + it.dateUtil = dateUtil } if (it is Treatment) { it.activePlugin = activePluginProvider diff --git a/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt b/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt index 7e37b24660..4b930d4947 100644 --- a/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt @@ -1,13 +1,16 @@ package info.nightscout.androidaps.db +import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert @@ -31,6 +34,7 @@ class BgReadingTest : TestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var resourceHelper: ResourceHelper + @Mock lateinit var databaseHelper: DatabaseHelperInterface var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -55,21 +59,21 @@ class BgReadingTest : TestBase() { fun directionToSymbol() { val bgReading = BgReading(injector) bgReading.direction = "DoubleDown" - Assert.assertEquals("\u21ca", bgReading.directionToSymbol()) + Assert.assertEquals("\u21ca", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "SingleDown" - Assert.assertEquals("\u2193", bgReading.directionToSymbol()) + Assert.assertEquals("\u2193", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "FortyFiveDown" - Assert.assertEquals("\u2198", bgReading.directionToSymbol()) + Assert.assertEquals("\u2198", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "Flat" - Assert.assertEquals("\u2192", bgReading.directionToSymbol()) + Assert.assertEquals("\u2192", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "FortyFiveUp" - Assert.assertEquals("\u2197", bgReading.directionToSymbol()) + Assert.assertEquals("\u2197", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "SingleUp" - Assert.assertEquals("\u2191", bgReading.directionToSymbol()) + Assert.assertEquals("\u2191", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "DoubleUp" - Assert.assertEquals("\u21c8", bgReading.directionToSymbol()) + Assert.assertEquals("\u21c8", bgReading.directionToSymbol(databaseHelper)) bgReading.direction = "OUT OF RANGE" - Assert.assertEquals("??", bgReading.directionToSymbol()) + Assert.assertEquals("??", bgReading.directionToSymbol(databaseHelper)) } @Test fun dateTest() { @@ -88,8 +92,8 @@ class BgReadingTest : TestBase() { } @Test fun copyFromTest() { - val databaseHelper = Mockito.mock(DatabaseHelper::class.java) - `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) +// val databaseHelper = Mockito.mock(DatabaseHelper::class.java) +// `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) setReadings(72, 0) val bgReading = BgReading(injector) val copy = BgReading(injector) @@ -100,7 +104,7 @@ class BgReadingTest : TestBase() { copy.copyFrom(bgReading) Assert.assertEquals(81.0, copy.value, 0.1) Assert.assertEquals(now, copy.date) - Assert.assertEquals(bgReading.directionToSymbol(), copy.directionToSymbol()) + Assert.assertEquals(bgReading.directionToSymbol(databaseHelper), copy.directionToSymbol(databaseHelper)) } @Test @@ -119,34 +123,28 @@ class BgReadingTest : TestBase() { @Test fun calculateDirection() { val bgReading = BgReading(injector) val bgReadingsList: List? = null - val databaseHelper = Mockito.mock(DatabaseHelper::class.java) - `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) - `when`(MainApp.getDbHelper().getAllBgreadingsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(bgReadingsList) - Assert.assertEquals("NONE", bgReading.calculateDirection()) +// val databaseHelper = Mockito.mock(DatabaseHelper::class.java) +// `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) + `when`(databaseHelper.getAllBgreadingsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(bgReadingsList) + Assert.assertEquals("NONE", bgReading.calculateDirection(databaseHelper)) setReadings(72, 0) - Assert.assertEquals("DoubleUp", bgReading.calculateDirection()) + Assert.assertEquals("DoubleUp", bgReading.calculateDirection(databaseHelper)) setReadings(76, 60) - Assert.assertEquals("SingleUp", bgReading.calculateDirection()) + Assert.assertEquals("SingleUp", bgReading.calculateDirection(databaseHelper)) setReadings(74, 65) - Assert.assertEquals("FortyFiveUp", bgReading.calculateDirection()) + Assert.assertEquals("FortyFiveUp", bgReading.calculateDirection(databaseHelper)) setReadings(72, 72) - Assert.assertEquals("Flat", bgReading.calculateDirection()) + Assert.assertEquals("Flat", bgReading.calculateDirection(databaseHelper)) setReadings(0, 72) - Assert.assertEquals("DoubleDown", bgReading.calculateDirection()) + Assert.assertEquals("DoubleDown", bgReading.calculateDirection(databaseHelper)) setReadings(60, 76) - Assert.assertEquals("SingleDown", bgReading.calculateDirection()) + Assert.assertEquals("SingleDown", bgReading.calculateDirection(databaseHelper)) setReadings(65, 74) - Assert.assertEquals("FortyFiveDown", bgReading.calculateDirection()) + Assert.assertEquals("FortyFiveDown", bgReading.calculateDirection(databaseHelper)) } @Before fun prepareMock() { - val mainApp = PowerMockito.mockStatic(MainApp::class.java) -// AAPSMocker.mockApplicationContext() -// AAPSMocker.mockSP() -// AAPSMocker.mockL() -// AAPSMocker.mockDatabaseHelper() -// `when`(mainApp.androidInjector()).thenReturn(injector.androidInjector()) } fun setReadings(current_value: Int, previous_value: Int) { @@ -159,6 +157,6 @@ class BgReadingTest : TestBase() { val bgReadings: MutableList = mutableListOf() bgReadings.add(now) bgReadings.add(previous) - `when`(MainApp.getDbHelper().getAllBgreadingsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(bgReadings) + `when`(databaseHelper.getAllBgreadingsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(bgReadings) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index fda1b15ae5..43451779f6 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.interfaces import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile @@ -57,7 +58,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { @Mock lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin @Mock lateinit var profiler: Profiler - private var buildHelper = BuildHelper() + private var buildHelper = BuildHelper(Config()) lateinit var danaRPump: DanaRPump lateinit var constraintChecker: ConstraintChecker @@ -110,14 +111,14 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { danaRPump = DanaRPump(aapsLogger, sp, injector) hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context) - objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp) + objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config()) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context) - danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump) - danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) - insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context) + danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump, dateUtil) + danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) + insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context, Config(), dateUtil) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) - safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin) + safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin, Config()) val constraintsPluginsList = ArrayList() constraintsPluginsList.add(safetyPlugin) constraintsPluginsList.add(objectivesPlugin) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index b4dc882882..a0cd07823e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.constraints.objectives import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -38,7 +38,7 @@ class ObjectivesPluginTest : TestBase() { } @Before fun prepareMock() { - objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp) + objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config()) objectivesPlugin.onStart() `when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %1\$d not started") } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt index 3e36b8bca0..20474af664 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.safety import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile @@ -73,7 +74,7 @@ class SafetyPluginTest : TestBaseWithProfile() { `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription) hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context) - safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin) + safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin, Config()) } @Test fun pumpDescriptionShouldLimitLoopInvocation() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt index f172acb741..b628f6035a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt @@ -95,7 +95,7 @@ class TriggerBgTest : TriggerTestBase() { private fun generateOneCurrentRecordBgData(): List { val list: MutableList = ArrayList() - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":" + (now - 1) + ",\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":214,\"mills\":" + (now - 1) + ",\"direction\":\"Flat\"}")))) return list } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt index ebf0a57fc1..97c26dbcd0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt @@ -103,14 +103,14 @@ class TriggerDeltaTest : TriggerTestBase() { private fun generateValidBgData(): List { val list: MutableList = ArrayList() - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) // +2 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))) // +3 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))) // +4 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) // +2 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))) // +3 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))) // +4 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) return list } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index 3cbaa271f2..2b35932914 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -4,6 +4,7 @@ import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile +import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin @@ -51,6 +52,15 @@ open class TriggerTestBase : TestBaseWithProfile() { if (it is TriggerBg) { it.profileFunction = profileFunction } + if (it is TriggerTime) { + it.dateUtil = dateUtil + } + if (it is TriggerTimeRange) { + it.dateUtil = dateUtil + } + if (it is TriggerRecurringTime) { + it.dateUtil = dateUtil + } if (it is TriggerBTDevice) { it.context = context it.automationPlugin = automationPlugin @@ -68,6 +78,9 @@ open class TriggerTestBase : TestBaseWithProfile() { if (it is StaticLabel) { it.resourceHelper = resourceHelper } + if (it is BgReading) { + it.dateUtil = dateUtil + } } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt index e66c001aee..26706da190 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt @@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.general.maintenance import android.content.Context import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -32,7 +32,7 @@ class MaintenancePluginTest : TestBase() { @Before fun mock() { - sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper) + sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper, Config()) } @Test fun logfilesTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index bf96b45765..1e4d27804d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator +import android.content.Context import android.telephony.SmsManager import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile @@ -25,7 +27,10 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentService import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.CommandQueue -import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.XdripCalibrations import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -46,6 +51,7 @@ import java.util.* @PrepareForTest(ConstraintChecker::class, FabricPrivacy::class, VirtualPumpPlugin::class, XdripCalibrations::class, SmsManager::class, CommandQueue::class, LocalProfilePlugin::class, DateUtil::class, IobCobCalculatorPlugin::class, OneTimePassword::class) class SmsCommunicatorPluginTest : TestBaseWithProfile() { + @Mock lateinit var context: Context @Mock lateinit var sp: SP @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var activePlugin: ActivePluginProvider @@ -103,7 +109,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(SmsManager.getDefault()).thenReturn(smsManager) `when`(sp.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678") - smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp) + smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp, Config(), DateUtil(context, resourceHelper)) smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true) Mockito.doAnswer { invocation: InvocationOnMock -> val callback = invocation.getArgument(1) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.kt index d0a5f7ebeb..b7b421035b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.kt @@ -30,6 +30,7 @@ import java.util.* @PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class) class GlucoseStatusTest : TestBase() { + @Mock lateinit var dateUtil: DateUtil @Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin val injector = HasAndroidInjector { @@ -38,6 +39,9 @@ class GlucoseStatusTest : TestBase() { it.aapsLogger = aapsLogger it.iobCobCalculatorPlugin = iobCobCalculatorPlugin } + if (it is BgReading) { + it.dateUtil = dateUtil + } } } @@ -129,14 +133,14 @@ class GlucoseStatusTest : TestBase() { private fun generateValidBgData(): List { val list: MutableList = ArrayList() try { - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) // +2 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))) // +3 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))) // +4 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) // +2 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":219,\"mills\":1514766300000,\"direction\":\"Flat\"}")))) // +3 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":223,\"mills\":1514766000000,\"direction\":\"Flat\"}")))) // +4 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":222,\"mills\":1514765700000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":224,\"mills\":1514765400000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) } catch (e: JSONException) { throw RuntimeException(e) } @@ -146,9 +150,9 @@ class GlucoseStatusTest : TestBase() { private fun generateMostRecentBgData(): List { val list: MutableList = ArrayList() try { - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))) // +2 - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))) // +2 + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}")))) } catch (e: JSONException) { throw RuntimeException(e) } @@ -162,7 +166,7 @@ class GlucoseStatusTest : TestBase() { private fun generateOldBgData(): List { val list: MutableList = ArrayList() try { - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}")))) } catch (e: JSONException) { throw RuntimeException(e) } @@ -172,7 +176,7 @@ class GlucoseStatusTest : TestBase() { private fun generateOneCurrentRecordBgData(): List { val list: MutableList = ArrayList() try { - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}")))) } catch (e: JSONException) { throw RuntimeException(e) } @@ -185,15 +189,15 @@ class GlucoseStatusTest : TestBase() { val endTime = 1514766900000L val latestReading = 100.0 // Now - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":$latestReading,\"mills\":$endTime,\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":$latestReading,\"mills\":$endTime,\"direction\":\"Flat\"}")))) // One minute ago - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 1) + ",\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 1) + ",\"direction\":\"Flat\"}")))) // Two minutes ago - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 2) + ",\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":" + latestReading + ",\"mills\":" + (endTime - 1000 * 60 * 2) + ",\"direction\":\"Flat\"}")))) // Three minutes and beyond at constant rate for (i in 3..49) { - list.add(BgReading(NSSgv(JSONObject("{\"mgdl\":" + (latestReading + i * 2) + ",\"mills\":" + (endTime - 1000 * 60 * i) + ",\"direction\":\"Flat\"}")))) + list.add(BgReading(injector, NSSgv(JSONObject("{\"mgdl\":" + (latestReading + i * 2) + ",\"mills\":" + (endTime - 1000 * 60 * i) + ",\"direction\":\"Flat\"}")))) } } catch (e: JSONException) { throw RuntimeException(e) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/IobCobCalculatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/IobCobCalculatorPluginTest.kt index 595c8215d7..a34d8b5022 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/IobCobCalculatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/IobCobCalculatorPluginTest.kt @@ -42,6 +42,7 @@ class IobCobCalculatorPluginTest : TestBase() { @Mock lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var fabricPrivacy: FabricPrivacy + @Mock lateinit var dateUtil: DateUtil lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @@ -52,13 +53,14 @@ class IobCobCalculatorPluginTest : TestBase() { it.defaultValueHelper = defaultValueHelper it.resourceHelper = resourceHelper it.profileFunction = profileFunction + it.dateUtil = dateUtil } } } @Before fun mock() { - iobCobCalculatorPlugin = IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy) + iobCobCalculatorPlugin = IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt index d3f14725af..0880445d72 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt @@ -44,7 +44,7 @@ class DanaRPluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaRPump = DanaRPump(aapsLogger, sp, injector) - danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump) + danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump, dateUtil) } @Test @Throws(Exception::class) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt index 8392d74120..e2d094de22 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.Mock @@ -16,6 +17,7 @@ open class DanaRTestBase : TestBase() { @Mock lateinit var sp: SP @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePluginProvider: ActivePluginProvider + @Mock lateinit var dateUtil: DateUtil val injector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt index d8a2d12b20..efd97bea09 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt @@ -36,7 +36,7 @@ class MessageHashTableRTest : DanaRTestBase() { @Test fun runTest() { Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val messageHashTable = MessageHashTableR(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, activePlugin, injector) + val messageHashTable = MessageHashTableR(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, activePlugin, injector, dateUtil) val testMessage = messageHashTable.findMessage(0x41f2) Assert.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarmTest.kt index afb5e6ec6c..e70a9bfe9a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarmTest.kt @@ -11,7 +11,7 @@ class MsgHistoryAlarmTest : DanaRTestBase() { val rxBus = RxBusWrapper() @Test fun runTest() { - val packet = MsgHistoryAlarm(aapsLogger, rxBus) + val packet = MsgHistoryAlarm(aapsLogger, rxBus, dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllTest.kt index 47401ff67b..694a523a67 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllTest.kt @@ -18,7 +18,7 @@ class MsgHistoryAllTest : DanaRTestBase() { @Test fun runTest() { PowerMockito.mockStatic(MainApp::class.java) `when`(MainApp.getDbHelper()).thenReturn(PowerMockito.mock(DatabaseHelper::class.java)) - val packet = MsgHistoryAll(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryAll(aapsLogger, RxBusWrapper(), dateUtil) // test message decoding val array = ByteArray(100) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHourTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHourTest.kt index dd7d81502a..4240454bb9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHourTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHourTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryBasalHourTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryBasalHour(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryBasalHour(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolusTest.kt index 5edd07ed2e..f93be7d72e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolusTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryBolusTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryBolus(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryBolus(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarboTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarboTest.kt index 225ea67259..e30cf23e14 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarboTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarboTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryCarboTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryCarbo(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryCarbo(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulinTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulinTest.kt index b6ef8be268..9c52a30bde 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulinTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulinTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryDailyInsulinTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryDailyInsulin(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryDailyInsulin(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryErrorTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryErrorTest.kt index 756139c88b..e32d657577 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryErrorTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryErrorTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryErrorTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryError(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryError(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucoseTest.kt index e460432652..1e01007392 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucoseTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucoseTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryGlucoseTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryGlucose(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryGlucose(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewTest.kt index 52d000d56d..9cf8f16263 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryNewTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryNew(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryNew(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefillTest.kt index 1a2014cb2b..1cfbee9c64 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefillTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefillTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistoryRefillTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistoryRefill(aapsLogger, RxBusWrapper()) + val packet = MsgHistoryRefill(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspendTest.kt index 5863a7596c..d9b6576cda 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspendTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspendTest.kt @@ -9,7 +9,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgHistorySuspendTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgHistorySuspend(aapsLogger, RxBusWrapper()) + val packet = MsgHistorySuspend(aapsLogger, RxBusWrapper(), dateUtil) // nothing left to test } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTimeTest.kt index c314b5d882..678842b9ae 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTimeTest.kt @@ -24,7 +24,7 @@ class MsgInitConnStatusTimeTest : DanaRTestBase() { @Mock lateinit var commandQueue: CommandQueueProvider @Test fun runTest() { - val packet = MsgInitConnStatusTime(aapsLogger, RxBusWrapper(), resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue) + val packet = MsgInitConnStatusTime(aapsLogger, RxBusWrapper(), resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, dateUtil) // test message decoding packet.handleMessage(createArray(20, 1.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTimeTest.kt index 067d368591..1b5ed6e857 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTimeTest.kt @@ -10,7 +10,7 @@ import java.util.* class MsgSetTimeTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgSetTime(aapsLogger, Date(System.currentTimeMillis())) + val packet = MsgSetTime(aapsLogger, dateUtil, Date(System.currentTimeMillis())) // test message decoding packet.handleMessage(createArray(34, 7.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt index 7a40b86a07..28b69b98ef 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt @@ -11,7 +11,7 @@ import java.util.* class MsgSettingPumpTimeTest : DanaRTestBase() { @Test fun runTest() { - val packet = MsgSettingPumpTime(aapsLogger, danaRPump) + val packet = MsgSettingPumpTime(aapsLogger, danaRPump, dateUtil) danaRPump.units = DanaRPump.UNITS_MGDL // test message decoding val bytes = createArray(34, 7.toByte()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt index 67403dfcd3..74bf318496 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt @@ -18,7 +18,7 @@ class MsgStatusBolusExtendedTest : DanaRTestBase() { @Test fun runTest() { `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) - val packet = MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin) + val packet = MsgStatusBolusExtended(injector, aapsLogger, danaRPump, activePlugin, dateUtil) // test message decoding val array = ByteArray(100) putByteToArray(array, 0, 1) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt index b4f61fd220..e35a45ed1f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt @@ -45,7 +45,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaRPump = DanaRPump(aapsLogger, sp, injector) - danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, rxBus, danaRPump, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue) + danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, rxBus, danaRPump, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, dateUtil) } @Test @Throws(Exception::class) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt index f72d6cde94..94df6cc4fe 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt @@ -31,7 +31,7 @@ class MessageHashTableRKoreanTest : DanaRSTestBase() { @Test fun runTest() { Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val messageHashTable = MessageHashTableRKorean(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, activePlugin, injector) + val messageHashTable = MessageHashTableRKorean(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue, activePlugin, dateUtil, injector) val testMessage = messageHashTable.findMessage(0x41f2) Assert.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt index 3f5da64f27..81b3524543 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt @@ -63,6 +63,6 @@ class DanaRSPluginTest : DanaRSTestBase() { Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 8fe1009923..1907eef740 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import android.content.Context import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint @@ -7,6 +8,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.utils.DateUtil import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -19,6 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class DanaRSMessageHashTableTest : DanaRSTestBase() { + @Mock lateinit var context: Context @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker @@ -28,8 +31,8 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage, injector) - val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) + val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage, injector, DateUtil(context, resourceHelper)) + val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, 0, 0, 0) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) Assert.assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index f983386933..e97edfb860 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import android.content.Context import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage @@ -17,6 +18,7 @@ import java.util.* @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class) class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { + @Mock lateinit var context: Context @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @@ -24,7 +26,7 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { @Test fun runTest() { val now = DateUtil.now() - val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, injector, now) + val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, injector, DateUtil(context, resourceHelper), now) // test getRequestedParams val returnedValues = testPacket.requestParams val expectedValues = getCalender(now) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt index 33e343ee08..402352f235 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt @@ -14,19 +14,19 @@ class DanaRS_Packet_APS_Set_Event_HistoryTest : DanaRSTestBase() { @Test fun runTest() { // test for negative carbs val now = DateUtil.now() - var historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, -1, 0) + var historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, now, -1, 0) var testparams = historyTest.requestParams Assert.assertEquals(0.toByte(), testparams[8]) // 5g carbs - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 5, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, now, 5, 0) testparams = historyTest.requestParams Assert.assertEquals(5.toByte(), testparams[8]) // 150g carbs - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 150, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, now, 150, 0) testparams = historyTest.requestParams Assert.assertEquals(150.toByte(), testparams[8]) // test message generation - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 5, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, now, 5, 0) testparams = historyTest.requestParams Assert.assertEquals(5.toByte(), testparams[8]) Assert.assertEquals(11, testparams.size) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt index f8e3472c8e..ca70660272 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump, dateUtil) // test message decoding val array = ByteArray(100) putByteToArray(array, 0, 1.toByte()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt index 86239a8ea1..ecfbd0ef40 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump, dateUtil) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index bcc56e2f92..b05a2643f9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -44,7 +44,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { @Before fun mock() { - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt index 327aa1c8a6..4297e7683d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt @@ -11,13 +11,13 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump, dateUtil) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(13, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump, dateUtil) packet.handleMessage(createArray(15, 0.toByte())) Assert.assertEquals(false, packet.failed) packet.handleMessage(createArray(15, 161.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt index 3de89db27b..cd3f76de5c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt @@ -9,14 +9,14 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_General_Get_Shipping_InformationTest : DanaRSTestBase() { @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) // everything ok :) - packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil) packet.handleMessage(createArray(18, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_SHIPPING_INFORMATION", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt index 743d3f66e7..5a5c6c4e81 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt index 1f7dd00783..0a0f87fe56 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt index 8451e90b0f..86e962d1df 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt index 0442ea98b9..6cb0c847fc 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt index badaa0aa10..da4c629042 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt index 22a99fcc53..2fc07b5eda 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt index 91d4bea862..c1e4a772c6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt index 19c8d2ef4e..a53a5c0812 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt index 8b75ec344f..29641db16e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt index 66b06f4ed7..5bd6ce327d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt index a4e436a373..1c193ea587 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index 0f90812ed0..d91872f922 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -61,7 +61,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt index 8f74812e9e..9ed05dd6f1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt @@ -11,7 +11,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump, dateUtil) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt index 5fd034e5b6..e6c32cc43a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt @@ -13,7 +13,7 @@ import java.util.* class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now()) + val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, dateUtil, DateUtil.now()) // test params val params = packet.requestParams Assert.assertEquals((Date().date and 0xff).toByte(), params[2]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt index 23285e59e3..1c7a6083b5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt @@ -45,7 +45,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaRPump = DanaRPump(aapsLogger, sp, injector) - danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, rxBus, context, danaRPump, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, detailedBolusInfoStorage) + danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, rxBus, context, danaRPump, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, detailedBolusInfoStorage, dateUtil) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt index b84258c00b..b497e88b95 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRv2.comm +import android.content.Context import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint @@ -13,6 +14,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test @@ -26,6 +28,7 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, ConfigBuilderPlugin::class) class MessageHashTable_rv2Test : DanaRTestBase() { + @Mock lateinit var context: Context @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker @@ -41,7 +44,7 @@ class MessageHashTable_rv2Test : DanaRTestBase() { @Test fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val messageHashTableRv2 = MessageHashTableRv2(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue, activePlugin, detailedBolusInfoStorage, treatmentsPlugin, injector) + val messageHashTableRv2 = MessageHashTableRv2(aapsLogger, rxBus, resourceHelper, constraintChecker, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue, activePlugin, detailedBolusInfoStorage, treatmentsPlugin, injector, DateUtil(context, resourceHelper)) val forTesting: MessageBase = MsgStatusAPS_v2(aapsLogger, danaRPump) val testPacket: MessageBase = messageHashTableRv2.findMessage(forTesting.command) Assert.assertEquals(0xE001, testPacket.command.toLong()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2Test.kt index 0c3d40916a..bcfacf1e81 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2Test.kt @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRv2.comm +import android.content.Context import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test @@ -17,13 +19,14 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(DetailedBolusInfoStorage::class) class MsgHistoryEvents_v2Test : DanaRTestBase() { + @Mock lateinit var context: Context @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var danaRv2Plugin: DanaRv2Plugin @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Test @Throws(Exception::class) fun runTest() { - var packet = MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, RxBusWrapper(), treatmentsPlugin, injector, 0) + var packet = MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, RxBusWrapper(), treatmentsPlugin, injector, DateUtil(context, resourceHelper), 0) // test message decoding val array = ByteArray(100) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2Test.kt index fa98c68830..fefc050457 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2Test.kt @@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgStatusTempBasal_v2Test : DanaRTestBase() { @Test fun runTest() { - val packet = MsgStatusTempBasal_v2(aapsLogger, danaRPump) + val packet = MsgStatusTempBasal_v2(aapsLogger, danaRPump, dateUtil) // test message decoding packet.handleMessage(createArray(34, 1.toByte())) Assert.assertEquals(true, danaRPump.isTempBasalInProgress) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt index db6d30ef59..cdafb560a6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.virtual import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -9,6 +10,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -32,12 +34,13 @@ class VirtualPumpPluginUTest : TestBase() { @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var commandQueue: CommandQueueProvider + @Mock lateinit var dateUtil: DateUtil lateinit var virtualPumpPlugin: VirtualPumpPlugin @Before fun prepareMocks() { - virtualPumpPlugin = VirtualPumpPlugin(HasAndroidInjector { AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, resourceHelper, sp, profileFunction, treatmentsPlugin, commandQueue) + virtualPumpPlugin = VirtualPumpPlugin(HasAndroidInjector { AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, resourceHelper, sp, profileFunction, treatmentsPlugin, commandQueue, Config(), dateUtil) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt index 000a718c01..f410b29a94 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPluginTest.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.sensitivity import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult @@ -24,7 +25,7 @@ class AbstractSensitivityPluginTest : TestBase() { private inner class SensitivityTestClass(pluginDescription: PluginDescription, aapsLogger: AAPSLogger, resourceHelper: ResourceHelper, sp: SP) : AbstractSensitivityPlugin(pluginDescription, HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, resourceHelper, sp) { - override fun detectSensitivity(plugin: IobCobCalculatorPlugin, fromTime: Long, toTime: Long): AutosensResult { + override fun detectSensitivity(plugin: IobCobCalculatorInterface, fromTime: Long, toTime: Long): AutosensResult { return AutosensResult() } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPluginTest.kt index 8aa4ccad2d..f36a10ec7e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPluginTest.kt @@ -58,7 +58,7 @@ class TreatmentsPluginTest : TestBaseWithProfile() { `when`(profileFunction.getProfile(ArgumentMatchers.anyLong())).thenReturn(validProfile) `when`(activePluginProvider.activeInsulin).thenReturn(insulinOrefRapidActingPlugin) - sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePluginProvider, fabricPrivacy) + sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePluginProvider, fabricPrivacy, dateUtil) sot.service = treatmentService } diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt index f4ebe83fdd..b375602bfb 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt @@ -4,6 +4,7 @@ import android.content.Context import dagger.Lazy import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Config import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.interfaces.ActivePluginProvider @@ -38,7 +39,7 @@ class CommandQueueTest : TestBaseWithProfile() { @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var sp: SP - private val buildHelper = BuildHelper() + private val buildHelper = BuildHelper(Config()) val injector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt b/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt index 0edbe93c11..3a70e1a34c 100644 --- a/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.utils +import android.content.Context import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.R import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -14,6 +15,7 @@ import java.util.* @RunWith(PowerMockRunner::class) class DateUtilTest : TestBase() { + @Mock lateinit var context: Context @Mock lateinit var resourceHelper: ResourceHelper @Test @@ -46,22 +48,22 @@ class DateUtilTest : TestBase() { } @Test fun timeStringTest() { - Assert.assertTrue(DateUtil.timeString(Date(1513902750000L)).contains("32")) - Assert.assertTrue(DateUtil.timeString(1513902750000L).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).timeString(Date(1513902750000L)).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).timeString(1513902750000L).contains("32")) } @Test fun dateAndTimeStringTest() { - Assert.assertTrue(DateUtil.dateAndTimeString(1513902750000L).contains("22")) - Assert.assertTrue(DateUtil.dateAndTimeString(1513902750000L).contains("32")) - Assert.assertTrue(DateUtil.dateAndTimeString(Date(1513902750000L)).contains("22")) - Assert.assertTrue(DateUtil.dateAndTimeString(Date(1513902750000L)).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeString(1513902750000L).contains("22")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeString(1513902750000L).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeString(Date(1513902750000L)).contains("22")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeString(Date(1513902750000L)).contains("32")) } @Test fun dateAndTimeRangeStringTest() { - Assert.assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22")) - Assert.assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32")) - Assert.assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22")) - Assert.assertTrue(DateUtil.dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("22")) + Assert.assertTrue(DateUtil(context, resourceHelper).dateAndTimeRangeString(1513902750000L, 1513902750000L).contains("32")) } /* diff --git a/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.java b/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.java deleted file mode 100644 index 166ce04b10..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.junit.Assert; -import org.junit.Test; - -public class SntpClientTest { - - @Test - public void ntpTimeTest() { - // no internet - SntpClient.ntpTime(new SntpClient.Callback() { - @Override - public void run() { - Assert.assertFalse(networkConnected); - Assert.assertFalse(success); - Assert.assertEquals(0L, time); - } - }, false); - // internet - SntpClient.doNtpTime(new SntpClient.Callback() { - @Override - public void run() { - Assert.assertTrue(success); - Assert.assertTrue(Math.abs(time - DateUtil.now()) < 60000); - } - }); - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.kt b/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.kt new file mode 100644 index 0000000000..79a8541daf --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/utils/SntpClientTest.kt @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.utils + +import info.nightscout.androidaps.TestBase +import org.junit.Assert +import org.junit.Test +import org.mockito.Mock + +class SntpClientTest : TestBase() { + @Mock lateinit var dateUtil: DateUtil + + @Test + fun ntpTimeTest() { + // no internet + SntpClient(aapsLogger, dateUtil).ntpTime(object : SntpClient.Callback() { + override fun run() { + Assert.assertFalse(networkConnected) + Assert.assertFalse(success) + Assert.assertEquals(0L, time) + } + }, false) + // internet + SntpClient(aapsLogger, dateUtil).doNtpTime(object : SntpClient.Callback() { + override fun run() { + Assert.assertTrue(success) + Assert.assertTrue(Math.abs(time - DateUtil.now()) < 60000) + } + }) + } +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/db/BgReading.java b/core/src/main/java/info/nightscout/androidaps/db/BgReading.java index f2b53b8738..89ef6b473a 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/core/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -33,6 +33,7 @@ public class BgReading implements DataPointWithLabelInterface { @Inject public DefaultValueHelper defaultValueHelper; @Inject public ProfileFunction profileFunction; @Inject public ResourceHelper resourceHelper; + @Inject public DateUtil dateUtil; @DatabaseField(id = true) public long date; @@ -66,7 +67,8 @@ public class BgReading implements DataPointWithLabelInterface { injector.androidInjector().inject(this); } - public BgReading(NSSgv sgv) { + public BgReading(HasAndroidInjector injector, NSSgv sgv) { + injector.androidInjector().inject(this); date = sgv.getMills(); value = sgv.getMgdl(); raw = sgv.getFiltered() != null ? sgv.getFiltered() : value; @@ -125,7 +127,7 @@ public class BgReading implements DataPointWithLabelInterface { public String toString() { return "BgReading{" + "date=" + date + - ", date=" + DateUtil.dateAndTimeString(date) + + ", date=" + dateUtil.dateAndTimeString(date) + ", value=" + value + ", direction=" + direction + ", raw=" + raw + diff --git a/core/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/core/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index 6f95917ace..1300d0bbf9 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/core/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -38,6 +38,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { @Inject ResourceHelper resourceHelper; @Inject AAPSLogger aapsLogger; @Inject Translator translator; + @Inject DateUtil dateUtil; @DatabaseField(id = true) public long date; @@ -122,7 +123,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { public String toString() { return "CareportalEvent{" + "date= " + date + - ", date= " + DateUtil.dateAndTimeString(date) + + ", date= " + dateUtil.dateAndTimeString(date) + ", isValid= " + isValid + ", _id= " + _id + ", eventType= " + eventType + @@ -134,7 +135,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { for (int i = 0; i < list.size(); i++) { CareportalEvent event = list.get(i); if (event.date <= time && event.date > (time - T.mins(5).msecs())) { - aapsLogger.debug(LTag.DATABASE, "Found event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found event for time: " + dateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } diff --git a/core/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/core/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index 49b223d9b9..e1f96431cb 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/core/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -212,7 +212,7 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface { public String log() { return "ExtendedBolus{" + "date= " + date + - ", date= " + DateUtil.dateAndTimeString(date) + + ", date= " + dateUtil.dateAndTimeString(date) + ", isValid=" + isValid + ", _id= " + _id + ", pumpId= " + pumpId + diff --git a/core/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/core/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 09b7d047ba..006a839510 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/core/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -73,6 +73,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { @Inject public AAPSLogger aapsLogger; @Inject public RxBusWrapper rxBus; @Inject public ResourceHelper resourceHelper; + @Inject public DateUtil dateUtil; public ProfileSwitch() { this.injector = StaticInjector.Companion.getInstance(); @@ -233,11 +234,11 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { @Override public boolean isValid() { - boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date)); + boolean isValid = getProfileObject() != null && getProfileObject().isValid(dateUtil.dateAndTimeString(date)); ProfileSwitch active = treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now()); long activeProfileSwitchDate = active != null ? active.date : -1L; if (!isValid && date == activeProfileSwitchDate) - createNotificationInvalidProfile(DateUtil.dateAndTimeString(date)); + createNotificationInvalidProfile(dateUtil.dateAndTimeString(date)); return isValid; } @@ -246,17 +247,17 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { rxBus.send(new EventNewNotification(notification)); } - public static boolean isEvent5minBack(AAPSLogger aapsLogger, List list, long time, boolean zeroDurationOnly) { + public boolean isEvent5minBack(List list, long time, boolean zeroDurationOnly) { for (int i = 0; i < list.size(); i++) { ProfileSwitch event = list.get(i); if (event.date <= time && event.date > (time - T.mins(5).msecs())) { if (zeroDurationOnly) { if (event.durationInMinutes == 0) { - aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + dateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } else { - aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + dateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } @@ -314,7 +315,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { public String toString() { return "ProfileSwitch{" + "date=" + date + - "date=" + DateUtil.dateAndTimeString(date) + + "date=" + dateUtil.dateAndTimeString(date) + ", isValid=" + isValid + ", duration=" + durationInMinutes + ", profileName=" + profileName + diff --git a/core/src/main/java/info/nightscout/androidaps/db/TDD.java b/core/src/main/java/info/nightscout/androidaps/db/TDD.java index eba359f2ad..05b9025491 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/TDD.java +++ b/core/src/main/java/info/nightscout/androidaps/db/TDD.java @@ -46,11 +46,10 @@ public class TDD { } - @Override - public String toString() { + public String toString(DateUtil dateUtil) { return "TDD [" + "date=" + date + - "date(str)=" + DateUtil.dateAndTimeString(date) + + "date(str)=" + dateUtil.dateAndTimeString(date) + ", bolus=" + bolus + ", basal=" + basal + ", total=" + total + diff --git a/core/src/main/java/info/nightscout/androidaps/db/TempTarget.java b/core/src/main/java/info/nightscout/androidaps/db/TempTarget.java index cc9b7db990..92668d255a 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/TempTarget.java +++ b/core/src/main/java/info/nightscout/androidaps/db/TempTarget.java @@ -182,10 +182,10 @@ public class TempTarget implements Interval { else return DecimalFormatter.to1Decimal(low * Constants.MGDL_TO_MMOLL); } - public String toString() { + public String toString(DateUtil dateUtil) { return "TemporaryTarget{" + "date=" + date + - "date=" + DateUtil.dateAndTimeString(date) + + "date=" + dateUtil.dateAndTimeString(date) + ", isValid=" + isValid + ", duration=" + durationInMinutes + ", reason=" + reason + diff --git a/core/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/core/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index cf59c456d3..d4f89fdd7e 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/core/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -404,7 +404,7 @@ public class TemporaryBasal implements Interval, DbObjectBase { public String toString() { return "TemporaryBasal{" + "date=" + date + - ", date=" + DateUtil.dateAndTimeString(date) + + ", date=" + dateUtil.dateAndTimeString(date) + ", isValid=" + isValid + ", pumpId=" + pumpId + ", _id=" + _id + diff --git a/core/src/main/java/info/nightscout/androidaps/db/Treatment.java b/core/src/main/java/info/nightscout/androidaps/db/Treatment.java index 0df0dd0efa..bd3a4c0ebe 100644 --- a/core/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/core/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -37,6 +37,7 @@ public class Treatment implements DataPointWithLabelInterface, DbObjectBase { @Inject public ResourceHelper resourceHelper; @Inject public ProfileFunction profileFunction; @Inject public ActivePluginProvider activePlugin; + @Inject public DateUtil dateUtil; public static final String TABLE_TREATMENTS = "Treatments"; @@ -108,7 +109,7 @@ public class Treatment implements DataPointWithLabelInterface, DbObjectBase { @NonNull public String toString() { return "Treatment{" + "date= " + date + - ", date= " + DateUtil.dateAndTimeString(date) + + ", date= " + dateUtil.dateAndTimeString(date) + ", isValid= " + isValid + ", isSMB= " + isSMB + ", _id= " + _id + diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/data/AutosensData.java b/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/data/AutosensData.java index 9cd8c74f87..51a1b58c18 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/data/AutosensData.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/data/AutosensData.java @@ -11,7 +11,6 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.core.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; -import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; @@ -29,8 +28,8 @@ public class AutosensData implements DataPointWithLabelInterface { @Inject AAPSLogger aapsLogger; @Inject SP sp; @Inject ResourceHelper resourceHelper; - @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject DateUtil dateUtil; public AutosensData(HasAndroidInjector injector) { injector.androidInjector().inject(this); @@ -56,7 +55,7 @@ public class AutosensData implements DataPointWithLabelInterface { double sens = profile.getIsfMgdl(t.date); double ic = profile.getIc(t.date); min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; - aapsLogger.debug(LTag.AUTOSENS, "Min 5m carbs impact for " + carbs + "g @" + DateUtil.dateAndTimeString(t.date) + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic); + aapsLogger.debug(LTag.AUTOSENS, "Min 5m carbs impact for " + carbs + "g @" + dateUtil.dateAndTimeString(t.date) + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic); } else { min5minCarbImpact = sp.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact); } @@ -71,7 +70,7 @@ public class AutosensData implements DataPointWithLabelInterface { @Override public String toString() { - return String.format(Locale.ENGLISH, "CarbsInPast: time: %s carbs: %.02f min5minCI: %.02f remaining: %.2f", DateUtil.dateAndTimeString(time), carbs, min5minCarbImpact, remaining); + return String.format(Locale.ENGLISH, "CarbsInPast: time: %s carbs: %.02f min5minCI: %.02f remaining: %.2f", dateUtil.dateAndTimeString(time), carbs, min5minCarbImpact, remaining); } } @@ -107,7 +106,7 @@ public class AutosensData implements DataPointWithLabelInterface { @Override public String toString() { return String.format(Locale.ENGLISH, "AutosensData: %s pastSensitivity=%s delta=%.02f avgDelta=%.02f bgi=%.02f deviation=%.02f avgDeviation=%.02f absorbed=%.02f carbsFromBolus=%.02f cob=%.02f autosensRatio=%.02f slopeFromMaxDeviation=%.02f slopeFromMinDeviation=%.02f activeCarbsList=%s", - DateUtil.dateAndTimeString(time), pastSensitivity, delta, avgDelta, bgi, deviation, avgDeviation, absorbed, carbsFromBolus, cob, autosensResult.ratio, slopeFromMaxDeviation, slopeFromMinDeviation, activeCarbsList.toString()); + dateUtil.dateAndTimeString(time), pastSensitivity, delta, avgDelta, bgi, deviation, avgDeviation, absorbed, carbsFromBolus, cob, autosensResult.ratio, slopeFromMaxDeviation, slopeFromMinDeviation, activeCarbsList.toString()); } public List cloneCarbsList() { @@ -134,7 +133,7 @@ public class AutosensData implements DataPointWithLabelInterface { activeCarbsList.remove(i--); if (c.remaining > 0) cob -= c.remaining; - aapsLogger.debug(LTag.AUTOSENS, "Removing carbs at " + DateUtil.dateAndTimeString(toTime) + " after " + maxAbsorptionHours + "h > " + c.toString()); + aapsLogger.debug(LTag.AUTOSENS, "Removing carbs at " + dateUtil.dateAndTimeString(toTime) + " after " + maxAbsorptionHours + "h > " + c.toString()); } } } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/DateUtil.java b/core/src/main/java/info/nightscout/androidaps/utils/DateUtil.java index 16fb3e2504..58e156d7a0 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/DateUtil.java +++ b/core/src/main/java/info/nightscout/androidaps/utils/DateUtil.java @@ -44,19 +44,10 @@ public class DateUtil { private final Context context; private final ResourceHelper resourceHelper; - @Deprecated - private static DateUtil instance; - @Inject public DateUtil(Context context, ResourceHelper resourceHelper) { this.context = context; this.resourceHelper = resourceHelper; - instance = this; - } - - @Deprecated - public static DateUtil getInstance() { - return instance; } /** @@ -206,22 +197,22 @@ public class DateUtil { return new DateTime(mills).toString(DateTimeFormat.fullTime()); } - public static String dateAndTimeString(Date date) { - return dateString(date) + " " + instance.timeString(date); + public String dateAndTimeString(Date date) { + return dateString(date) + " " + timeString(date); } - public static String dateAndTimeRangeString(long start, long end) { - return dateAndTimeString(start) + " - " + instance.timeString(end); + public String dateAndTimeRangeString(long start, long end) { + return dateAndTimeString(start) + " - " + timeString(end); } - public static String dateAndTimeString(long mills) { + public String dateAndTimeString(long mills) { if (mills == 0) return ""; - return dateString(mills) + " " + instance.timeString(mills); + return dateString(mills) + " " + timeString(mills); } - public static String dateAndTimeAndSecondsString(long mills) { + public String dateAndTimeAndSecondsString(long mills) { if (mills == 0) return ""; - return dateString(mills) + " " + instance.timeStringWithSeconds(mills); + return dateString(mills) + " " + timeStringWithSeconds(mills); } public static String dateAndTimeFullString(long mills) { @@ -245,11 +236,11 @@ public class DateUtil { private static LongSparseArray timeStrings = new LongSparseArray<>(); - public static String timeStringFromSeconds(int seconds) { + public String timeStringFromSeconds(int seconds) { String cached = timeStrings.get(seconds); if (cached != null) return cached; - String t = instance.timeString(toDate(seconds)); + String t = timeString(toDate(seconds)); timeStrings.put(seconds, t); return t; }