Unverified Commit d9f9adb6 authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge branch 'develop' into patch-5

parents 7504c46b 8b7da88d
...@@ -23,13 +23,14 @@ import java.sql.Timestamp ...@@ -23,13 +23,14 @@ import java.sql.Timestamp
* Created by Filipe de Lima Brito (filipedelimabrito@gmail.com) on 9/22/17. * Created by Filipe de Lima Brito (filipedelimabrito@gmail.com) on 9/22/17.
*/ */
class RoomListPresenter(val context: Context, val view: RoomListContract.View) : RoomListContract.Presenter { class RoomListPresenter(val context: Context, val view: RoomListContract.View) : RoomListContract.Presenter {
private lateinit var TAG: String
override fun requestPinnedMessages(roomId: String, override fun requestPinnedMessages(roomId: String,
roomType: String, roomType: String,
hostname: String, hostname: String,
token: String, token: String,
userId: String, userId: String,
offset: Int) { offset: Int) {
TAG = "pinned"
view.showWaitingView(true) view.showWaitingView(true)
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForPinnedMessages(roomId, .newCall(RestApiHelper.getRequestForPinnedMessages(roomId,
...@@ -53,7 +54,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -53,7 +54,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
if (response.isSuccessful) { if (response.isSuccessful) {
val result = response.body()?.string() val result = response.body()?.string()
if (result != null) { if (result != null) {
handleMessagesJson(result, true) handleMessagesJson(result, true, TAG)
} }
} else { } else {
showErrorMessage(response.message()) showErrorMessage(response.message())
...@@ -68,6 +69,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -68,6 +69,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
token: String, token: String,
userId: String, userId: String,
offset: Int) { offset: Int) {
TAG = "favorite"
view.showWaitingView(true) view.showWaitingView(true)
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForFavoriteMessages(roomId, .newCall(RestApiHelper.getRequestForFavoriteMessages(roomId,
...@@ -91,7 +93,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -91,7 +93,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
if (response.isSuccessful) { if (response.isSuccessful) {
val result = response.body()?.string() val result = response.body()?.string()
if (result != null) { if (result != null) {
handleMessagesJson(result, false) handleMessagesJson(result, false, TAG)
} }
} else { } else {
showErrorMessage(response.message()) showErrorMessage(response.message())
...@@ -180,7 +182,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -180,7 +182,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
OkHttpHelper.getClient().dispatcher().cancelAll() OkHttpHelper.getClient().dispatcher().cancelAll()
} }
private fun handleMessagesJson(json: String, isPinnedMessage: Boolean) { private fun handleMessagesJson(json: String, isPinnedMessage: Boolean, TAG: String) {
try { try {
val jSONObject = JSONObject(json) val jSONObject = JSONObject(json)
val messagesJSONArray = jSONObject.getJSONArray("messages") val messagesJSONArray = jSONObject.getJSONArray("messages")
...@@ -204,7 +206,10 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) : ...@@ -204,7 +206,10 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
} }
if (dataSet.isEmpty() && !hasItem) { if (dataSet.isEmpty() && !hasItem) {
if (TAG.equals("favorite"))
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 if (TAG.equals("pinned"))
showEmptyViewMessage(context.getString(R.string.fragment_room_list_no_pinned_message_to_show))
} else { } else {
if (dataSet.isNotEmpty()) { if (dataSet.isNotEmpty()) {
hasItem = true hasItem = true
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
<string name="fragment_room_list_file_list_title">File list (%s)</string> <string name="fragment_room_list_file_list_title">File list (%s)</string>
<string name="fragment_room_list_member_list_title">Member list (%s)</string> <string name="fragment_room_list_member_list_title">Member list (%s)</string>
<string name="fragment_room_list_could_not_load_your_request">Could not load your request.\n%s.</string> <string name="fragment_room_list_could_not_load_your_request">Could not load your request.\n%s.</string>
<string name="fragment_room_list_no_pinned_message_to_show">No pinned message to show</string> <string name="fragment_room_list_no_pinned_message_to_show">No pinned messages to show</string>
<string name="fragment_room_list_no_favorite_message_to_show">No favorite message to show</string> <string name="fragment_room_list_no_favorite_message_to_show">No favorite messages to show</string>
<string name="fragment_room_list_no_file_list_to_show">No file list to show</string> <string name="fragment_room_list_no_file_list_to_show">No file list to show</string>
<string name="fragment_room_list_no_member_list_to_show">No member list to show</string> <string name="fragment_room_list_no_member_list_to_show">No member list to show</string>
......
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