From 6c1c1e38fd07a4706e760dd2d7a18b5ca1021b97 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Feb 2017 11:44:04 +0100 Subject: [PATCH] fix a crash at long events if sunday is the first day --- .../simplemobiletools/calendar/fragments/WeekFragment.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index aa4d1fb37..1c363d03f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -277,7 +277,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { val minTS = Math.max(startDateTime.withTimeAtStartOfDay().seconds(), mWeekTimestamp) val maxTS = Math.min(endDateTime.withTimeAtStartOfDay().seconds(), mWeekTimestamp + context.secondsInWeek) val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS) - val firstDayIndex = startDateTimeInWeek.dayOfWeek - if (context.config.isSundayFirst) 0 else 1 + val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (context.config.isSundayFirst) 0 else 1) % 7 val daysCnt = Days.daysBetween(Formatter.getDateTimeFromTS(minTS), Formatter.getDateTimeFromTS(maxTS)).days activity.runOnUiThread { @@ -286,7 +286,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt() leftMargin = getColumnWithId(firstDayIndex).x.toInt() bottomMargin = 1 - width = getColumnWithId(firstDayIndex + daysCnt).right - leftMargin - 1 + width = getColumnWithId(Math.min(firstDayIndex + daysCnt, 6)).right - leftMargin - 1 } mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { @@ -317,7 +317,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { mWasDestroyed = true } - private fun getColumnWithId(id: Int) = mView.findViewById(mRes.getIdentifier("week_column_$id", "id", context.packageName)) as RelativeLayout + private fun getColumnWithId(id: Int) = mView.findViewById(mRes.getIdentifier("week_column_$id", "id", context.packageName)) as ViewGroup fun setListener(listener: WeekScrollListener) { mListener = listener