This commit is contained in:
Milos Kozak 2021-08-11 18:10:48 +02:00
commit 24fc69c26b

View file

@ -93,11 +93,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
overviewData = OverviewData(injector, aapsLogger, resourceHelper, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, config, loopPlugin, nsDeviceStatus, repository, overviewMenus, iobCobCalculator, translator) overviewData = OverviewData(injector, aapsLogger, resourceHelper, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, config, loopPlugin, nsDeviceStatus, repository, overviewMenus, iobCobCalculator, translator)
binding.left.setOnClickListener { binding.left.setOnClickListener {
setTime(overviewData.fromTime - T.hours(rangeToDisplay.toLong()).msecs()) adjustTimeRange(overviewData.fromTime - T.hours(rangeToDisplay.toLong()).msecs())
loadAll("onClickLeft") loadAll("onClickLeft")
} }
binding.right.setOnClickListener { binding.right.setOnClickListener {
setTime(overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs()) adjustTimeRange(overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs())
loadAll("onClickRight") loadAll("onClickRight")
} }
binding.end.setOnClickListener { binding.end.setOnClickListener {
@ -265,6 +265,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun loadAll(from: String) { private fun loadAll(from: String) {
updateDate()
Thread { Thread {
overviewData.prepareBasalData(from) overviewData.prepareBasalData(from)
overviewData.prepareTemporaryTargetData(from) overviewData.prepareTemporaryTargetData(from)
@ -276,18 +277,22 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
} }
private fun setTime(start: Long) { private fun setTime(start: Long) {
Calendar.getInstance().also { calendar -> GregorianCalendar().also { calendar ->
calendar.timeInMillis = start calendar.timeInMillis = start
calendar[Calendar.MILLISECOND] = 0 calendar[Calendar.MILLISECOND] = 0
calendar[Calendar.SECOND] = 0 calendar[Calendar.SECOND] = 0
calendar[Calendar.MINUTE] = 0 calendar[Calendar.MINUTE] = 0
calendar[Calendar.HOUR_OF_DAY] = 0 calendar[Calendar.HOUR_OF_DAY] -= (calendar[Calendar.HOUR_OF_DAY] % rangeToDisplay)
overviewData.fromTime = calendar.timeInMillis adjustTimeRange(calendar.timeInMillis)
overviewData.toTime = overviewData.fromTime + T.hours(rangeToDisplay.toLong()).msecs()
overviewData.endTime = overviewData.toTime
} }
} }
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) { private fun runCalculation(from: String) {
Thread { Thread {
iobCobCalculator.stopCalculation(from) iobCobCalculator.stopCalculation(from)
@ -307,13 +312,17 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
runningRefresh = false runningRefresh = false
} }
fun updateDate() {
binding.date.text = dateUtil.dateAndTimeString(overviewData.fromTime)
binding.zoom.text = rangeToDisplay.toString()
}
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun updateGUI(from: String) { fun updateGUI(from: String) {
aapsLogger.debug(LTag.UI, "updateGui $from") aapsLogger.debug(LTag.UI, "updateGui $from")
binding.date.text = dateUtil.dateAndTimeString(overviewData.fromTime) updateDate()
binding.zoom.text = rangeToDisplay.toString()
val pump = activePlugin.activePump val pump = activePlugin.activePump
val graphData = GraphData(injector, binding.bgGraph, overviewData) val graphData = GraphData(injector, binding.bgGraph, overviewData)