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

Update RoomListPresenter.kt

parent a156dc67
...@@ -18,21 +18,23 @@ import org.json.JSONObject ...@@ -18,21 +18,23 @@ import org.json.JSONObject
import java.io.IOException import java.io.IOException
import java.sql.Timestamp import java.sql.Timestamp
class RoomListPresenter(val context: Context, val view: RoomListContract.View): RoomListContract.Presenter { class RoomListPresenter(val context: Context, val view: RoomListContract.View) : RoomListContract.Presenter {
val mainHandler = Handler(context.mainLooper) val mainHandler = Handler(context.mainLooper)
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: String) {
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForPinnedMessages(roomId, .newCall(RestApiHelper.getRequestForPinnedMessages(roomId,
roomType, roomType,
hostname, hostname,
token, token,
userId)) userId,
offset))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) } mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) }
...@@ -58,7 +60,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -58,7 +60,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
.build() .build()
val timestampString = messagesJSONArray.getJSONObject(it).optString("ts") val timestampString = messagesJSONArray.getJSONObject(it).optString("ts")
val timestamp = if (timestampString.isBlank()) { 0 } else { val timestamp = if (timestampString.isBlank()) {
0
} else {
Timestamp.valueOf(timestampString Timestamp.valueOf(timestampString
.replace("T", " ") .replace("T", " ")
.replace("Z", "")) .replace("Z", ""))
...@@ -66,7 +70,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -66,7 +70,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
} }
val editedAtString = messagesJSONArray.getJSONObject(it).optString("_updatedAt") val editedAtString = messagesJSONArray.getJSONObject(it).optString("_updatedAt")
val editedAt = if (editedAtString.isBlank()) { 0 } else { val editedAt = if (editedAtString.isBlank()) {
0
} else {
Timestamp.valueOf(editedAtString Timestamp.valueOf(editedAtString
.replace("T", " ") .replace("T", " ")
.replace("Z", "")) .replace("Z", ""))
...@@ -96,13 +102,15 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -96,13 +102,15 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
roomType: String, roomType: String,
hostname: String, hostname: String,
token: String, token: String,
userId: String) { userId: String,
offset: String) {
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForFavoriteMessages(roomId, .newCall(RestApiHelper.getRequestForFavoriteMessages(roomId,
roomType, roomType,
hostname, hostname,
token, token,
userId)) userId,
offset))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) } mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) }
...@@ -128,7 +136,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -128,7 +136,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
.build() .build()
val timestampString = messagesJSONArray.getJSONObject(it).optString("ts") val timestampString = messagesJSONArray.getJSONObject(it).optString("ts")
val timestamp = if (timestampString.isBlank()) { 0 } else { val timestamp = if (timestampString.isBlank()) {
0
} else {
Timestamp.valueOf(timestampString Timestamp.valueOf(timestampString
.replace("T", " ") .replace("T", " ")
.replace("Z", "")) .replace("Z", ""))
...@@ -136,7 +146,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -136,7 +146,9 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
} }
val editedAtString = messagesJSONArray.getJSONObject(it).optString("_updatedAt") val editedAtString = messagesJSONArray.getJSONObject(it).optString("_updatedAt")
val editedAt = if (editedAtString.isBlank()) { 0 } else { val editedAt = if (editedAtString.isBlank()) {
0
} else {
Timestamp.valueOf(editedAtString Timestamp.valueOf(editedAtString
.replace("T", " ") .replace("T", " ")
.replace("Z", "")) .replace("Z", ""))
...@@ -167,7 +179,8 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -167,7 +179,8 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
roomType: String, roomType: String,
hostname: String, hostname: String,
token: String, token: String,
userId: String) { userId: String,
offset: String) {
// OkHttpHelper.getClient() // OkHttpHelper.getClient()
// .newCall(RestApiHelper.getRequestForFileList(roomId, // .newCall(RestApiHelper.getRequestForFileList(roomId,
// roomType, // roomType,
...@@ -214,13 +227,16 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View): ...@@ -214,13 +227,16 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View):
roomType: String, roomType: String,
hostname: String, hostname: String,
token: String, token: String,
userId: String) { userId: String,
offset: String
) {
OkHttpHelper.getClient() OkHttpHelper.getClient()
.newCall(RestApiHelper.getRequestForMemberList(roomId, .newCall(RestApiHelper.getRequestForMemberList(roomId,
roomType, roomType,
hostname, hostname,
token, token,
userId)) userId,
offset))
.enqueue(object : Callback { .enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) } mainHandler.post { view.showMessage(context.getString(R.string.fragment_room_list_could_not_load_your_request, e.message)) }
......
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