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

Update RoomListPresenter.kt

parent f0b47aaf
...@@ -36,9 +36,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -36,9 +36,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
offset.toString())) offset.toString()))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
val message = e.message if (!call.isCanceled) {
if (message != null) { val message = e.message
showErrorMessage(message) if (message != null) {
showErrorMessage(message)
}
} }
} }
...@@ -72,9 +74,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -72,9 +74,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
offset.toString())) offset.toString()))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
val message = e.message if (!call.isCanceled) {
if (message != null) { val message = e.message
showErrorMessage(message) if (message != null) {
showErrorMessage(message)
}
} }
} }
...@@ -98,8 +102,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -98,8 +102,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
hostname: String, hostname: String,
token: String, token: String,
userId: String, userId: String,
offset: Int) { offset: Int) {}
}
override fun requestMemberList(roomId: String, override fun requestMemberList(roomId: String,
roomType: String, roomType: String,
...@@ -108,7 +111,6 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -108,7 +111,6 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
userId: String, userId: String,
offset: Int) { offset: Int) {
view.showWaitingView(true) view.showWaitingView(true)
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForMemberList(roomId, .newCall(RestApiHelper.getRequestForMemberList(roomId,
roomType, roomType,
...@@ -118,9 +120,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -118,9 +120,11 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
offset.toString())) offset.toString()))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
val message = e.message if (!call.isCanceled) {
if (message != null) { val message = e.message
showErrorMessage(message) if (message != null) {
showErrorMessage(message)
}
} }
} }
...@@ -138,6 +142,10 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -138,6 +142,10 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
}) })
} }
override fun cancelRequest() {
OkHttpHelper.getClient().dispatcher().cancelAll()
}
private fun handleMessagesJson(json: String, isPinnedMessage: Boolean) { private fun handleMessagesJson(json: String, isPinnedMessage: Boolean) {
val jSONObject = JSONObject(json) val jSONObject = JSONObject(json)
val messagesJSONArray = jSONObject.getJSONArray("messages") val messagesJSONArray = jSONObject.getJSONArray("messages")
...@@ -174,15 +182,15 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -174,15 +182,15 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
.build() .build()
} }
if (dataSet.isEmpty() && previousMessageDataSet.isEmpty()) { if (dataSet.isEmpty() && !hasItem) {
showEmptyViewMessage(context.getString(R.string.fragment_room_list_no_favorite_message_to_show)) showEmptyViewMessage(context.getString(R.string.fragment_room_list_no_favorite_message_to_show))
} else { } else {
if (dataSet.isNotEmpty()) { if (dataSet.isNotEmpty()) {
previousMessageDataSet += dataSet hasItem = true
if (isPinnedMessage) { if (isPinnedMessage) {
showPinnedMessageList(previousMessageDataSet as ArrayList<Message>, jSONObject.optString("total")) showPinnedMessageList(dataSet, jSONObject.optString("total"))
} else { } else {
showFavoriteMessageList(previousMessageDataSet as ArrayList<Message>, jSONObject.optString("total")) showFavoriteMessageList(dataSet, jSONObject.optString("total"))
} }
} }
} }
...@@ -198,12 +206,12 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -198,12 +206,12 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
getUserFromJsonObject(membersJsonArray.getJSONObject(it)) getUserFromJsonObject(membersJsonArray.getJSONObject(it))
} }
if (dataSet.isEmpty() && previousUserDataSet.isEmpty()) { if (dataSet.isEmpty() && !hasItem) {
showEmptyViewMessage(context.getString(R.string.fragment_room_list_no_member_list_to_show)) showEmptyViewMessage(context.getString(R.string.fragment_room_list_no_member_list_to_show))
} else { } else {
if (dataSet.isNotEmpty()) { if (dataSet.isNotEmpty()) {
previousUserDataSet += dataSet hasItem = true
showMemberList(previousUserDataSet as ArrayList<User>, jsonObject.optString("total")) showMemberList(dataSet, jsonObject.optString("total"))
} }
} }
} }
...@@ -254,6 +262,5 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -254,6 +262,5 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
} }
private val mainHandler = Handler(context.mainLooper) private val mainHandler = Handler(context.mainLooper)
private var previousMessageDataSet = emptyList<Message>() private var hasItem: Boolean = false
private var previousUserDataSet = emptyList<User>()
} }
\ No newline at end of file
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