[Agenda] Try to fix agenda fragment not attached crashes.

This commit is contained in:
Kuba Szczodrzyński 2020-03-10 20:25:14 +01:00
parent acd5e9b998
commit 930813fb8a

View File

@ -126,6 +126,8 @@ class AgendaFragment : Fragment(), CoroutineScope {
} }
private fun createDefaultAgendaView() { (b as? FragmentAgendaDefaultBinding)?.let { b -> launch { private fun createDefaultAgendaView() { (b as? FragmentAgendaDefaultBinding)?.let { b -> launch {
if (!isAdded)
return@launch
delay(500) delay(500)
val eventList = mutableListOf<CalendarEvent>() val eventList = mutableListOf<CalendarEvent>()
@ -139,6 +141,8 @@ class AgendaFragment : Fragment(), CoroutineScope {
/** /**
* LESSON CHANGES * LESSON CHANGES
*/ */
if (!isAdded)
return@launch
val lessons = withContext(Dispatchers.Default) { app.db.timetableDao().getAllChangesNow(app.profileId) } val lessons = withContext(Dispatchers.Default) { app.db.timetableDao().getAllChangesNow(app.profileId) }
val lessonChangeCounters = mutableListOf<LessonChangeCounter>() val lessonChangeCounters = mutableListOf<LessonChangeCounter>()
@ -170,6 +174,8 @@ class AgendaFragment : Fragment(), CoroutineScope {
/** /**
* TEACHER ABSENCES * TEACHER ABSENCES
*/ */
if (!isAdded)
return@launch
val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true) val showTeacherAbsences = app.profile.getStudentData("showTeacherAbsences", true)
@ -208,6 +214,8 @@ class AgendaFragment : Fragment(), CoroutineScope {
/** /**
* EVENTS * EVENTS
*/ */
if (!isAdded)
return@launch
val events = withContext(Dispatchers.Default) { app.db.eventDao().getAllNow(app.profileId) } val events = withContext(Dispatchers.Default) { app.db.eventDao().getAllNow(app.profileId) }
val unreadEventDates = mutableSetOf<Int>() val unreadEventDates = mutableSetOf<Int>()