From a2630593170f0637eb2170a85467dd02a0cb78e8 Mon Sep 17 00:00:00 2001 From: vanous Date: Mon, 12 Aug 2019 23:18:20 +0200 Subject: [PATCH] Modify charts range based on settings. More/Less labels density. --- .../charts/AbstractWeekChartFragment.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 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 a50dcdbab..0af2e32f9 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 @@ -59,7 +59,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue; public abstract class AbstractWeekChartFragment extends AbstractChartFragment { protected static final Logger LOG = LoggerFactory.getLogger(AbstractWeekChartFragment.class); - protected final int TOTAL_DAYS = 7; + protected final int TOTAL_DAYS = getRangeDays(); private Locale mLocale; private int mTargetValue = 0; @@ -103,6 +103,17 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { // mBalanceView.setText(getBalanceMessage(balance)); } + private String getWeeksChartsLabel(Calendar day){ + if (GBApplication.getPrefs().getBoolean("charts_range", true)) { + //month, show day date + return String.valueOf(day.get(Calendar.DAY_OF_MONTH)); + } + else{ + //week, show short day name + return day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale); + } + } + private WeekChartsData refreshWeekBeforeData(DBHandler db, BarChart barChart, Calendar day, GBDevice device) { day = (Calendar) day.clone(); // do not modify the caller's argument day.add(Calendar.DATE, -TOTAL_DAYS); @@ -115,7 +126,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { balance += calculateBalance(amounts); entries.add(new BarEntry(counter, getTotalsForActivityAmounts(amounts))); - labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale)); + labels.add(getWeeksChartsLabel(day)); day.add(Calendar.DATE, 1); } @@ -337,6 +348,14 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment { return amounts; } + private int getRangeDays(){ + if (GBApplication.getPrefs().getBoolean("charts_range", true)) { + return 30;} + else{ + return 7; + } + } + abstract String getAverage(float value); abstract int getGoal();