add a check to avoid crash when data is loaded too late

This commit is contained in:
tibbi 2017-01-22 16:59:27 +01:00
parent c1a2051f8c
commit 6151604759

View file

@ -31,6 +31,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var mRowHeight = 0 private var mRowHeight = 0
private var minScrollY = -1 private var minScrollY = -1
private var maxScrollY = -1 private var maxScrollY = -1
private var mWasDestroyed = false
lateinit var mView: View lateinit var mView: View
lateinit var mCalendar: WeeklyCalendarImpl lateinit var mCalendar: WeeklyCalendarImpl
lateinit var mRes: Resources lateinit var mRes: Resources
@ -128,6 +129,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
} }
override fun updateWeeklyCalendar(events: List<Event>) { override fun updateWeeklyCalendar(events: List<Event>) {
if (mWasDestroyed)
return
val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height) val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height)
val minuteHeight = fullHeight / (24 * 60) val minuteHeight = fullHeight / (24 * 60)
val minimalHeight = mRes.getDimension(R.dimen.weekly_view_minimal_event_height).toInt() val minimalHeight = mRes.getDimension(R.dimen.weekly_view_minimal_event_height).toInt()
@ -168,6 +172,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
} }
} }
override fun onDestroyView() {
super.onDestroyView()
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 RelativeLayout
fun setListener(listener: WeekScrollListener) { fun setListener(listener: WeekScrollListener) {