Skip to content

Commit 724646f

Browse files
committed
Update week view loader
1 parent c265c9d commit 724646f

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ Interfaces
132132

133133
Use the following interfaces according to your need.
134134

135-
- `mWeekView.setMonthChangeListener()` to provide events to the calendar
135+
- `mWeekView.setWeekViewLoader()` to provide events to the calendar
136+
- `mWeekView.setMonthChangeListener()` to provide events to the calendar by months
136137
- `mWeekView.setOnEventClickListener()` to get a callback when an event is clicked
137138
- `mWeekView.setEventLongPressListener()` to get a callback when an event is long pressed
138139
- `mWeekView.setEmptyViewClickListener()` to get a callback when any empty space is clicked

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,39 @@
55

66
public class MonthLoader implements WeekViewLoader {
77

8-
private WeekView.MonthChangeListener mOnMonthChangeListener;
9-
public MonthLoader(WeekView.MonthChangeListener listener){
8+
private MonthChangeListener mOnMonthChangeListener;
9+
10+
public MonthLoader(MonthChangeListener listener){
1011
this.mOnMonthChangeListener = listener;
1112
}
1213

1314
@Override
1415
public double toWeekViewPeriodIndex(Calendar instance){
15-
return instance.get(Calendar.YEAR)*12 + instance.get(Calendar.MONTH) + (instance.get(Calendar.DAY_OF_MONTH)-1)/30.0;
16+
return instance.get(Calendar.YEAR) * 12 + instance.get(Calendar.MONTH) + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0;
1617
}
1718

1819
@Override
1920
public List<WeekViewEvent> onLoad(int periodIndex){
20-
return mOnMonthChangeListener.onMonthChange(periodIndex/12,periodIndex%12+1);
21+
return mOnMonthChangeListener.onMonthChange(periodIndex / 12, periodIndex % 12 + 1);
2122
}
2223

23-
24-
public WeekView.MonthChangeListener getOnMonthChangeListener() {
24+
public MonthChangeListener getOnMonthChangeListener() {
2525
return mOnMonthChangeListener;
2626
}
2727

28-
public void setOnMonthChangeListener(WeekView.MonthChangeListener onMonthChangeListener) {
28+
public void setOnMonthChangeListener(MonthChangeListener onMonthChangeListener) {
2929
this.mOnMonthChangeListener = onMonthChangeListener;
3030
}
31+
32+
public interface MonthChangeListener {
33+
/**
34+
* Very important interface, it's the base to load events in the calendar.
35+
* 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/>
36+
* <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>.
39+
* @return a list of the events happening <strong>during the specified month</strong>.
40+
*/
41+
List<WeekViewEvent> onMonthChange(int newYear, int newMonth);
42+
}
3143
}

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.Rect;
1010
import android.graphics.RectF;
1111
import android.graphics.Typeface;
12+
import android.support.annotation.Nullable;
1213
import android.support.v4.view.GestureDetectorCompat;
1314
import android.support.v4.view.ViewCompat;
1415
import android.text.Layout;
@@ -1119,20 +1120,32 @@ public EventClickListener getEventClickListener() {
11191120
return mEventClickListener;
11201121
}
11211122

1122-
public MonthChangeListener getMonthChangeListener() {
1123+
public @Nullable MonthLoader.MonthChangeListener getMonthChangeListener() {
11231124
if (mWeekViewLoader instanceof MonthLoader)
11241125
return ((MonthLoader) mWeekViewLoader).getOnMonthChangeListener();
11251126
return null;
11261127
}
11271128

1128-
public void setMonthChangeListener(MonthChangeListener monthChangeListener) {
1129+
public void setMonthChangeListener(MonthLoader.MonthChangeListener monthChangeListener) {
11291130
this.mWeekViewLoader = new MonthLoader(monthChangeListener);
11301131
}
11311132

1133+
/**
1134+
* Get event loader in the week view. Event loaders define the interval after which the events
1135+
* are loaded in week view. For a MonthLoader events are loaded for every month. You can define
1136+
* your custom event loader by extending WeekViewLoader.
1137+
* @return The event loader.
1138+
*/
11321139
public WeekViewLoader getWeekViewLoader(){
11331140
return mWeekViewLoader;
11341141
}
11351142

1143+
/**
1144+
* Set event loader in the week view. For example, a MonthLoader. Event loaders define the
1145+
* interval after which the events are loaded in week view. For a MonthLoader events are loaded
1146+
* for every month. You can define your custom event loader by extending WeekViewLoader.
1147+
* @param loader The event loader.
1148+
*/
11361149
public void setWeekViewLoader(WeekViewLoader loader){
11371150
this.mWeekViewLoader = loader;
11381151
}
@@ -1772,18 +1785,6 @@ public interface EventClickListener {
17721785
void onEventClick(WeekViewEvent event, RectF eventRect);
17731786
}
17741787

1775-
public interface MonthChangeListener {
1776-
/**
1777-
* Very important interface, it's the base to load events in the calendar.
1778-
* 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/>
1779-
* <strong>That's why you can have three times the same event at the same place if you mess up with the configuration</strong>
1780-
* @param newYear: year of the events required by the view.
1781-
* @param newMonth: month of the events required by the view <br/><strong>1 based (not like JAVA API) --> January = 1 and December = 12</strong>.
1782-
* @return a list of the events happening <strong>during the specified month</strong>.
1783-
*/
1784-
List<WeekViewEvent> onMonthChange(int newYear, int newMonth);
1785-
}
1786-
17871788
public interface EventLongPressListener {
17881789
/**
17891790
* Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ public interface WeekViewLoader {
77
/**
88
* Convert a date into a double that will be used to reference when you're loading data.
99
*
10-
* All periods that have the same integer part, define one period. Dates that are later in time should have a greater return value.
10+
* All periods that have the same integer part, define one period. Dates that are later in time
11+
* should have a greater return value.
1112
*
1213
* @param instance the date
1314
* @return The period index in which the date falls (floating point number).
1415
*/
15-
public double toWeekViewPeriodIndex(Calendar instance);
16+
double toWeekViewPeriodIndex(Calendar instance);
1617

1718
/**
1819
* Load the events within the period
1920
* @param periodIndex the period to load
2021
* @return A list with the events of this period
2122
*/
22-
public List<WeekViewEvent> onLoad(int periodIndex);
23+
List<WeekViewEvent> onLoad(int periodIndex);
2324
}

sample/src/main/java/com/alamkanak/weekview/sample/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.widget.Toast;
1010

1111
import com.alamkanak.weekview.DateTimeInterpreter;
12+
import com.alamkanak.weekview.MonthLoader;
1213
import com.alamkanak.weekview.WeekView;
1314
import com.alamkanak.weekview.WeekViewEvent;
1415

@@ -23,7 +24,7 @@
2324
* Created by Raquib-ul-Alam Kanak on 7/21/2014.
2425
* Website: http://alamkanak.github.io/
2526
*/
26-
public class MainActivity extends ActionBarActivity implements WeekView.MonthChangeListener,
27+
public class MainActivity extends ActionBarActivity implements MonthLoader.MonthChangeListener,
2728
WeekView.EventClickListener, WeekView.EventLongPressListener {
2829

2930
private static final int TYPE_DAY_VIEW = 1;

0 commit comments

Comments
 (0)