From 5bebfdc170bbefd2047de436bc87c10be04eb358 Mon Sep 17 00:00:00 2001 From: Lionel Mamane Date: Fri, 6 Oct 2023 10:01:52 +0200 Subject: [PATCH 1/3] factorise setting FORMAT_SHOW_WEEKDAY since it is set in all cases --- .../android/calendar/widget/CalendarAppWidgetModel.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java index ed98583ab..276468fba 100644 --- a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java +++ b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java @@ -204,15 +204,16 @@ private EventInfo populateEventInfo(long eventId, boolean allDay, long start, lo private DayInfo populateDayInfo(int julianDay, Time recycle) { long millis = recycle.setJulianDay(julianDay); - int flags = DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE; + int flags = + DateUtils.FORMAT_ABBREV_ALL | + DateUtils.FORMAT_SHOW_DATE | + DateUtils.FORMAT_SHOW_WEEKDAY; String label; if (julianDay == mTodayJulianDay + 1) { - flags |= DateUtils.FORMAT_SHOW_WEEKDAY; label = mContext.getString(R.string.agenda_tomorrow, Utils.formatDateRange(mContext, millis, millis, flags)); } else { - flags |= DateUtils.FORMAT_SHOW_WEEKDAY; label = Utils.formatDateRange(mContext, millis, millis, flags); } return new DayInfo(julianDay, label); From bf48961a57ab1b235cab37d2de59906fb4643c74 Mon Sep 17 00:00:00 2001 From: Lionel Mamane Date: Fri, 6 Oct 2023 10:04:58 +0200 Subject: [PATCH 2/3] remove small race condition --- .../com/android/calendar/widget/CalendarAppWidgetModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java index 276468fba..a8b720720 100644 --- a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java +++ b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java @@ -50,7 +50,7 @@ class CalendarAppWidgetModel { public CalendarAppWidgetModel(Context context, String timeZone) { mNow = System.currentTimeMillis(); Time time = new Time(timeZone); - time.set(System.currentTimeMillis()); // This is needed for gmtoff to be set + time.set(mNow); // This is needed for gmtoff to be set mTodayJulianDay = Time.getJulianDay(mNow, time.getGmtOffset()); mMaxJulianDay = mTodayJulianDay + CalendarAppWidgetService.MAX_DAYS - 1; mEventInfos = new ArrayList(50); From 983b9a96b7232313ae48cb77d2cf507bf4d5a350 Mon Sep 17 00:00:00 2001 From: Lionel Mamane Date: Fri, 6 Oct 2023 10:42:35 +0200 Subject: [PATCH 3/3] gh#1463 don't pass recycle to functions that can thrash it when subsequent uses _do_ depend on (part of) the value thereof. --- .../com/android/calendar/widget/CalendarAppWidgetModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java index a8b720720..d454d6ba3 100644 --- a/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java +++ b/app/src/main/java/com/android/calendar/widget/CalendarAppWidgetModel.java @@ -60,13 +60,11 @@ public CalendarAppWidgetModel(Context context, String timeZone) { } public void buildFromCursor(Cursor cursor, String timeZone) { - final Time recycle = new Time(timeZone); final ArrayList> mBuckets = new ArrayList>(CalendarAppWidgetService.MAX_DAYS); for (int i = 0; i < CalendarAppWidgetService.MAX_DAYS; i++) { mBuckets.add(new LinkedList()); } - recycle.set(System.currentTimeMillis()); mShowTZ = !TextUtils.equals(timeZone, Utils.getCurrentTimezone()); if (mShowTZ) { mHomeTZName = TimeZone.getTimeZone(timeZone).getDisplayName(false, TimeZone.SHORT); @@ -93,6 +91,7 @@ public void buildFromCursor(Cursor cursor, String timeZone) { // Adjust all-day times into local timezone if (allDay) { + final Time recycle = new Time(); start = Utils.convertAlldayUtcToLocal(recycle, start, tz); end = Utils.convertAlldayUtcToLocal(recycle, end, tz); } @@ -131,6 +130,7 @@ public void buildFromCursor(Cursor cursor, String timeZone) { if (!bucket.isEmpty()) { // We don't show day header in today if (day != mTodayJulianDay) { + final Time recycle = new Time(timeZone); final DayInfo dayInfo = populateDayInfo(day, recycle); // Add the day header final int dayIndex = mDayInfos.size();