1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 18:36:50 +01:00

Add switch to set old/new style of sleep detection range

This commit is contained in:
vanous 2019-10-26 10:39:15 +02:00
parent 31ce36e335
commit 71b393932f
5 changed files with 36 additions and 11 deletions

View File

@ -6,8 +6,7 @@
* Makibes HR3: Support the english version
* Makibes HR3: Enable bluetooth pairing for working reconnection
* Work around crash when trying to display changelog
* "Limit sleep charts range" (FIXME)
* " Check for non empty list of sleep sessions" (FIXME)
* Sleep detection settings: Rolling 24 hours (existing style) or Noon to noon
#### Version 0.37.1
* Amazfit Bip Lite: Support flashing firmware and watchfaces

View File

@ -720,7 +720,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
protected List<? extends ActivitySample> getSamplesofSleep(DBHandler db, GBDevice device) {
int SLEEP_HOUR_LIMIT = 13;
int SLEEP_HOUR_LIMIT = 12;
int tsStart = getTSStart();
Calendar day = GregorianCalendar.getInstance();

View File

@ -48,6 +48,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession;
@ -56,6 +57,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class SleepChartFragment extends AbstractChartFragment {
@ -72,17 +74,26 @@ public class SleepChartFragment extends AbstractChartFragment {
@Override
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
List<? extends ActivitySample> samples = getSamplesofSleep(db, device);
Prefs prefs = GBApplication.getPrefs();
List<? extends ActivitySample> samples;
if (prefs.getBoolean("chart_sleep_range_24h", false)) {
samples = getSamples(db, device);
}else{
samples = getSamplesofSleep(db, device);
}
MySleepChartsData mySleepChartsData = refreshSleepAmounts(device, samples);
if (mySleepChartsData.sleepSessions.size()>0) {
long tstart = mySleepChartsData.sleepSessions.get(0).getSleepStart().getTime() / 1000;
long tend = mySleepChartsData.sleepSessions.get(mySleepChartsData.sleepSessions.size() - 1).getSleepEnd().getTime() / 1000;
for (Iterator<ActivitySample> iterator = (Iterator<ActivitySample>) samples.iterator(); iterator.hasNext(); ) {
ActivitySample sample = iterator.next();
if (sample.getTimestamp() < tstart || sample.getTimestamp() > tend) {
iterator.remove();
if (!prefs.getBoolean("chart_sleep_range_24h", false)) {
if (mySleepChartsData.sleepSessions.size() > 0) {
long tstart = mySleepChartsData.sleepSessions.get(0).getSleepStart().getTime() / 1000;
long tend = mySleepChartsData.sleepSessions.get(mySleepChartsData.sleepSessions.size() - 1).getSleepEnd().getTime() / 1000;
for (Iterator<ActivitySample> iterator = (Iterator<ActivitySample>) samples.iterator(); iterator.hasNext(); ) {
ActivitySample sample = iterator.next();
if (sample.getTimestamp() < tstart || sample.getTimestamp() > tend) {
iterator.remove();
}
}
}
}

View File

@ -532,6 +532,10 @@
<string name="pref_title_chart_heartrate_color">Heart rate color</string>
<string name="weekstepschart_steps_a_month">Steps per month</string>
<string name="weeksleepchart_sleep_a_month">Sleep per month</string>
<string name="pref_title_chart_sleep_rolling_24_hour">Sleep range</string>
<string name="pref_chart_sleep_rolling_24_on">Past 24 hours</string>
<string name="pref_chart_sleep_rolling_24_off">Noon to noon</string>
<string name="authenticating">Authenticating</string>
<string name="authentication_required">Authentication required</string>
<string name="activity_prefs_sleep_duration">Preferred sleep duration in hours</string>

View File

@ -31,6 +31,15 @@
android:defaultValue="true"
android:key="charts_allow_swipe"
android:title="@string/pref_title_charts_swipe" />
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="false"
android:key="chart_sleep_range_24h"
android:summaryOff="@string/pref_chart_sleep_rolling_24_off"
android:summaryOn="@string/pref_chart_sleep_rolling_24_on"
android:title="@string/pref_title_chart_sleep_rolling_24_hour" />
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="true"
@ -44,5 +53,7 @@
android:summaryOff="@string/pref_charts_range_off"
android:summaryOn="@string/pref_charts_range_on"
android:title="@string/pref_title_charts_range" />
</PreferenceCategory>
</PreferenceScreen>