From 12e09bdb73c8327f93efabe1399165c614fd7852 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 25 May 2020 20:56:14 +0200 Subject: [PATCH] adding some crashfixes --- .../pro/adapters/EventListWidgetAdapter.kt | 5 ++++- .../calendar/pro/fragments/WeekFragment.kt | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt index f71657f69..50ff6beed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt @@ -48,7 +48,10 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi setupListEvent(remoteView, event) } else { remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget) - setupListSection(remoteView, events[position] as ListSection) + val section = events.getOrNull(position) as? ListSection + if (section != null) { + setupListSection(remoteView, section) + } } return remoteView diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt index 01aa3237b..1c1280f56 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt @@ -164,7 +164,9 @@ class WeekFragment : Fragment(), WeeklyCalendar { } fun updateCalendar() { - WeeklyCalendarImpl(this, context!!).updateWeeklyCalendar(weekTimestamp) + if (context != null) { + WeeklyCalendarImpl(this, context!!).updateWeeklyCalendar(weekTimestamp) + } } private fun setupDayLabels() { @@ -195,15 +197,15 @@ class WeekFragment : Fragment(), WeeklyCalendar { private fun initGrid() { (0..6).map { getColumnWithId(it) } - .forEachIndexed { index, layout -> - layout.removeAllViews() - val gestureDetector = getViewGestureDetector(layout, index) + .forEachIndexed { index, layout -> + layout.removeAllViews() + val gestureDetector = getViewGestureDetector(layout, index) - layout.setOnTouchListener { view, motionEvent -> - gestureDetector.onTouchEvent(motionEvent) - true - } + layout.setOnTouchListener { view, motionEvent -> + gestureDetector.onTouchEvent(motionEvent) + true } + } } private fun getViewGestureDetector(view: ViewGroup, index: Int): GestureDetector { @@ -294,7 +296,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { if (context != null && activity != null && isAdded) { val replaceDescription = config.replaceDescription val sorted = events.sortedWith( - compareBy { it.startTS }.thenBy { it.endTS }.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description } + compareBy { it.startTS }.thenBy { it.endTS }.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description } ).toMutableList() as ArrayList currEvents = sorted