From a11f6871cdb84762cc1590a486b6211c711a8f8f Mon Sep 17 00:00:00 2001 From: a0z Date: Tue, 26 Nov 2024 22:18:47 +0100 Subject: [PATCH] Respiratory rate: fix strings, margins, missing data on chart --- .../gadgetbridge/GBApplication.java | 2 +- .../charts/RespiratoryRateDailyFragment.java | 38 +++++++++++++++++-- .../charts/RespiratoryRatePeriodFragment.java | 6 +-- .../res/layout/fragment_respiratory_rate.xml | 4 +- .../fragment_respiratory_rate_period.xml | 2 +- app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/strings.xml | 1 - 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index e137acc90..dbd91c454 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -1901,7 +1901,7 @@ public class GBApplication extends Application { } final String newPrefValue; - if (!StringUtils.isBlank(chartsTabsValue)) { + if (!StringUtils.isBlank(chartsTabsValue) && !chartsTabsValue.contains("respiratoryrate")) { newPrefValue = chartsTabsValue + ",respiratoryrate"; } else { newPrefValue = "respiratoryrate"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRateDailyFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRateDailyFragment.java index 22f418ac6..a6c53ba58 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRateDailyFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRateDailyFragment.java @@ -106,11 +106,29 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment lineEntries = new ArrayList<>(); + final List lineDataSets = new ArrayList<>(); + List lineEntries = new ArrayList<>(); final TimestampTranslation tsTranslation = new TimestampTranslation(); + int lastTsShorten = 0; for (final AbstractRespiratoryRateSample sample : respiratoryRateDay.respiratoryRateSamples) { int ts = (int) (sample.getTimestamp() / 1000L); - lineEntries.add(new Entry(tsTranslation.shorten(ts), (int) sample.getRespiratoryRate())); + int tsShorten = tsTranslation.shorten(ts); + if (lastTsShorten == 0 || (tsShorten - lastTsShorten) <= 300) { + lineEntries.add(new Entry(tsShorten, (int) sample.getRespiratoryRate())); + } else { + if (!lineEntries.isEmpty()) { + List clone = new ArrayList<>(lineEntries.size()); + clone.addAll(lineEntries); + lineDataSets.add(createDataSet(clone)); + lineEntries.clear(); + } + } + lastTsShorten = tsShorten; + lineEntries.add(new Entry(tsShorten, (int) sample.getRespiratoryRate())); + } + + if (!lineEntries.isEmpty()) { + lineDataSets.add(createDataSet(lineEntries)); } respiratoryRateChart.getXAxis().setValueFormatter(new SampleXLabelFormatter(tsTranslation, "HH:mm")); @@ -130,12 +148,26 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment lineDataSets = new ArrayList<>(); lineDataSets.add(lineDataSet); final LineData lineData = new LineData(lineDataSets); respiratoryRateChart.setData(lineData); } + protected LineDataSet createDataSet(final List values) { + final LineDataSet lineDataSet = new LineDataSet(values, getString(R.string.respiratoryRate)); + lineDataSet.setColor(getResources().getColor(R.color.respiratory_rate_color)); + lineDataSet.setDrawCircles(false); + lineDataSet.setLineWidth(2f); + lineDataSet.setFillAlpha(255); + lineDataSet.setDrawCircles(false); + lineDataSet.setCircleColor(getResources().getColor(R.color.respiratory_rate_color)); + lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); + lineDataSet.setDrawValues(false); + lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER); + + return lineDataSet; + } + @Override protected void renderCharts() { respiratoryRateChart.invalidate(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRatePeriodFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRatePeriodFragment.java index e8d69553c..7c70ed960 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRatePeriodFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/RespiratoryRatePeriodFragment.java @@ -168,8 +168,8 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment lineDataSets = new ArrayList<>(); lineDataSets.add(awakeDataSet); @@ -177,7 +177,7 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment legendEntries = new ArrayList<>(1); LegendEntry awakeEntry = new LegendEntry(); - awakeEntry.label = getString(R.string.awake_avg); + awakeEntry.label = getString(R.string.sleep_colored_stats_awake_avg); awakeEntry.formColor = getResources().getColor(R.color.respiratory_rate_color); LegendEntry sleepEntry = new LegendEntry(); sleepEntry.label = getString(R.string.sleep_avg); diff --git a/app/src/main/res/layout/fragment_respiratory_rate.xml b/app/src/main/res/layout/fragment_respiratory_rate.xml index 3b765765e..5b25e5a7c 100644 --- a/app/src/main/res/layout/fragment_respiratory_rate.xml +++ b/app/src/main/res/layout/fragment_respiratory_rate.xml @@ -51,7 +51,7 @@ @@ -77,7 +77,6 @@ diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index dbc15a901..d73325e16 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -3114,6 +3114,7 @@ @string/menuitem_temperature @string/menuitem_weight @string/watchface_widget_type_calories + @string/p_respiratory_rate diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c37131ffa..a106c48c3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1019,7 +1019,6 @@ Light AVG REM AVG Awake AVG - Awake AVG Sleep AVG Lowest Highest