From c343735b5755e772eb5acfcb2b4df731b0171c6b Mon Sep 17 00:00:00 2001 From: Seil0 Date: Tue, 18 Feb 2020 15:18:36 +0100 Subject: [PATCH] fix crash on first startup --- .../projectlaogai/controller/CacheController.kt | 16 +++++----------- .../projectlaogai/fragments/HomeFragment.kt | 5 +---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/controller/CacheController.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/controller/CacheController.kt index ad9b047..2ad54b1 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/controller/CacheController.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/controller/CacheController.kt @@ -28,10 +28,7 @@ import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.JsonParser import com.google.gson.reflect.TypeToken -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.joinAll -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.cCourse import org.mosad.seil0.projectlaogai.hsoparser.Course import org.mosad.seil0.projectlaogai.hsoparser.MensaMenu @@ -111,7 +108,7 @@ class CacheController(cont: Context) { // make sure the file exists if (!file.exists()) - GlobalScope.launch(Dispatchers.Default) { TCoRAPIController.getCoursesList(context).join() } + runBlocking { TCoRAPIController.getCoursesList(context).join() } val fileReader = FileReader(file) val bufferedReader = BufferedReader(fileReader) @@ -132,7 +129,7 @@ class CacheController(cont: Context) { // make sure the file exists if (!file.exists()) - GlobalScope.launch(Dispatchers.Default) { TCoRAPIController.getMensa(context).join() } + runBlocking { TCoRAPIController.getMensa(context).join() } val fileReader = FileReader(file) val bufferedReader = BufferedReader(fileReader) @@ -150,11 +147,8 @@ class CacheController(cont: Context) { val file = File(context.filesDir, "timetable-$courseName-$week.json") // make sure the file exists - if (!file.exists()) { - GlobalScope.launch(Dispatchers.Default) { - TCoRAPIController.getTimetable(courseName, week, context).join() - } - } + if (!file.exists()) + runBlocking { TCoRAPIController.getTimetable(courseName, week, context).join() } val fileReader = FileReader(file) val bufferedReader = BufferedReader(fileReader) diff --git a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt index e58b8de..bfd233a 100644 --- a/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt +++ b/app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt @@ -31,10 +31,7 @@ import android.view.ViewGroup import android.widget.TextView import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_home.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext +import kotlinx.coroutines.* import org.mosad.seil0.projectlaogai.R import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaMenu import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.timetables