mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
optimize monthly layout drawing
This commit is contained in:
@ -18,6 +18,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
|
|
||||||
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
||||||
private var mEvents = ArrayList<Event>()
|
private var mEvents = ArrayList<Event>()
|
||||||
|
private var days = ArrayList<DayMonthly>(DAYS_CNT)
|
||||||
var mFilterEventTypes = true
|
var mFilterEventTypes = true
|
||||||
|
|
||||||
lateinit var mTargetDate: DateTime
|
lateinit var mTargetDate: DateTime
|
||||||
@ -37,47 +38,51 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getDays() {
|
fun getDays() {
|
||||||
val days = ArrayList<DayMonthly>(DAYS_CNT)
|
if (days.isEmpty()) {
|
||||||
|
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
||||||
|
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
||||||
|
if (!mContext.config.isSundayFirst)
|
||||||
|
firstDayIndex -= 1
|
||||||
|
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
||||||
|
|
||||||
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
var isThisMonth = false
|
||||||
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
var isToday: Boolean
|
||||||
if (!mContext.config.isSundayFirst)
|
var value = prevMonthDays - firstDayIndex + 1
|
||||||
firstDayIndex -= 1
|
var curDay: DateTime = mTargetDate
|
||||||
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
|
||||||
|
|
||||||
var isThisMonth = false
|
for (i in 0 until DAYS_CNT) {
|
||||||
var isToday: Boolean
|
when {
|
||||||
var value = prevMonthDays - firstDayIndex + 1
|
i < firstDayIndex -> {
|
||||||
var curDay: DateTime = mTargetDate
|
isThisMonth = false
|
||||||
|
curDay = mTargetDate.withDayOfMonth(1).minusMonths(1)
|
||||||
|
}
|
||||||
|
i == firstDayIndex -> {
|
||||||
|
value = 1
|
||||||
|
isThisMonth = true
|
||||||
|
curDay = mTargetDate
|
||||||
|
}
|
||||||
|
value == currMonthDays + 1 -> {
|
||||||
|
value = 1
|
||||||
|
isThisMonth = false
|
||||||
|
curDay = mTargetDate.withDayOfMonth(1).plusMonths(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i in 0 until DAYS_CNT) {
|
isToday = isThisMonth && isToday(mTargetDate, value)
|
||||||
when {
|
|
||||||
i < firstDayIndex -> {
|
val newDay = curDay.withDayOfMonth(value)
|
||||||
isThisMonth = false
|
val dayCode = Formatter.getDayCodeFromDateTime(newDay)
|
||||||
curDay = mTargetDate.withDayOfMonth(1).minusMonths(1)
|
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList())
|
||||||
}
|
days.add(day)
|
||||||
i == firstDayIndex -> {
|
value++
|
||||||
value = 1
|
|
||||||
isThisMonth = true
|
|
||||||
curDay = mTargetDate
|
|
||||||
}
|
|
||||||
value == currMonthDays + 1 -> {
|
|
||||||
value = 1
|
|
||||||
isThisMonth = false
|
|
||||||
curDay = mTargetDate.withDayOfMonth(1).plusMonths(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isToday = isThisMonth && isToday(mTargetDate, value)
|
|
||||||
|
|
||||||
val newDay = curDay.withDayOfMonth(value)
|
|
||||||
val dayCode = Formatter.getDayCodeFromDateTime(newDay)
|
|
||||||
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList())
|
|
||||||
days.add(day)
|
|
||||||
value++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markDaysWithEvents(days)
|
if (mEvents.isEmpty()) {
|
||||||
|
mCallback.updateMonthlyCalendar(monthName, days)
|
||||||
|
} else {
|
||||||
|
markDaysWithEvents(days)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// it works more often than not, dont touch
|
// it works more often than not, dont touch
|
||||||
|
Reference in New Issue
Block a user