This commit is contained in:
Yair Morgenstern 2020-08-05 21:52:48 +03:00
commit 73cd231f5b
2 changed files with 17 additions and 3 deletions

View file

@ -49,7 +49,7 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
val folderList = DropBox.getFolderList("/Maps") val folderList = DropBox.getFolderList("/Maps")
Gdx.app.postRunnable { Gdx.app.postRunnable {
scrollableMapTable.apply { defaults().pad(10f) } scrollableMapTable.apply { defaults().pad(10f) }
for (downloadableMap in folderList.entries) { for (downloadableMap in folderList) {
val downloadMapButton = downloadableMap.name.toTextButton() val downloadMapButton = downloadableMap.name.toTextButton()
listOfMaps.add(downloadMapButton) listOfMaps.add(downloadMapButton)
downloadMapButton.onClick { downloadMapButton.onClick {

View file

@ -45,10 +45,22 @@ object DropBox {
} }
} }
fun getFolderList(folder:String):FolderList{ fun getFolderList(folder:String): ArrayList<FolderListEntry> {
val folderList = ArrayList<FolderListEntry>()
// The DropBox API returns only partial file listings from one request. list_folder and
// list_folder/continue return similar responses, but list_folder/continue requires a cursor
// instead of the path.
val response = dropboxApi("https://api.dropboxapi.com/2/files/list_folder", val response = dropboxApi("https://api.dropboxapi.com/2/files/list_folder",
"{\"path\":\"$folder\"}","application/json") "{\"path\":\"$folder\"}","application/json")
return GameSaver.json().fromJson(FolderList::class.java,response) var currentFolderListChunk = GameSaver.json().fromJson(FolderList::class.java, response)
folderList.addAll(currentFolderListChunk.entries)
while (currentFolderListChunk.has_more) {
val continuationResponse = dropboxApi("https://api.dropboxapi.com/2/files/list_folder/continue",
"{\"cursor\":\"${currentFolderListChunk.cursor}\"}","application/json")
currentFolderListChunk = GameSaver.json().fromJson(FolderList::class.java, continuationResponse)
folderList.addAll(currentFolderListChunk.entries)
}
return folderList
} }
fun downloadFile(fileName:String): InputStream { fun downloadFile(fileName:String): InputStream {
@ -84,6 +96,8 @@ object DropBox {
class FolderList{ class FolderList{
var entries = ArrayList<FolderListEntry>() var entries = ArrayList<FolderListEntry>()
var cursor = ""
var has_more = false
} }
class FolderListEntry{ class FolderListEntry{