1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 09:35:50 +01:00

Respiratory rate: fix strings, margins, missing data on chart

This commit is contained in:
a0z 2024-11-26 22:18:47 +01:00 committed by José Rebelo
parent 9ae56ae88c
commit a11f6871cd
7 changed files with 42 additions and 12 deletions

View File

@ -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";

View File

@ -106,11 +106,29 @@ public class RespiratoryRateDailyFragment extends RespiratoryRateFragment<Respir
respiratoryRateChart.getLegend().setTextColor(TEXT_COLOR);
respiratoryRateChart.getLegend().setCustom(legendEntries);
final List<Entry> lineEntries = new ArrayList<>();
final List<ILineDataSet> lineDataSets = new ArrayList<>();
List<Entry> 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<Entry> 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<Respir
lineDataSet.setDrawValues(false);
lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
final List<ILineDataSet> lineDataSets = new ArrayList<>();
lineDataSets.add(lineDataSet);
final LineData lineData = new LineData(lineDataSets);
respiratoryRateChart.setData(lineData);
}
protected LineDataSet createDataSet(final List<Entry> 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();

View File

@ -168,8 +168,8 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<Respi
}
}
LineDataSet awakeDataSet = createDataSet(lineAwakeRateAvgEntries, getString(R.string.awake_avg), R.color.respiratory_rate_color);
LineDataSet sleepDataSet = createDataSet(lineSleepRateEntries, getString(R.string.awake_avg), R.color.chart_light_sleep_light);
LineDataSet awakeDataSet = createDataSet(lineAwakeRateAvgEntries, getString(R.string.sleep_colored_stats_awake_avg), R.color.respiratory_rate_color);
LineDataSet sleepDataSet = createDataSet(lineSleepRateEntries, getString(R.string.sleep_avg), R.color.chart_light_sleep_light);
final List<ILineDataSet> lineDataSets = new ArrayList<>();
lineDataSets.add(awakeDataSet);
@ -177,7 +177,7 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<Respi
List<LegendEntry> 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);

View File

@ -51,7 +51,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/awake_avg"
android:text="@string/sleep_colored_stats_awake_avg"
android:textSize="12sp" />
</LinearLayout>
@ -77,7 +77,6 @@
<LinearLayout
style="@style/GridTile"
android:layout_marginStart="1dp"
android:layout_marginTop="2dp"
>
<TextView
android:id="@+id/day_lowest"
@ -95,7 +94,6 @@
<LinearLayout
style="@style/GridTile"
android:layout_marginStart="1dp"
android:layout_marginTop="2dp"
>
<TextView
android:id="@+id/day_highest"

View File

@ -71,7 +71,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/awake_avg"
android:text="@string/sleep_colored_stats_awake_avg"
android:textSize="12sp" />
</LinearLayout>
</GridLayout>

View File

@ -3114,6 +3114,7 @@
<item>@string/menuitem_temperature</item>
<item>@string/menuitem_weight</item>
<item>@string/watchface_widget_type_calories</item>
<item>@string/p_respiratory_rate</item>
</string-array>
<string-array name="pref_charts_tabs_values">

View File

@ -1019,7 +1019,6 @@
<string name="sleep_colored_stats_light_avg">Light AVG</string>
<string name="sleep_colored_stats_rem_avg">REM AVG</string>
<string name="sleep_colored_stats_awake_avg">Awake AVG</string>
<string name="awake_avg">Awake AVG</string>
<string name="sleep_avg">Sleep AVG</string>
<string name="lowest">Lowest</string>
<string name="highest">Highest</string>