1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Show single day in bottom charts label

This commit is contained in:
José Rebelo 2024-10-05 14:43:35 +01:00
parent 694227a3b1
commit 5272d017ac
9 changed files with 57 additions and 20 deletions

View File

@ -141,6 +141,11 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
akNotWorn = new ActivityConfig(ActivityKind.NOT_WORN, getString(R.string.abstract_chart_fragment_kind_not_worn), AK_NOT_WORN_COLOR);
}
@Override
protected boolean isSingleDay() {
return false;
}
protected Integer getColorFor(ActivityKind activityKind) {
switch (activityKind) {
case DEEP_SLEEP:

View File

@ -154,6 +154,7 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
protected void onMadeVisibleInActivity() {
super.onMadeVisibleInActivity();
showDateBar(true);
updateDateInfo(getStartDate(), getEndDate());
if (mChartDirty) {
refresh();
}
@ -187,6 +188,14 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
return toTimestamp(getStartDate());
}
/**
* Whether this chart shows data only for a single day. The day is expected to match
* the end timestamp.
*/
protected boolean isSingleDay() {
return true;
}
protected int toTimestamp(Date date) {
return (int) ((date.getTime() / 1000));
}
@ -236,6 +245,8 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
if (!shiftDates(startDate, endDate, offset)) {
return;
}
updateDateInfo(getStartDate(), getEndDate());
}
refreshIfVisible();
}
@ -316,7 +327,6 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
if (chartsHost != null) {
if (chartsHost.getDevice() != null) {
mChartDirty = false;
updateDateInfo(getStartDate(), getEndDate());
if (refreshTask != null && refreshTask.getStatus() != AsyncTask.Status.FINISHED) {
refreshTask.cancel(true);
}
@ -383,8 +393,8 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
private void updateDateInfo(final Date from, final Date to) {
int dateFlags = DateUtils.FORMAT_SHOW_WEEKDAY;
if (from.equals(to)) {
getChartsHost().setDateInfo(DateTimeUtils.formatDate(from, dateFlags));
if (isSingleDay() || from.equals(to)) {
getChartsHost().setDateInfo(DateTimeUtils.formatDate(to, dateFlags));
} else {
getChartsHost().setDateInfo(DateTimeUtils.formatDateRange(from, to, dateFlags));
}

View File

@ -60,7 +60,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class SleepChartFragment extends AbstractActivityChartFragment<SleepChartFragment.MyChartsData> {
public class DaySleepChartFragment extends AbstractActivityChartFragment<DaySleepChartFragment.MyChartsData> {
protected static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
private LineChart mActivityChart;
@ -93,6 +93,10 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
private boolean SHOW_CHARTS_AVERAGE = prefs.getBoolean("charts_show_average", true);
private int sleepLinesLimit = prefs.getInt("chart_sleep_lines_limit", 6);
@Override
protected boolean isSingleDay() {
return true;
}
@Override
protected MyChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {

View File

@ -30,7 +30,6 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;

View File

@ -34,14 +34,12 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.DefaultAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -82,9 +80,9 @@ public class Spo2ChartFragment extends AbstractChartFragment<Spo2ChartFragment.S
CHART_TEXT_COLOR = GBApplication.getSecondaryTextColor(requireContext());
if (prefs.getBoolean("chart_heartrate_color", false)) {
CHART_LINE_COLOR = ContextCompat.getColor(getContext(), R.color.chart_heartrate_alternative);
CHART_LINE_COLOR = ContextCompat.getColor(requireContext(), R.color.chart_heartrate_alternative);
} else {
CHART_LINE_COLOR = ContextCompat.getColor(getContext(), R.color.chart_heartrate);
CHART_LINE_COLOR = ContextCompat.getColor(requireContext(), R.color.chart_heartrate);
}
SPO2_AVERAGE_LABEL = requireContext().getString(R.string.charts_legend_spo2_average);
@ -124,7 +122,7 @@ public class Spo2ChartFragment extends AbstractChartFragment<Spo2ChartFragment.S
mSpo2Chart.setData(chartsData.getData());
mSpo2Chart.getAxisLeft().removeAllLimitLines();
LOG.info("SpO2 average: " + spo2Data.getAverage());
LOG.debug("SpO2 average: {}", spo2Data.getAverage());
if (spo2Data.getAverage() > 0 && SHOW_CHARTS_AVERAGE) {
final LimitLine averageLine = new LimitLine(spo2Data.getAverage());
@ -142,6 +140,11 @@ public class Spo2ChartFragment extends AbstractChartFragment<Spo2ChartFragment.S
return requireContext().getString(R.string.pref_header_spo2);
}
@Override
public boolean isSingleDay() {
return false;
}
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,

View File

@ -150,6 +150,11 @@ public class TemperatureChartFragment extends AbstractChartFragment<TemperatureC
mTemperatureChart.animateX(ANIM_TIME, Easing.EaseInOutQuart);
}
@Override
protected boolean isSingleDay() {
return false;
}
@Override
protected int getTSStart() {
return getTSEnd() - TOTAL_DAYS*24*60*60;

View File

@ -94,6 +94,11 @@ public class WeightChartFragment extends AbstractChartFragment<WeightChartFragme
weightTargetKg = prefs.getInt(ActivityUser.PREF_USER_GOAL_WEIGHT_KG, ActivityUser.defaultUserGoalWeightKg);
}
@Override
protected boolean isSingleDay() {
return false;
}
@Override
protected WeightChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
long tsStart = getTSStart() * 1000L;

View File

@ -6,7 +6,7 @@ import androidx.fragment.app.FragmentManager;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepChartFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.DaySleepChartFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.WeekSleepChartFragment;
public class SleepFragmentAdapter extends NestedFragmentAdapter {
@ -19,12 +19,12 @@ public class SleepFragmentAdapter extends NestedFragmentAdapter {
public Fragment createFragment(int position) {
switch (position) {
case 0:
return new SleepChartFragment();
return new DaySleepChartFragment();
case 1:
return WeekSleepChartFragment.newInstance(7);
case 2:
return WeekSleepChartFragment.newInstance(30);
}
return new SleepChartFragment();
return new DaySleepChartFragment();
}
}

View File

@ -40,7 +40,7 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="Today" />
android:text="@string/stats_empty_value" />
</LinearLayout>
@ -58,7 +58,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text="&lt;&lt;&lt;" />
android:text="&lt;&lt;&lt;"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/charts_previous_week"
@ -67,7 +68,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text="&lt;&lt;" />
android:text="&lt;&lt;"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/charts_previous_day"
@ -76,7 +78,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text="&lt;" />
android:text="&lt;"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/charts_next_day"
@ -85,7 +88,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text=">" />
android:text=">"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/charts_next_week"
android:layout_width="wrap_content"
@ -93,7 +97,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text=">>" />
android:text=">>"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/charts_next_month"
@ -102,7 +107,8 @@
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginHorizontal="2dp"
android:text=">>>" />
android:text=">>>"
tools:ignore="HardcodedText"/>
</LinearLayout>
</LinearLayout>