From 7809655ef443210c3d5516084a3e583f706541cc Mon Sep 17 00:00:00 2001 From: vanous Date: Sun, 11 Aug 2019 12:00:00 +0200 Subject: [PATCH] Add Average Settings. Addformat method to get average. --- .../activities/charts/AbstractWeekChartFragment.java | 10 +++++++--- .../activities/charts/WeekSleepChartFragment.java | 7 +++++++ .../activities/charts/WeekStepsChartFragment.java | 5 +++++ app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/preferences.xml | 6 ++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java index f376b7625..a50dcdbab 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractWeekChartFragment.java @@ -48,6 +48,7 @@ import java.util.Calendar; import java.util.List; import java.util.Locale; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -135,7 +136,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { average = Math.abs(balance / TOTAL_DAYS); } LimitLine average_line = new LimitLine(average); - average_line.setLabel(getString(R.string.average, average)); + average_line.setLabel(getString(R.string.average, getAverage(average))); if (average > (mTargetValue)) { average_line.setLineColor(Color.GREEN); @@ -146,10 +147,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { average_line.setTextColor(Color.RED); } if (average > 0) { - barChart.getAxisLeft().addLimitLine(average_line); + if (GBApplication.getPrefs().getBoolean("charts_show_average", true)) { + barChart.getAxisLeft().addLimitLine(average_line); + } } - return new WeekChartsData(barData, new PreformattedXIndexLabelFormatter(labels), getBalanceMessage(balance, mTargetValue)); } @@ -335,6 +337,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { return amounts; } + abstract String getAverage(float value); + abstract int getGoal(); abstract int getOffsetHours(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java index 936bcc27a..d13a0b492 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java @@ -167,4 +167,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { private String getHM(long value) { return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES); } + + @Override + String getAverage(float value) { + //return String.format("%.0f", value); + return getHM((long)value); + } + } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java index 35ef4ee40..8dccc1a26 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java @@ -113,4 +113,9 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment { } else return getString(R.string.no_data); } + + @Override + String getAverage(float value) { + return String.format("%.0f", value); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9dfb49af..1dbdca832 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,6 +73,7 @@ Default Charts Settings Enable left/right swipe in the charts activity + Show averages in the charts Date and Time Sync time Sync time to Gadgetbridge device when connecting, and when time or time zone changes on Android device @@ -417,7 +418,7 @@ Steps today, target: %1$s Lack of steps: %1$d Overstep: %1$d - Average: %1$.0f + Average: %1$s Do not ACK activity data transfer If the activity data are not acked to the band, they will not be cleared. Useful if GB is used together with other apps. Will keep activity data on the Mi Band even after synchronization. Useful if GB is used together with other apps. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 1d057873f..a07f53dcc 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -183,6 +183,12 @@ android:defaultValue="true" android:key="charts_allow_swipe" android:title="@string/pref_title_charts_swipe" /> + +