From ef5f4d9fd0258a525acdf7a16bc4a89c88ec30d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 4 Jan 2025 13:46:33 +0000 Subject: [PATCH] Restore steps balance on weekly and monthly charts --- .../charts/AbstractWeekChartFragment.java | 38 +--------------- .../charts/StepsPeriodFragment.java | 36 ++++++++++++--- .../charts/WeekSleepChartFragment.java | 2 + .../main/res/layout/fragment_steps_period.xml | 13 +++++- .../res/layout/fragment_weeksteps_chart.xml | 44 ------------------- 5 files changed, 45 insertions(+), 88 deletions(-) delete mode 100644 app/src/main/res/layout/fragment_weeksteps_chart.xml 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 96f3eafc6..35ccc7f58 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 @@ -19,12 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts; import android.app.Activity; import android.graphics.Color; -import android.os.Build; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.components.LimitLine; @@ -68,9 +62,8 @@ public abstract class AbstractWeekChartFragment extends AbstractActivityChartFra protected int mTargetValue = 0; protected BarChart mWeekChart; - protected TextView mBalanceView; - private int mOffsetHours = getOffsetHours(); + private final int mOffsetHours = getOffsetHours(); protected String getWeeksChartsLabel(Calendar day){ if (TOTAL_DAYS > 7) { @@ -210,35 +203,6 @@ public abstract class AbstractWeekChartFragment extends AbstractActivityChartFra return lineDataSet; }; - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mLocale = getResources().getConfiguration().locale; - - View rootView = inflater.inflate(R.layout.fragment_weeksteps_chart, container, false); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - rootView.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> { - getChartsHost().enableSwipeRefresh(scrollY == 0); - }); - } - - final int goal = getGoal(); - if (goal >= 0) { - mTargetValue = goal; - } - - mWeekChart = rootView.findViewById(R.id.weekstepschart); - mBalanceView = rootView.findViewById(R.id.balance); - - setupWeekChart(); - - // refresh immediately instead of use refreshIfVisible(), for perceived performance - refresh(); - - return rootView; - } - protected void setupWeekChart() { mWeekChart.setBackgroundColor(BACKGROUND_COLOR); mWeekChart.getDescription().setTextColor(DESCRIPTION_COLOR); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepsPeriodFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepsPeriodFragment.java index 8e377db4b..8ed862011 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepsPeriodFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepsPeriodFragment.java @@ -1,5 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts; +import android.content.Context; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -46,6 +47,8 @@ public class StepsPeriodFragment extends StepsFragment entries = new ArrayList<>(); int counter = 0; - for(StepsDay day : stepsData.days) { + for (StepsDay day : stepsData.days) { entries.add(new BarEntry(counter, day.steps)); counter++; } @@ -183,6 +189,8 @@ public class StepsPeriodFragment extends StepsFragment chart) {} + protected void setupLegend(Chart chart) { + } protected static class StepsData extends ChartsData { List days; @@ -211,10 +220,11 @@ public class StepsPeriodFragment extends StepsFragment days) { this.days = days; int daysCounter = 0; - for(StepsDay day : days) { + for (StepsDay day : days) { this.totalSteps += day.steps; this.totalDistance += day.distance; if (day.steps > 0) { @@ -227,5 +237,19 @@ public class StepsPeriodFragment extends StepsFragment 0) { + return context.getString(R.string.overstep, Math.abs(totalBalance)); + } else { + return context.getString(R.string.lack_of_step, Math.abs(totalBalance)); + + } + } } } 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 bfef3234e..149b0a533 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 @@ -67,6 +67,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { private LinearLayout sleepScoreWrapper; private LineChart sleepScoreChart; + private TextView mBalanceView; + public static WeekSleepChartFragment newInstance ( int totalDays ) { WeekSleepChartFragment fragmentFirst = new WeekSleepChartFragment(); Bundle args = new Bundle(); diff --git a/app/src/main/res/layout/fragment_steps_period.xml b/app/src/main/res/layout/fragment_steps_period.xml index 9fe156eeb..bca4d3a27 100644 --- a/app/src/main/res/layout/fragment_steps_period.xml +++ b/app/src/main/res/layout/fragment_steps_period.xml @@ -20,10 +20,21 @@ android:gravity="center" android:textSize="20sp" android:layout_marginTop="15dp" - android:layout_marginBottom="20dp" + android:layout_marginBottom="10dp" /> + + + + - - - - - - - - - - - - - - -