Commit 28da0cb6 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RoomDialogPresenter.kt

parent 8b4f5e32
package chat.rocket.android.fragment.chatroom.dialog package chat.rocket.android.fragment.chatroom.dialog
import android.content.Context import android.content.Context
import android.os.Handler
import android.util.Log import android.util.Log
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.helper.OkHttpHelper import chat.rocket.android.helper.OkHttpHelper
...@@ -13,6 +14,8 @@ import org.json.JSONObject ...@@ -13,6 +14,8 @@ import org.json.JSONObject
class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.View): RoomDialogContract.Presenter { class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.View): RoomDialogContract.Presenter {
val mainHandler = Handler(context.mainLooper)
override fun getDataSet(roomId: String, override fun getDataSet(roomId: String,
roomName: String, roomName: String,
roomType: String, roomType: String,
...@@ -90,14 +93,24 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie ...@@ -90,14 +93,24 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) { if (response.isSuccessful) {
val jSONObject = JSONObject(response.body()?.string()) val jSONObject = JSONObject(response.body()?.string())
Log.i("REST", " = " + jSONObject.toString())
Log.i("REST", " = " + jSONObject)
val filesJSONArray = jSONObject.get("files") as JSONArray val filesJSONArray = jSONObject.get("files") as JSONArray
val total = filesJSONArray.length() val filesJSONArrayLength = filesJSONArray.length()
val dataSet = ArrayList<String>(total) val amazonS3JSONArray = JSONArray()
(0 until total).mapTo(dataSet) { filesJSONArray.get(it).toString() } for (i in 0 until filesJSONArrayLength) {
view.showFileList(dataSet) amazonS3JSONArray.put(filesJSONArray.getJSONObject(i).get("AmazonS3"))
}
val pathJSONArray = JSONArray()
val amazonS3JSONArrayLength = amazonS3JSONArray.length()
for (i in 0 until amazonS3JSONArrayLength) {
pathJSONArray.put(amazonS3JSONArray.getJSONObject(i).get("path"))
}
val pathJSONArrayLength = pathJSONArray.length()
val dataSet = ArrayList<String>(pathJSONArrayLength)
(0 until pathJSONArrayLength).mapTo(dataSet) { pathJSONArray.get(it).toString() }
mainHandler.post { view.showFileList(dataSet) }
} else { } else {
// TODO("move to strings.xml") // TODO("move to strings.xml")
view.showMessage("Response is not successful") view.showMessage("Response is not successful")
...@@ -133,7 +146,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie ...@@ -133,7 +146,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
val dataSet = ArrayList<String>(total) val dataSet = ArrayList<String>(total)
(0 until total).mapTo(dataSet) { membersJSONArray.get(it).toString() } (0 until total).mapTo(dataSet) { membersJSONArray.get(it).toString() }
view.showMemberList(dataSet) mainHandler.post { view.showMemberList(dataSet) }
} else { } else {
// TODO("move to strings.xml") // TODO("move to strings.xml")
view.showMessage("Response is not successful") view.showMessage("Response is not successful")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment