2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2015-2020 0nse, Andreas Shimokawa, Carsten Pfeiffer,
|
2019-11-23 21:52:46 +01:00
|
|
|
Daniele Gobbetti, Pavel Elagin, vanous
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
2015-07-29 16:30:19 +02:00
|
|
|
|
2017-03-31 23:42:25 +02:00
|
|
|
import com.github.mikephil.charting.charts.Chart;
|
2019-08-24 12:41:26 +02:00
|
|
|
import com.github.mikephil.charting.formatter.ValueFormatter;
|
2017-02-23 08:49:55 +01:00
|
|
|
|
2017-03-11 11:29:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-07-29 16:30:19 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2017-02-26 00:40:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
|
2017-03-11 11:29:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
2015-07-29 16:30:19 +02:00
|
|
|
|
2017-02-21 16:20:42 +01:00
|
|
|
public class WeekStepsChartFragment extends AbstractWeekChartFragment {
|
2016-04-11 23:18:12 +02:00
|
|
|
@Override
|
2017-02-21 16:20:42 +01:00
|
|
|
public String getTitle() {
|
2019-08-12 23:08:17 +02:00
|
|
|
if (GBApplication.getPrefs().getBoolean("charts_range", true)) {
|
|
|
|
return getString(R.string.weekstepschart_steps_a_month);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return getString(R.string.weekstepschart_steps_a_week);
|
|
|
|
}
|
2015-07-29 16:30:19 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 14:21:59 +01:00
|
|
|
@Override
|
|
|
|
String getPieDescription(int targetValue) {
|
|
|
|
return getString(R.string.weeksteps_today_steps_description, String.valueOf(targetValue));
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:30:19 +02:00
|
|
|
@Override
|
2017-02-21 16:20:42 +01:00
|
|
|
int getGoal() {
|
2018-09-16 20:49:00 +02:00
|
|
|
return GBApplication.getPrefs().getInt(ActivityUser.PREF_USER_STEPS_GOAL, ActivityUser.defaultUserStepsGoal);
|
2015-07-29 16:30:19 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 17:33:00 +01:00
|
|
|
@Override
|
|
|
|
int getOffsetHours() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:30:19 +02:00
|
|
|
@Override
|
2017-02-26 21:41:27 +01:00
|
|
|
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
2018-09-16 13:37:08 +02:00
|
|
|
long totalSteps = 0;
|
2017-02-26 00:40:50 +01:00
|
|
|
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
|
|
|
totalSteps += amount.getTotalSteps();
|
|
|
|
}
|
2017-02-26 21:41:27 +01:00
|
|
|
return new float[]{totalSteps};
|
2016-04-11 23:18:12 +02:00
|
|
|
}
|
2017-02-23 08:49:55 +01:00
|
|
|
|
2018-09-10 23:38:49 +02:00
|
|
|
@Override
|
2018-09-16 13:37:08 +02:00
|
|
|
protected long calculateBalance(ActivityAmounts activityAmounts) {
|
|
|
|
long balance = 0;
|
2018-09-10 23:38:49 +02:00
|
|
|
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
|
|
|
balance += amount.getTotalSteps();
|
|
|
|
}
|
|
|
|
return balance;
|
|
|
|
}
|
|
|
|
|
2017-02-23 21:15:57 +01:00
|
|
|
@Override
|
2018-09-16 13:37:08 +02:00
|
|
|
protected String formatPieValue(long value) {
|
2017-02-23 21:15:57 +01:00
|
|
|
return String.valueOf(value);
|
|
|
|
}
|
|
|
|
|
2017-03-31 23:42:25 +02:00
|
|
|
@Override
|
|
|
|
String[] getPieLabels() {
|
|
|
|
return new String[]{""};
|
|
|
|
}
|
|
|
|
|
2017-02-23 08:49:55 +01:00
|
|
|
@Override
|
2019-08-24 12:41:26 +02:00
|
|
|
ValueFormatter getPieValueFormatter() {
|
2017-03-03 14:21:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-08-24 12:41:26 +02:00
|
|
|
ValueFormatter getBarValueFormatter() {
|
2017-03-03 14:21:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-08-24 12:41:26 +02:00
|
|
|
ValueFormatter getYAxisFormatter() {
|
2017-02-23 08:49:55 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-26 21:41:27 +01:00
|
|
|
int[] getColors() {
|
|
|
|
return new int[]{akActivity.color};
|
2017-02-23 08:49:55 +01:00
|
|
|
}
|
2017-03-31 23:42:25 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setupLegend(Chart chart) {
|
|
|
|
// no legend here, it is all about the steps here
|
|
|
|
chart.getLegend().setEnabled(false);
|
|
|
|
}
|
2018-09-06 15:07:48 +02:00
|
|
|
|
|
|
|
@Override
|
2018-09-16 13:37:08 +02:00
|
|
|
protected String getBalanceMessage(long balance, int targetValue) {
|
2018-09-06 15:07:48 +02:00
|
|
|
if (balance > 0) {
|
2020-04-09 18:22:57 +02:00
|
|
|
final long totalBalance = balance - ((long)targetValue * TOTAL_DAYS_FOR_AVERAGE);
|
2018-09-06 15:07:48 +02:00
|
|
|
if (totalBalance > 0)
|
2018-09-16 13:37:08 +02:00
|
|
|
return getString(R.string.overstep, Math.abs(totalBalance));
|
2018-09-06 15:07:48 +02:00
|
|
|
else
|
2018-09-16 13:37:08 +02:00
|
|
|
return getString(R.string.lack_of_step, Math.abs(totalBalance));
|
2018-09-06 15:07:48 +02:00
|
|
|
} else
|
|
|
|
return getString(R.string.no_data);
|
|
|
|
}
|
2019-08-11 12:00:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
String getAverage(float value) {
|
|
|
|
return String.format("%.0f", value);
|
|
|
|
}
|
2015-07-29 16:30:19 +02:00
|
|
|
}
|