mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 13:18:56 +07:00
Solved ANR when waiting for the list of maps
This commit is contained in:
@ -14,15 +14,34 @@ import com.unciv.ui.worldscreen.mainmenu.DropBox
|
|||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
|
class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
|
||||||
|
val contentTable = Table()
|
||||||
init {
|
init {
|
||||||
val folderList: DropBox.FolderList
|
thread(name="LoadMapList") { loadContent() }
|
||||||
|
add(contentTable).row()
|
||||||
|
addCloseButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadContent() {
|
||||||
try {
|
try {
|
||||||
folderList = DropBox().getFolderList("/Maps")
|
val folderList = DropBox().getFolderList("/Maps")
|
||||||
|
Gdx.app.postRunnable {
|
||||||
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
||||||
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 {
|
||||||
thread(name="MapDownload") {
|
thread(name = "MapDownload") { loadMap(downloadableMap) }
|
||||||
|
}
|
||||||
|
scrollableMapTable.add(downloadMapButton).row()
|
||||||
|
}
|
||||||
|
contentTable.add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
||||||
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
addGoodSizedLabel("Could not get list of maps!").row()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadMap(downloadableMap: DropBox.FolderListEntry) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||||
@ -44,12 +63,3 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scrollableMapTable.add(downloadMapButton).row()
|
|
||||||
}
|
|
||||||
add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
addGoodSizedLabel("Could not get list of maps!").row()
|
|
||||||
}
|
|
||||||
addCloseButton()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user