From 4665640835169131746dbe026d018142b630ba9b Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 12 Mar 2023 18:21:47 +0100 Subject: [PATCH] Added workaround for formatDateRange crash --- .../eu/faircode/email/FragmentMessages.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6b6775ac02..131c48f1b7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1048,16 +1048,39 @@ public class FragmentMessages extends FragmentBase cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.DAY_OF_MONTH, -1); - CharSequence rtime; - if (time <= cal.getTimeInMillis()) - rtime = DateUtils.formatDateRange(context, - time, time, - FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_DATE); - else - rtime = DateUtils.getRelativeTimeSpanString( - time, now.getTime(), - DAY_IN_MILLIS, 0); - return (rtime == null ? "" : rtime.toString()); + try { + CharSequence rtime; + if (time <= cal.getTimeInMillis()) + rtime = DateUtils.formatDateRange(context, + time, time, + FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_DATE); + else + rtime = DateUtils.getRelativeTimeSpanString( + time, now.getTime(), + DAY_IN_MILLIS, 0); + return (rtime == null ? "" : rtime.toString()); + } catch (Throwable ex) { + Log.e(ex); + /* + java.util.MissingResourceException: Can't find resource for bundle android/icu/impl/data/icudt60b/supplementalData.res, key calendarPreferenceData + at android.icu.util.UResourceBundle.get(UResourceBundle.java:491) + at android.icu.util.Calendar.getKeywordValuesForLocale(Calendar.java:1873) + at android.icu.text.DateTimePatternGenerator.getCalendarTypeToUse(DateTimePatternGenerator.java:165) + at android.icu.text.DateTimePatternGenerator.addCLDRData(DateTimePatternGenerator.java:265) + at android.icu.text.DateTimePatternGenerator.initData(DateTimePatternGenerator.java:139) + at android.icu.text.DateTimePatternGenerator.getFrozenInstance(DateTimePatternGenerator.java:123) + at android.icu.text.DateTimePatternGenerator.getInstance(DateTimePatternGenerator.java:92) + at android.icu.text.DateIntervalFormat.getInstance(DateIntervalFormat.java:470) + at libcore.icu.DateIntervalFormat.getFormatter(DateIntervalFormat.java:100) + at libcore.icu.DateIntervalFormat.formatDateRange(DateIntervalFormat.java:87) + at libcore.icu.DateIntervalFormat.formatDateRange(DateIntervalFormat.java:49) + at android.text.format.DateUtils.formatDateRange(DateUtils.java:735) + at android.text.format.DateUtils.formatDateRange(DateUtils.java:560) + at android.text.format.DateUtils.formatDateRange(DateUtils.java:537) + at eu.faircode.email.FragmentMessages$13.getRelativeDate(SourceFile:52) + */ + return Helper.getDateInstance(context).format(time); + } } @NonNull