mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-08 19:27:04 +01:00
Merge pull request #1216 from elagin/start_end_sleep
Display start and end sleep.
This commit is contained in:
commit
f2db7b2919
@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -95,6 +94,9 @@ class ActivityAnalysis {
|
||||
}
|
||||
}
|
||||
|
||||
amount.setStartDate(sample.getTimestamp());
|
||||
amount.setEndDate(sample.getTimestamp());
|
||||
|
||||
previousAmount = amount;
|
||||
previousSample = sample;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ 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.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
@ -43,6 +44,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -62,6 +64,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
|
||||
private LineChart mActivityChart;
|
||||
private PieChart mSleepAmountChart;
|
||||
private TextView mSleepchartInfo;
|
||||
|
||||
private int mSmartAlarmFrom = -1;
|
||||
private int mSmartAlarmTo = -1;
|
||||
@ -86,9 +89,25 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
List<Integer> colors = new ArrayList<>();
|
||||
// int index = 0;
|
||||
long totalSeconds = 0;
|
||||
|
||||
Date startSleep = null;
|
||||
Date endSleep = null;
|
||||
|
||||
for (ActivityAmount amount : amounts.getAmounts()) {
|
||||
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
|
||||
long value = amount.getTotalSeconds();
|
||||
if(startSleep == null){
|
||||
startSleep = amount.getStartDate();
|
||||
} else {
|
||||
if(startSleep.after(amount.getStartDate()))
|
||||
startSleep = amount.getStartDate();
|
||||
}
|
||||
if(endSleep == null){
|
||||
endSleep = amount.getEndDate();
|
||||
} else {
|
||||
if(endSleep.before(amount.getEndDate()))
|
||||
endSleep = amount.getEndDate();
|
||||
}
|
||||
totalSeconds += value;
|
||||
// entries.add(new PieEntry(value, index++));
|
||||
entries.add(new PieEntry(value, amount.getName(getActivity())));
|
||||
@ -112,7 +131,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
data.setDataSet(set);
|
||||
|
||||
//setupLegend(pieChart);
|
||||
return new MySleepChartsData(totalSleep, data);
|
||||
return new MySleepChartsData(totalSleep, data, startSleep, endSleep);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -124,6 +143,15 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
mActivityChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||
mActivityChart.getXAxis().setValueFormatter(mcd.getChartsData().getXValueFormatter());
|
||||
mActivityChart.setData(mcd.getChartsData().getData());
|
||||
|
||||
if (mcd.getPieData().getStartSleep() != null && mcd.getPieData().getEndSleep() != null) {
|
||||
mSleepchartInfo.setText(getContext().getString(
|
||||
R.string.you_slept,
|
||||
DateTimeUtils.timeToString(mcd.getPieData().getStartSleep()),
|
||||
DateTimeUtils.timeToString(mcd.getPieData().getEndSleep())));
|
||||
} else {
|
||||
mSleepchartInfo.setText(getContext().getString(R.string.you_did_not_sleep));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,6 +166,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
|
||||
mActivityChart = (LineChart) rootView.findViewById(R.id.sleepchart);
|
||||
mSleepAmountChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
|
||||
mSleepchartInfo = (TextView) rootView.findViewById(R.id.sleepchart_info);
|
||||
|
||||
setupActivityChart();
|
||||
setupSleepAmountChart();
|
||||
@ -246,10 +275,14 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
private static class MySleepChartsData extends ChartsData {
|
||||
private String totalSleep;
|
||||
private final PieData pieData;
|
||||
private Date startSleep;
|
||||
private Date endSleep;
|
||||
|
||||
public MySleepChartsData(String totalSleep, PieData pieData) {
|
||||
public MySleepChartsData(String totalSleep, PieData pieData, Date startSleep, Date endSleep) {
|
||||
this.totalSleep = totalSleep;
|
||||
this.pieData = pieData;
|
||||
this.startSleep = startSleep;
|
||||
this.endSleep = endSleep;
|
||||
}
|
||||
|
||||
public PieData getPieData() {
|
||||
@ -259,6 +292,14 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
public CharSequence getTotalSleep() {
|
||||
return totalSleep;
|
||||
}
|
||||
|
||||
public Date getStartSleep() {
|
||||
return startSleep;
|
||||
}
|
||||
|
||||
public Date getEndSleep() {
|
||||
return endSleep;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyChartsData extends ChartsData {
|
||||
|
@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
public class ActivityAmount {
|
||||
@ -25,6 +27,8 @@ public class ActivityAmount {
|
||||
private short percent;
|
||||
private long totalSeconds;
|
||||
private long totalSteps;
|
||||
private Date startDate = null;
|
||||
private Date endDate = null;
|
||||
|
||||
public ActivityAmount(int activityKind) {
|
||||
this.activityKind = activityKind;
|
||||
@ -67,4 +71,21 @@ public class ActivityAmount {
|
||||
}
|
||||
return context.getString(R.string.abstract_chart_fragment_kind_activity);
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(int seconds) {
|
||||
if(startDate == null)
|
||||
this.startDate = new Date((long)seconds * 1000);
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(int seconds) {
|
||||
this.endDate = new Date((long)seconds * 1000);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
|
||||
public class DateTimeUtils {
|
||||
private static SimpleDateFormat DAY_STORAGE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||
private static SimpleDateFormat HOURS_MINUTES_FORMAT = new SimpleDateFormat("HH:mm", Locale.US);
|
||||
public static SimpleDateFormat ISO_8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US){
|
||||
//see https://github.com/Freeyourgadget/Gadgetbridge/issues/1076#issuecomment-383834116 and https://stackoverflow.com/a/30221245
|
||||
|
||||
@ -131,6 +132,10 @@ public class DateTimeUtils {
|
||||
return DAY_STORAGE_FORMAT.parse(day);
|
||||
}
|
||||
|
||||
public static String timeToString(Date date) {
|
||||
return HOURS_MINUTES_FORMAT.format(date);
|
||||
}
|
||||
|
||||
public static Date todayUTC() {
|
||||
Calendar cal = getCalendarUTC();
|
||||
return cal.getTime();
|
||||
|
@ -1,22 +1,35 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sleepchart_info"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="90" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="10"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/sleepchart_pie_light_deep"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="40">
|
||||
</com.github.mikephil.charting.charts.PieChart>
|
||||
android:layout_weight="40" />
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/sleepchart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
android:layout_weight="20" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!--<TextView-->
|
||||
<!--android:text="Test"-->
|
||||
|
@ -5,17 +5,22 @@
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sleepchart_info"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0" />
|
||||
|
||||
<com.github.mikephil.charting.charts.PieChart
|
||||
android:id="@+id/sleepchart_pie_light_deep"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="20"></com.github.mikephil.charting.charts.PieChart>
|
||||
android:layout_weight="2" />
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/sleepchart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
android:layout_weight="20" />
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -287,6 +287,8 @@
|
||||
<string name="abstract_chart_fragment_kind_light_sleep">Быстрый сон</string>
|
||||
<string name="abstract_chart_fragment_kind_deep_sleep">Глубокий сон</string>
|
||||
<string name="abstract_chart_fragment_kind_not_worn">Не носилось</string>
|
||||
<string name="you_slept">Вы спали с %1$s до %2$s</string>
|
||||
<string name="you_did_not_sleep">Вы не спали</string>
|
||||
<string name="device_not_connected">Не подключен.</string>
|
||||
<string name="user_feedback_all_alarms_disabled">Все будильники отключены</string>
|
||||
<string name="pref_title_keep_data_on_device">Хранить данные об активности на устройстве</string>
|
||||
@ -586,4 +588,4 @@
|
||||
<string name="title_activity_watch9_calibration">Калибровка Watch 9</string>
|
||||
<string name="mi3_prefs_band_screen_unlock">Разблокировать экран устройства</string>
|
||||
<string name="mi3_prefs_band_screen_unlock_summary">Смахните вверх, чтобы разблокировать экран устройства</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -386,6 +386,8 @@
|
||||
<string name="abstract_chart_fragment_kind_light_sleep">Light sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_deep_sleep">Deep sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_not_worn">Not worn</string>
|
||||
<string name="you_slept">You slept from %1$s to %2$s</string>
|
||||
<string name="you_did_not_sleep">You did not sleep</string>
|
||||
<string name="device_not_connected">Not connected.</string>
|
||||
<string name="user_feedback_all_alarms_disabled">All alarms disabled</string>
|
||||
<string name="pref_title_keep_data_on_device">Keep activity data on device</string>
|
||||
|
Loading…
Reference in New Issue
Block a user