Skip to content

Commit 2a67bdb

Browse files
author
marunjar
committed
improve scroll performance
another improvement for #139 there is no need to iterate over all days for 2 months to collect and calculate eventRects, it works if u just check all days with events
1 parent 345df42 commit 2a67bdb

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -858,25 +858,29 @@ private void getMoreEvents(Calendar day) {
858858
}
859859

860860
// Prepare to calculate positions of each events.
861-
ArrayList<EventRect> tempEvents = new ArrayList<EventRect>(mEventRects);
861+
List<EventRect> tempEvents = mEventRects;
862862
mEventRects = new ArrayList<EventRect>();
863-
Calendar dayCounter = (Calendar) day.clone();
864-
dayCounter.add(Calendar.MONTH, -1);
865-
dayCounter.set(Calendar.DAY_OF_MONTH, 1);
866-
Calendar maxDay = (Calendar) day.clone();
867-
maxDay.add(Calendar.MONTH, 1);
868-
maxDay.set(Calendar.DAY_OF_MONTH, maxDay.getActualMaximum(Calendar.DAY_OF_MONTH));
869-
870-
// Iterate through each day to calculate the position of the events.
871-
while (dayCounter.getTimeInMillis() <= maxDay.getTimeInMillis()) {
872-
ArrayList<EventRect> eventRects = new ArrayList<EventRect>();
873-
for (EventRect eventRect : tempEvents) {
874-
if (isSameDay(eventRect.event.getStartTime(), dayCounter))
875-
eventRects.add(eventRect);
876-
}
877863

864+
// Iterate through each day with events to calculate the position of the events.
865+
while (tempEvents.size() > 0) {
866+
ArrayList<EventRect> eventRects = new ArrayList<>(tempEvents.size());
867+
868+
// get first event for a day
869+
EventRect eventRect1 = tempEvents.remove(0);
870+
eventRects.add(eventRect1);
871+
872+
int i = 0;
873+
while (i < tempEvents.size()) {
874+
// collect all other events for same day
875+
EventRect eventRect2 = tempEvents.get(i);
876+
if (isSameDay(eventRect1.event.getStartTime(), eventRect2.event.getStartTime())) {
877+
tempEvents.remove(i);
878+
eventRects.add(eventRect2);
879+
} else {
880+
i++;
881+
}
882+
}
878883
computePositionOfEvents(eventRects);
879-
dayCounter.add(Calendar.DATE, 1);
880884
}
881885
}
882886

0 commit comments

Comments
 (0)