fix a glitch at updating synced events
This commit is contained in:
parent
669a931224
commit
0c1c752260
|
@ -136,6 +136,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
|
||||
val addHours = if (intent.getBooleanExtra(NEW_EVENT_SET_HOUR_DURATION, false)) 1 else 0
|
||||
mEventEndDateTime = mEventStartDateTime.plusHours(addHours)
|
||||
mEventCalendarId = config.lastUsedCaldavCalendar
|
||||
}
|
||||
|
||||
private fun showReminder1Dialog() {
|
||||
|
|
|
@ -76,7 +76,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
|||
|
||||
mCalendar.apply {
|
||||
mTargetDate = Formatter.getDateTimeFromCode(mDayCode)
|
||||
getDays() // prefill the screen asap, even if without events
|
||||
getDays(false) // prefill the screen asap, even if without events
|
||||
}
|
||||
updateCalendar()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
|
||||
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
||||
private var mEvents = ArrayList<Event>()
|
||||
private var days = ArrayList<DayMonthly>(DAYS_CNT)
|
||||
private var mFilterEventTypes = true
|
||||
|
||||
lateinit var mTargetDate: DateTime
|
||||
|
@ -34,55 +33,53 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
}
|
||||
|
||||
fun getMonth(targetDate: DateTime) {
|
||||
days.clear()
|
||||
updateMonthlyCalendar(targetDate)
|
||||
}
|
||||
|
||||
fun getDays() {
|
||||
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
|
||||
fun getDays(markDaysWithEvents: Boolean) {
|
||||
val days = ArrayList<DayMonthly>(DAYS_CNT)
|
||||
val currMonthDays = mTargetDate.dayOfMonth().maximumValue
|
||||
var firstDayIndex = mTargetDate.withDayOfMonth(1).dayOfWeek
|
||||
if (!mContext.config.isSundayFirst)
|
||||
firstDayIndex -= 1
|
||||
val prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().maximumValue
|
||||
|
||||
var isThisMonth = false
|
||||
var isToday: Boolean
|
||||
var value = prevMonthDays - firstDayIndex + 1
|
||||
var curDay: DateTime = mTargetDate
|
||||
var isThisMonth = false
|
||||
var isToday: Boolean
|
||||
var value = prevMonthDays - firstDayIndex + 1
|
||||
var curDay: DateTime = mTargetDate
|
||||
|
||||
for (i in 0 until DAYS_CNT) {
|
||||
when {
|
||||
i < firstDayIndex -> {
|
||||
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) {
|
||||
when {
|
||||
i < firstDayIndex -> {
|
||||
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)
|
||||
}
|
||||
|
||||
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++
|
||||
}
|
||||
|
||||
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++
|
||||
}
|
||||
|
||||
if (mEvents.isEmpty()) {
|
||||
mCallback.updateMonthlyCalendar(monthName, days)
|
||||
} else {
|
||||
if (markDaysWithEvents) {
|
||||
markDaysWithEvents(days)
|
||||
} else {
|
||||
mCallback.updateMonthlyCalendar(monthName, days)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,11 +130,12 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
}
|
||||
|
||||
private fun gotEvents(events: ArrayList<Event>) {
|
||||
mEvents = if (mFilterEventTypes)
|
||||
mEvents = if (mFilterEventTypes) {
|
||||
mContext.getFilteredEvents(events) as ArrayList<Event>
|
||||
else
|
||||
} else {
|
||||
events
|
||||
}
|
||||
|
||||
getDays()
|
||||
getDays(true)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue