From e1c245cdbd0e6033d8eaaa3445411778cae3139e Mon Sep 17 00:00:00 2001 From: Linos Giannopoulos Date: Tue, 1 Oct 2024 20:13:59 +0300 Subject: [PATCH] Make charts' date format more consistent Sleep and Steps charts already have the day/way/month sub-charts that already use the "Mon, Sep 7" format. This commit attempts to make the rest of the date formatting more consistent with that format in the activity list and the base navigation bar at the bottom of all charts. Closes #2412 Signed-off-by: Linos Giannopoulos --- .../charts/AbstractChartFragment.java | 6 ++++-- .../charts/ActivityListingChartFragment.java | 2 +- .../gadgetbridge/util/DateTimeUtils.java | 20 +++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java index 9c1aae219..3b30e7d27 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncTask; import android.os.Bundle; +import android.text.format.DateUtils; import android.view.View; import androidx.fragment.app.FragmentActivity; @@ -381,10 +382,11 @@ public abstract class AbstractChartFragment 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)); + getChartsHost().setDateInfo(DateTimeUtils.formatDate(from, dateFlags)); } else { - getChartsHost().setDateInfo(DateTimeUtils.formatDateRange(from, to)); + getChartsHost().setDateInfo(DateTimeUtils.formatDateRange(from, to, dateFlags)); } } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingChartFragment.java index 8e1845d98..411d7f359 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingChartFragment.java @@ -151,7 +151,7 @@ public class ActivityListingChartFragment extends AbstractActivityChartFragment< } Date activityDate = new Date(tsDateTo * 1000L); - stepsDateView.setText(DateTimeUtils.formatDate(activityDate)); + stepsDateView.setText(DateTimeUtils.formatDate(activityDate, DateUtils.FORMAT_SHOW_WEEKDAY)); if (GBApplication.getPrefs().getBoolean("charts_show_ongoing_activity", true)) { if (mcd.getOngoingSession() != null && DateUtils.isToday(activityDate.getTime())) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DateTimeUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DateTimeUtils.java index ef9a69a54..387bbec41 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DateTimeUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DateTimeUtils.java @@ -86,15 +86,11 @@ public class DateTimeUtils { } public static String formatDate(Date date) { - return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE); -// long dateMillis = date.getTime(); -// if (isToday(dateMillis)) { -// return "Today"; -// } -// if (isYesterday(dateMillis)) { -// return "Yesterday"; -// } -// DateFormat.getDateInstance(DateFormat.SHORT).format(date); + return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_ABBREV_ALL); + } + + public static String formatDate(Date date, int extraFlags) { + return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_ABBREV_ALL|extraFlags); } public static String formatDurationHoursMinutes(long duration, TimeUnit unit) { @@ -108,7 +104,11 @@ public class DateTimeUtils { } public static String formatDateRange(Date from, Date to) { - return DateUtils.formatDateRange(GBApplication.getContext(), from.getTime(), to.getTime(), DateUtils.FORMAT_SHOW_DATE); + return DateUtils.formatDateRange(GBApplication.getContext(), from.getTime(), to.getTime(), DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_ABBREV_ALL); + } + + public static String formatDateRange(Date from, Date to, int extraFlags) { + return DateUtils.formatDateRange(GBApplication.getContext(), from.getTime(), to.getTime(), DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_ABBREV_ALL|extraFlags); } public static Date shiftByDays(Date date, int offset) {