Skip to content

Commit 3d8d98c

Browse files
author
Jens Claes
committed
Merge pull request #236 from psamim/pr-weekviewevent
Accept subclasses of WeekViewEvent through MonthChangeListener interface
2 parents 119104b + 1d37ab7 commit 3d8d98c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public double toWeekViewPeriodIndex(Calendar instance){
1717
}
1818

1919
@Override
20-
public List<WeekViewEvent> onLoad(int periodIndex){
20+
public List<? extends WeekViewEvent> onLoad(int periodIndex){
2121
return mOnMonthChangeListener.onMonthChange(periodIndex / 12, periodIndex % 12 + 1);
2222
}
2323

@@ -34,10 +34,10 @@ public interface MonthChangeListener {
3434
* Very important interface, it's the base to load events in the calendar.
3535
* This method is called three times: once to load the previous month, once to load the next month and once to load the current month.<br/>
3636
* <strong>That's why you can have three times the same event at the same place if you mess up with the configuration</strong>
37-
* @param newYear: year of the events required by the view.
38-
* @param newMonth: month of the events required by the view <br/><strong>1 based (not like JAVA API) --> January = 1 and December = 12</strong>.
37+
* @param newYear : year of the events required by the view.
38+
* @param newMonth : month of the events required by the view <br/><strong>1 based (not like JAVA API) --> January = 1 and December = 12</strong>.
3939
* @return a list of the events happening <strong>during the specified month</strong>.
4040
*/
41-
List<WeekViewEvent> onMonthChange(int newYear, int newMonth);
41+
List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth);
4242
}
4343
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public class WeekView extends View {
7373
private Paint mEventBackgroundPaint;
7474
private float mHeaderColumnWidth;
7575
private List<EventRect> mEventRects;
76-
private List<WeekViewEvent> mPreviousPeriodEvents;
77-
private List<WeekViewEvent> mCurrentPeriodEvents;
78-
private List<WeekViewEvent> mNextPeriodEvents;
76+
private List<? extends WeekViewEvent> mPreviousPeriodEvents;
77+
private List<? extends WeekViewEvent> mCurrentPeriodEvents;
78+
private List<? extends WeekViewEvent> mNextPeriodEvents;
7979
private TextPaint mEventTextPaint;
8080
private Paint mHeaderColumnBackgroundPaint;
8181
private int mFetchedPeriod = -1; // the middle period the calendar has fetched.
@@ -853,9 +853,9 @@ private void getMoreEvents(Calendar day) {
853853
if (mWeekViewLoader != null){
854854
int periodToFetch = (int) mWeekViewLoader.toWeekViewPeriodIndex(day);
855855
if (!isInEditMode() && (mFetchedPeriod < 0 || mFetchedPeriod != periodToFetch || mRefreshEvents)) {
856-
List<WeekViewEvent> previousPeriodEvents = null;
857-
List<WeekViewEvent> currentPeriodEvents = null;
858-
List<WeekViewEvent> nextPeriodEvents = null;
856+
List<? extends WeekViewEvent> previousPeriodEvents = null;
857+
List<? extends WeekViewEvent> currentPeriodEvents = null;
858+
List<? extends WeekViewEvent> nextPeriodEvents = null;
859859

860860
if (mPreviousPeriodEvents != null && mCurrentPeriodEvents != null && mNextPeriodEvents != null){
861861
if (periodToFetch == mFetchedPeriod-1){
@@ -971,7 +971,7 @@ private void cacheEvent(WeekViewEvent event) {
971971
* Sort and cache events.
972972
* @param events The events to be sorted and cached.
973973
*/
974-
private void sortAndCacheEvents(List<WeekViewEvent> events) {
974+
private void sortAndCacheEvents(List<? extends WeekViewEvent> events) {
975975
sortEvents(events);
976976
for (WeekViewEvent event : events) {
977977
cacheEvent(event);
@@ -982,7 +982,7 @@ private void sortAndCacheEvents(List<WeekViewEvent> events) {
982982
* Sorts the events in ascending order.
983983
* @param events The events to be sorted.
984984
*/
985-
private void sortEvents(List<WeekViewEvent> events) {
985+
private void sortEvents(List<? extends WeekViewEvent> events) {
986986
Collections.sort(events, new Comparator<WeekViewEvent>() {
987987
@Override
988988
public int compare(WeekViewEvent event1, WeekViewEvent event2) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ public interface WeekViewLoader {
2020
* @param periodIndex the period to load
2121
* @return A list with the events of this period
2222
*/
23-
List<WeekViewEvent> onLoad(int periodIndex);
23+
List<? extends WeekViewEvent> onLoad(int periodIndex);
2424
}

0 commit comments

Comments
 (0)