From 930813fb8a9270989b7375350c070916d096bd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 10 Mar 2020 20:25:14 +0100 Subject: [PATCH] [Agenda] Try to fix agenda fragment not attached crashes. --- .../edziennik/ui/modules/agenda/AgendaFragment.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt index ebe7e19e..bddd805a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt @@ -126,6 +126,8 @@ class AgendaFragment : Fragment(), CoroutineScope { } private fun createDefaultAgendaView() { (b as? FragmentAgendaDefaultBinding)?.let { b -> launch { + if (!isAdded) + return@launch delay(500) val eventList = mutableListOf() @@ -139,6 +141,8 @@ class AgendaFragment : Fragment(), CoroutineScope { /** * LESSON CHANGES */ + if (!isAdded) + return@launch val lessons = withContext(Dispatchers.Default) { app.db.timetableDao().getAllChangesNow(app.profileId) } val lessonChangeCounters = mutableListOf() @@ -170,6 +174,8 @@ class AgendaFragment : Fragment(), CoroutineScope { /** * TEACHER ABSENCES */ + if (!isAdded) + return@launch val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true) @@ -208,6 +214,8 @@ class AgendaFragment : Fragment(), CoroutineScope { /** * EVENTS */ + if (!isAdded) + return@launch val events = withContext(Dispatchers.Default) { app.db.eventDao().getAllNow(app.profileId) } val unreadEventDates = mutableSetOf()