Commit d675b1e8 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RoomListPresenter.kt

parent aa288e56
...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom.list ...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom.list
import android.content.Context import android.content.Context
import android.os.Handler import android.os.Handler
import android.util.Log
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.api.rest.RestApiHelper import chat.rocket.android.api.rest.RestApiHelper
import chat.rocket.android.helper.OkHttpHelper import chat.rocket.android.helper.OkHttpHelper
...@@ -11,6 +12,7 @@ import chat.rocket.core.models.User ...@@ -11,6 +12,7 @@ import chat.rocket.core.models.User
import okhttp3.Call import okhttp3.Call
import okhttp3.Callback import okhttp3.Callback
import okhttp3.Response import okhttp3.Response
import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.io.IOException import java.io.IOException
import java.sql.Timestamp import java.sql.Timestamp
...@@ -147,6 +149,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -147,6 +149,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
} }
private fun handleMessagesJson(json: String, isPinnedMessage: Boolean) { private fun handleMessagesJson(json: String, isPinnedMessage: Boolean) {
try {
val jSONObject = JSONObject(json) val jSONObject = JSONObject(json)
val messagesJSONArray = jSONObject.getJSONArray("messages") val messagesJSONArray = jSONObject.getJSONArray("messages")
...@@ -194,9 +197,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -194,9 +197,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
} }
} }
} }
} catch (exception: JSONException) {
showInvalidRequest()
}
} }
private fun handleMembersJson(json: String) { private fun handleMembersJson(json: String) {
try {
val jsonObject = JSONObject(json) val jsonObject = JSONObject(json)
val membersJsonArray = jsonObject.getJSONArray("members") val membersJsonArray = jsonObject.getJSONArray("members")
...@@ -214,6 +221,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -214,6 +221,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
showMemberList(dataSet, jsonObject.optString("total")) showMemberList(dataSet, jsonObject.optString("total"))
} }
} }
}catch (exception: JSONException) {
showInvalidRequest()
}
} }
private fun getUserFromJsonObject(jsonObject: JSONObject): User { private fun getUserFromJsonObject(jsonObject: JSONObject): User {
...@@ -247,6 +257,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -247,6 +257,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
} }
} }
private fun showInvalidRequest() {
mainHandler.post {
view.showWaitingView(false)
view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, context.getString(R.string.make_sure_your_server_version_is_up_to_date)))
}
}
private fun showEmptyViewMessage(message: String) { private fun showEmptyViewMessage(message: String) {
mainHandler.post { mainHandler.post {
view.showWaitingView(false) view.showWaitingView(false)
......
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