|
1 |
| -package com.alamkanak.weekview; |
2 |
| - |
3 |
| -import java.util.Calendar; |
4 |
| -import java.util.List; |
5 |
| - |
6 |
| -public class MonthLoader implements WeekViewLoader { |
7 |
| - |
8 |
| - private MonthChangeListener mOnMonthChangeListener; |
9 |
| - |
10 |
| - public MonthLoader(MonthChangeListener listener) { |
11 |
| - this.mOnMonthChangeListener = listener; |
12 |
| - } |
13 |
| - |
14 |
| - @Override |
15 |
| - public double toWeekViewPeriodIndex(Calendar instance) { |
16 |
| - return instance.get(Calendar.YEAR) * 12 + instance.get(Calendar.MONTH) + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0; |
17 |
| - } |
18 |
| - |
19 |
| - @Override |
20 |
| - public List<? extends WeekViewEvent> onLoad(int periodIndex) { |
21 |
| - return mOnMonthChangeListener.onMonthChange(periodIndex / 12, periodIndex % 12 + 1); |
22 |
| - } |
23 |
| - |
24 |
| - public MonthChangeListener getOnMonthChangeListener() { |
25 |
| - return mOnMonthChangeListener; |
26 |
| - } |
27 |
| - |
28 |
| - public void setOnMonthChangeListener(MonthChangeListener onMonthChangeListener) { |
29 |
| - this.mOnMonthChangeListener = onMonthChangeListener; |
30 |
| - } |
31 |
| - |
32 |
| - public interface MonthChangeListener { |
33 |
| - /** |
34 |
| - * <p>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.</p> |
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 |
| - * |
38 |
| - * @param newYear : year of the events required by the view. |
39 |
| - * @param newMonth : <p>month of the events required by the view </p><strong>1 based (not like JAVA API) : January = 1 and December = 12</strong>. |
40 |
| - * @return a list of the events happening <strong>during the specified month</strong>. |
41 |
| - */ |
42 |
| - List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth); |
43 |
| - } |
44 |
| -} |
| 1 | +package com.alamkanak.weekview |
| 2 | + |
| 3 | +import java.util.Calendar |
| 4 | + |
| 5 | +class MonthLoader(var onMonthChangeListener: MonthChangeListener?) : WeekViewLoader { |
| 6 | + |
| 7 | + override fun toWeekViewPeriodIndex(instance: Calendar): Double { |
| 8 | + return (instance.get(Calendar.YEAR) * 12).toDouble() + instance.get(Calendar.MONTH).toDouble() + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0 |
| 9 | + } |
| 10 | + |
| 11 | + override fun onLoad(periodIndex: Int): List<WeekViewEvent> { |
| 12 | + return onMonthChangeListener!!.onMonthChange(periodIndex / 12, periodIndex % 12 + 1) |
| 13 | + } |
| 14 | + |
| 15 | + interface MonthChangeListener { |
| 16 | + /** |
| 17 | + * |
| 18 | + * Very important interface, it's the base to load events in the calendar. |
| 19 | + * 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. |
| 20 | + * **That's why you can have three times the same event at the same place if you mess up with the configuration** |
| 21 | + * |
| 22 | + * @param newYear : year of the events required by the view. |
| 23 | + * @param newMonth : |
| 24 | + * |
| 25 | + *month of the events required by the view **1 based (not like JAVA API) : January = 1 and December = 12**. |
| 26 | + * @return a list of the events happening **during the specified month**. |
| 27 | + */ |
| 28 | + fun onMonthChange(newYear: Int, newMonth: Int): List<WeekViewEvent> |
| 29 | + } |
| 30 | +} |
0 commit comments