mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01:00
Restore steps balance on weekly and monthly charts
This commit is contained in:
parent
d432800ae4
commit
ef5f4d9fd0
@ -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);
|
||||
|
@ -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<StepsPeriodFragment.Steps
|
||||
private TextView distanceTotal;
|
||||
private BarChart stepsChart;
|
||||
|
||||
private TextView mBalanceView;
|
||||
|
||||
protected int CHART_TEXT_COLOR;
|
||||
protected int TEXT_COLOR;
|
||||
protected int STEPS_GOAL;
|
||||
@ -84,6 +87,9 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
||||
stepsTotal = rootView.findViewById(R.id.steps_total);
|
||||
distanceTotal = rootView.findViewById(R.id.distance_total);
|
||||
STEPS_GOAL = GBApplication.getPrefs().getInt(ActivityUser.PREF_USER_STEPS_GOAL, ActivityUser.defaultUserStepsGoal);
|
||||
|
||||
mBalanceView = rootView.findViewById(R.id.balance);
|
||||
|
||||
setupStepsChart();
|
||||
refresh();
|
||||
|
||||
@ -183,6 +189,8 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
||||
distanceAvg.setText(valueFormatter.formatValue(stepsData.distanceDailyAvg, "km"));
|
||||
stepsTotal.setText(String.format(String.valueOf(stepsData.totalSteps)));
|
||||
distanceTotal.setText(valueFormatter.formatValue(stepsData.totalDistance, "km"));
|
||||
|
||||
mBalanceView.setText(stepsData.getBalanceMessage(getContext(), STEPS_GOAL));
|
||||
}
|
||||
|
||||
ValueFormatter getStepsChartDayValueFormatter(StepsPeriodFragment.StepsData stepsData) {
|
||||
@ -202,7 +210,8 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
||||
stepsChart.invalidate();
|
||||
}
|
||||
|
||||
protected void setupLegend(Chart<?> chart) {}
|
||||
protected void setupLegend(Chart<?> chart) {
|
||||
}
|
||||
|
||||
protected static class StepsData extends ChartsData {
|
||||
List<StepsDay> days;
|
||||
@ -211,6 +220,7 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
||||
long totalSteps = 0;
|
||||
double totalDistance = 0;
|
||||
StepsDay todayStepsDay;
|
||||
|
||||
protected StepsData(List<StepsDay> days) {
|
||||
this.days = days;
|
||||
int daysCounter = 0;
|
||||
@ -227,5 +237,19 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
||||
}
|
||||
this.todayStepsDay = days.get(days.size() - 1);
|
||||
}
|
||||
|
||||
protected String getBalanceMessage(final Context context, final int targetValue) {
|
||||
if (totalSteps == 0) {
|
||||
return context.getString(R.string.no_data);
|
||||
}
|
||||
|
||||
final long totalBalance = totalSteps - ((long) targetValue * days.size());
|
||||
if (totalBalance > 0) {
|
||||
return context.getString(R.string.overstep, Math.abs(totalBalance));
|
||||
} else {
|
||||
return context.getString(R.string.lack_of_step, Math.abs(totalBalance));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -20,10 +20,21 @@
|
||||
android:gravity="center"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center">
|
||||
<TextView
|
||||
android:id="@+id/balance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="250sp"
|
||||
|
@ -1,44 +0,0 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ActivityChartsActivity$PlaceholderFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/balance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/todaystepschart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="20" />
|
||||
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/weekstepschart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="20" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:id="@+id/steps_streaks_button"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:visibility="visible"
|
||||
app:srcCompat="@drawable/ic_events" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user