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

Add Average Settings. Addformat method to get average.

This commit is contained in:
vanous 2019-08-11 12:00:00 +02:00 committed by Andreas Shimokawa
parent f11628b42b
commit 7809655ef4
5 changed files with 27 additions and 4 deletions

View File

@ -48,6 +48,7 @@ import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -135,7 +136,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
average = Math.abs(balance / TOTAL_DAYS);
}
LimitLine average_line = new LimitLine(average);
average_line.setLabel(getString(R.string.average, average));
average_line.setLabel(getString(R.string.average, getAverage(average)));
if (average > (mTargetValue)) {
average_line.setLineColor(Color.GREEN);
@ -146,9 +147,10 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
average_line.setTextColor(Color.RED);
}
if (average > 0) {
if (GBApplication.getPrefs().getBoolean("charts_show_average", true)) {
barChart.getAxisLeft().addLimitLine(average_line);
}
}
return new WeekChartsData(barData, new PreformattedXIndexLabelFormatter(labels), getBalanceMessage(balance, mTargetValue));
}
@ -335,6 +337,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
return amounts;
}
abstract String getAverage(float value);
abstract int getGoal();
abstract int getOffsetHours();

View File

@ -167,4 +167,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
private String getHM(long value) {
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
}
@Override
String getAverage(float value) {
//return String.format("%.0f", value);
return getHM((long)value);
}
}

View File

@ -113,4 +113,9 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
} else
return getString(R.string.no_data);
}
@Override
String getAverage(float value) {
return String.format("%.0f", value);
}
}

View File

@ -73,6 +73,7 @@
<string name="pref_default">Default</string>
<string name="pref_header_charts">Charts Settings</string>
<string name="pref_title_charts_swipe">Enable left/right swipe in the charts activity</string>
<string name="pref_title_charts_average">Show averages in the charts</string>
<string name="pref_header_datetime">Date and Time</string>
<string name="pref_title_datetime_syctimeonconnect">Sync time</string>
<string name="pref_summary_datetime_syctimeonconnect">Sync time to Gadgetbridge device when connecting, and when time or time zone changes on Android device</string>
@ -417,7 +418,7 @@
<string name="weeksteps_today_steps_description">Steps today, target: %1$s</string>
<string name="lack_of_step">Lack of steps: %1$d</string>
<string name="overstep">Overstep: %1$d</string>
<string name="average">Average: %1$.0f</string>
<string name="average">Average: %1$s</string>
<string name="pref_title_dont_ack_transfer">Do not ACK activity data transfer</string>
<string name="pref_summary_dont_ack_transfers">If the activity data are not acked to the band, they will not be cleared. Useful if GB is used together with other apps.</string>
<string name="pref_summary_keep_data_on_device">Will keep activity data on the Mi Band even after synchronization. Useful if GB is used together with other apps.</string>

View File

@ -183,6 +183,12 @@
android:defaultValue="true"
android:key="charts_allow_swipe"
android:title="@string/pref_title_charts_swipe" />
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="true"
android:key="charts_show_average"
android:title="@string/pref_title_charts_average" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_key_datetime"