Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh#1463 fix wrong day display in widget #1469

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventInfo>(50);
Expand All @@ -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<LinkedList<RowInfo>> mBuckets =
new ArrayList<LinkedList<RowInfo>>(CalendarAppWidgetService.MAX_DAYS);
for (int i = 0; i < CalendarAppWidgetService.MAX_DAYS; i++) {
mBuckets.add(new LinkedList<RowInfo>());
}
recycle.set(System.currentTimeMillis());
mShowTZ = !TextUtils.equals(timeZone, Utils.getCurrentTimezone());
if (mShowTZ) {
mHomeTZName = TimeZone.getTimeZone(timeZone).getDisplayName(false, TimeZone.SHORT);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down