forked from Quivr/Android-Week-View
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMonthLoader.kt
More file actions
30 lines (25 loc) · 1.35 KB
/
MonthLoader.kt
File metadata and controls
30 lines (25 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.alamkanak.weekview
import java.util.*
class MonthLoader(var onMonthChangeListener: MonthChangeListener?) : WeekViewLoader {
override fun toWeekViewPeriodIndex(instance: Calendar): Double {
return (instance.get(Calendar.YEAR) * 12).toDouble() + instance.get(Calendar.MONTH).toDouble() + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0
}
override fun onLoad(periodIndex: Int): MutableList<out WeekViewEvent>? {
return onMonthChangeListener!!.onMonthChange(periodIndex / 12, periodIndex % 12 + 1)
}
interface MonthChangeListener {
/**
*
* Very important interface, it's the base to load events in the calendar.
* 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.
* **That's why you can have three times the same event at the same place if you mess up with the configuration**
*
* @param newYear : year of the events required by the view.
* @param newMonth :
*
*month of the events required by the view **1 based (not like JAVA API) : January = 1 and December = 12**.
* @return a list of the events happening **during the specified month**.
*/
fun onMonthChange(newYear: Int, newMonth: Int): MutableList<out WeekViewEvent>?
}
}