1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Add minimum/maximum heart rate popup, fixes #1483

This commit is contained in:
vanous 2020-11-01 23:58:54 +01:00
parent 6960b10e5d
commit 4c39dceecd
4 changed files with 31 additions and 15 deletions

View File

@ -65,7 +65,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
private static class ShowDurationDialog extends Dialog {
public static class ShowDurationDialog extends Dialog {
private final String mDuration;
private TextView durationLabel;

View File

@ -28,6 +28,8 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
@ -73,7 +75,10 @@ public class SleepChartFragment extends AbstractChartFragment {
private PieChart mSleepAmountChart;
private TextView mSleepchartInfo;
private TextView heartRateAverageLabel;
private ImageView heartRateWidget;
private ImageView heartRateIcon;
private int heartRateMin = 0;
private int heartRateMax = 0;
private int mSmartAlarmFrom = -1;
private int mSmartAlarmTo = -1;
@ -192,6 +197,8 @@ public class SleepChartFragment extends AbstractChartFragment {
mActivityChart.getXAxis().setValueFormatter(mcd.getChartsData().getXValueFormatter());
mActivityChart.setData(mcd.getChartsData().getData());
mSleepchartInfo.setText(buildYouSleptText(pieData));
heartRateMin = mcd.getHeartRateAxisMin();
heartRateMax = mcd.getHeartRateAxisMax();
if (!CHARTS_SLEEP_RANGE_24H
&& supportsHeartrate(getChartsHost().getDevice())
@ -289,8 +296,17 @@ public class SleepChartFragment extends AbstractChartFragment {
mActivityChart = rootView.findViewById(R.id.sleepchart);
mSleepAmountChart = rootView.findViewById(R.id.sleepchart_pie_light_deep);
mSleepchartInfo = rootView.findViewById(R.id.sleepchart_info);
heartRateWidget = rootView.findViewById(R.id.heartrate_widget_icon);
heartRateIcon = rootView.findViewById(R.id.heartrate_widget_icon);
heartRateAverageLabel = rootView.findViewById(R.id.heartrate_widget_label);
ConstraintLayout heartRateWidgetLayout = rootView.findViewById(R.id.heartrate_widget_layout);
heartRateWidgetLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String detailedDuration = String.format(getString(R.string.charts_min_max_heartrate_popup), heartRateMin, heartRateMax);
new ChartsActivity.ShowDurationDialog(detailedDuration, getContext()).show();
}
});
setupActivityChart();
setupSleepAmountChart();
@ -372,7 +388,7 @@ public class SleepChartFragment extends AbstractChartFragment {
deepSleepEntry.label = akDeepSleep.label;
deepSleepEntry.formColor = akDeepSleep.color;
legendEntries.add(deepSleepEntry);
heartRateWidget.setVisibility(View.GONE); //hide heart icon
heartRateIcon.setVisibility(View.GONE); //hide heart icon
if (supportsHeartrate(getChartsHost().getDevice())) {
LegendEntry hrEntry = new LegendEntry();
@ -384,7 +400,7 @@ public class SleepChartFragment extends AbstractChartFragment {
hrAverageEntry.label = HEARTRATE_AVERAGE_LABEL;
hrAverageEntry.formColor = Color.RED;
legendEntries.add(hrAverageEntry);
heartRateWidget.setVisibility(View.VISIBLE);
heartRateIcon.setVisibility(View.VISIBLE);
}
}
chart.getLegend().setCustom(legendEntries);
@ -432,12 +448,12 @@ public class SleepChartFragment extends AbstractChartFragment {
private final DefaultChartsData<LineData> chartsData;
private final MySleepChartsData pieData;
private final float heartRateAverage;
private float heartRateAxisMax;
private float heartRateAxisMin;
private int heartRateAxisMax;
private int heartRateAxisMin;
private float intensityAxisMax;
private float intensityAxisMin;
public MyChartsData(MySleepChartsData pieData, DefaultChartsData<LineData> chartsData, float heartRateAverage, float heartRateAxisMin, float heartRateAxisMax, float intensityAxisMin, float intensityAxisMax) {
public MyChartsData(MySleepChartsData pieData, DefaultChartsData<LineData> chartsData, float heartRateAverage, int heartRateAxisMin, int heartRateAxisMax, float intensityAxisMin, float intensityAxisMax) {
this.pieData = pieData;
this.chartsData = chartsData;
this.heartRateAverage = heartRateAverage;
@ -457,13 +473,11 @@ public class SleepChartFragment extends AbstractChartFragment {
return heartRateAverage;
}
public float getHeartRateAxisMax() {
public int getHeartRateAxisMax() {
return heartRateAxisMax;
}
public float getHeartRateAxisMin() {
return heartRateAxisMin;
}
public int getHeartRateAxisMin() { return heartRateAxisMin; }
public float getIntensityAxisMax() {
return intensityAxisMax;

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/charts_duration_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
android:layout_height="wrap_content"
android:padding="5dp" />
</LinearLayout>

View File

@ -509,6 +509,7 @@
<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="charts_min_max_heartrate_popup">Lowest heart rate: %1$d \nHighest heart rate: %2$d</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>