From 0a66ed307aa6520abe5cd2f8c0a85f608f3a6354 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 10 Aug 2021 21:36:26 +0200 Subject: [PATCH] HistoryBrowser improvement --- .../activities/HistoryBrowseActivity.kt | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt index 6b0be2cc68..843de8b05b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt @@ -93,11 +93,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { overviewData = OverviewData(injector, aapsLogger, resourceHelper, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, config, loopPlugin, nsDeviceStatus, repository, overviewMenus, iobCobCalculator, translator) binding.left.setOnClickListener { - setTime(overviewData.fromTime - T.hours(rangeToDisplay.toLong()).msecs()) + adjustTimeRange(overviewData.fromTime - T.hours(rangeToDisplay.toLong()).msecs()) loadAll("onClickLeft") } binding.right.setOnClickListener { - setTime(overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs()) + adjustTimeRange(overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs()) loadAll("onClickRight") } binding.end.setOnClickListener { @@ -266,6 +266,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { @Suppress("SameParameterValue") private fun loadAll(from: String) { + updateDate() Thread { overviewData.prepareBasalData(from) overviewData.prepareTemporaryTargetData(from) @@ -277,18 +278,22 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } private fun setTime(start: Long) { - Calendar.getInstance().also { calendar -> + GregorianCalendar().also { calendar -> calendar.timeInMillis = start calendar[Calendar.MILLISECOND] = 0 calendar[Calendar.SECOND] = 0 calendar[Calendar.MINUTE] = 0 - calendar[Calendar.HOUR_OF_DAY] = 0 - overviewData.fromTime = calendar.timeInMillis - overviewData.toTime = overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs() - overviewData.endTime = overviewData.toTime + calendar[Calendar.HOUR_OF_DAY] -= (calendar[Calendar.HOUR_OF_DAY] % rangeToDisplay) + adjustTimeRange(calendar.timeInMillis) } } + private fun adjustTimeRange(start: Long) { + overviewData.fromTime = start + overviewData.toTime = overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs() + overviewData.endTime = overviewData.toTime + } + private fun runCalculation(from: String) { Thread { iobCobCalculator.stopCalculation(from) @@ -308,13 +313,17 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { runningRefresh = false } + fun updateDate() { + binding.date.text = dateUtil.dateAndTimeString(overviewData.fromTime) + binding.zoom.text = rangeToDisplay.toString() + } + @Suppress("UNUSED_PARAMETER") @SuppressLint("SetTextI18n") fun updateGUI(from: String) { aapsLogger.debug(LTag.UI, "updateGui $from") - binding.date.text = dateUtil.dateAndTimeString(overviewData.fromTime) - binding.zoom.text = rangeToDisplay.toString() + updateDate() val pump = activePlugin.activePump val graphData = GraphData(injector, binding.bgGraph, overviewData)