From 468b645486e42e8a6f5ebaa6be51745b13c0c4e2 Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Thu, 28 Jun 2018 22:36:08 +0200 Subject: [PATCH] Do calculations in a central place --- .../androidaps/plugins/Overview/OverviewFragment.java | 8 ++++---- app/src/main/java/info/nightscout/utils/DateUtil.java | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index eb13cf5ef8..d1cbf71c05 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -839,7 +839,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (wizard.superBolus) { final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (loopPlugin.isEnabled(PluginType.LOOP)) { - loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); + loopPlugin.superBolusTo(System.currentTimeMillis() + DateUtil.hourToMs(2)); MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() { @@ -1426,12 +1426,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, predHours = Math.max(0, predHours); hoursToFetch = rangeToDisplay - predHours; toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific - fromTime = toTime - hoursToFetch * 60 * 60 * 1000L; - endTime = toTime + predHours * 60 * 60 * 1000L; + fromTime = toTime - DateUtil.hourToMs(hoursToFetch); + endTime = toTime + DateUtil.hourToMs(predHours); } else { hoursToFetch = rangeToDisplay; toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific - fromTime = toTime - hoursToFetch * 60 * 60 * 1000L; + fromTime = toTime - DateUtil.hourToMs(hoursToFetch); endTime = toTime; } diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index 7d7db3f5a7..ca13381e37 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -180,4 +180,8 @@ public class DateUtil { return date - date % 1000; } + public static long hourToMs(long hour) { + return hour * 60 * 60 * 1000L; + } + }