Solved Application Not Responding when downloading map

This commit is contained in:
Yair Morgenstern 2019-12-17 20:39:46 +02:00
parent fc4eb01be8
commit e82cdd42fa

View file

@ -1,5 +1,6 @@
package com.unciv.ui.mapeditor package com.unciv.ui.mapeditor
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
@ -10,6 +11,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.DropBox import com.unciv.ui.worldscreen.optionstable.DropBox
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.worldscreen.optionstable.PopupTable
import kotlin.concurrent.thread
class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) { class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) {
init { init {
@ -20,17 +22,25 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen)
for (downloadableMap in folderList.entries) { for (downloadableMap in folderList.entries) {
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin) val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
downloadMapButton.onClick { downloadMapButton.onClick {
try{ thread {
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display) try {
val decodedMapJson = Gzip.unzip(mapJsonGzipped) val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
val mapObject = MapSaver().mapFromJson(decodedMapJson) val decodedMapJson = Gzip.unzip(mapJsonGzipped)
MapSaver().saveMap(downloadableMap.name, mapObject) val mapObject = MapSaver().mapFromJson(decodedMapJson)
UncivGame.Current.setScreen(MapEditorScreen(mapObject)) MapSaver().saveMap(downloadableMap.name, mapObject)
}
catch(ex:Exception){ // creating a screen is a GL task
val couldNotDownloadMapPopup = PopupTable(screen) Gdx.app.postRunnable { UncivGame.Current.setScreen(MapEditorScreen(mapObject)) }
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row() } catch (ex: Exception) {
couldNotDownloadMapPopup.addCloseButton() print(ex)
// Yes, even creating popups.
Gdx.app.postRunnable {
val couldNotDownloadMapPopup = PopupTable(screen)
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
couldNotDownloadMapPopup.addCloseButton()
}
}
} }
} }
scrollableMapTable.add(downloadMapButton).row() scrollableMapTable.add(downloadMapButton).row()