1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Change weekly sleep charts to display sleep from 12:00-12:00 instead of 0:00-0:00

This commit is contained in:
Andreas Shimokawa 2017-03-03 17:33:00 +01:00
parent a0bb0c973c
commit a90e0074fc
4 changed files with 22 additions and 10 deletions

View File

@ -47,6 +47,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
private PieChart mTodayPieChart;
private BarChart mWeekChart;
private int mOffsetHours = getOffsetHours();
@Override
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
Calendar day = Calendar.getInstance();
@ -213,7 +215,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
// chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
}
private List<? extends ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, GBDevice device) {
private List<? extends ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, int offsetHours, GBDevice device) {
int startTs;
int endTs;
@ -221,12 +223,10 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
day.set(Calendar.HOUR_OF_DAY, 0);
day.set(Calendar.MINUTE, 0);
day.set(Calendar.SECOND, 0);
startTs = (int) (day.getTimeInMillis() / 1000);
day.add(Calendar.HOUR, offsetHours);
day.set(Calendar.HOUR_OF_DAY, 23);
day.set(Calendar.MINUTE, 59);
day.set(Calendar.SECOND, 59);
endTs = (int) (day.getTimeInMillis() / 1000);
startTs = (int) (day.getTimeInMillis() / 1000);
endTs = startTs + 24 * 60 * 60 - 1;
return getSamples(db, device, startTs, endTs);
}
@ -272,14 +272,14 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
Activity activity = getActivity();
if (activity != null) {
activityAmountCache = ((ChartsActivity) activity).mActivityAmountCache;
amounts = (ActivityAmounts) (activityAmountCache.lookup(day.hashCode()));
amounts = (ActivityAmounts) (activityAmountCache.lookup(day.hashCode() ^ mOffsetHours));
}
if (amounts == null) {
ActivityAnalysis analysis = new ActivityAnalysis();
amounts = analysis.calculateActivityAmounts(getSamplesOfDay(db, day, device));
amounts = analysis.calculateActivityAmounts(getSamplesOfDay(db, day, mOffsetHours, device));
if (activityAmountCache != null) {
activityAmountCache.add(day.hashCode(), amounts);
activityAmountCache.add(day.hashCode() ^ mOffsetHours, amounts);
}
}
@ -288,6 +288,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract int getGoal();
abstract int getOffsetHours();
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
abstract String formatPieValue(int value);

View File

@ -53,7 +53,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
private PagerTabStrip mPagerTabStrip;
private ViewPager viewPager;
LimitedQueue mActivityAmountCache = new LimitedQueue(32);
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
private static class ShowDurationDialog extends Dialog {
private final String mDuration;

View File

@ -30,6 +30,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
return 8 * 60; // FIXME
}
@Override
int getOffsetHours() {
return -12;
}
@Override
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
long totalSecondsDeepSleep = 0;

View File

@ -29,6 +29,11 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
return -1;
}
@Override
int getOffsetHours() {
return 0;
}
@Override
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
int totalSteps = 0;