Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
6dfd2561
Commit
6dfd2561
authored
Sep 15, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RoomDialogPresenter.kt
parent
c1110705
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
12 deletions
+56
-12
RoomDialogPresenter.kt
...t/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
+56
-12
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/dialog/RoomDialogPresenter.kt
View file @
6dfd2561
...
@@ -5,12 +5,15 @@ import android.os.Handler
...
@@ -5,12 +5,15 @@ 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
import
chat.rocket.core.SyncState
import
chat.rocket.core.models.Message
import
chat.rocket.core.models.Room
import
chat.rocket.core.models.Room
import
chat.rocket.core.models.User
import
okhttp3.*
import
okhttp3.*
import
java.io.IOException
import
okhttp3.HttpUrl
import
org.json.JSONArray
import
org.json.JSONArray
import
org.json.JSONObject
import
org.json.JSONObject
import
java.io.IOException
import
java.sql.Timestamp
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
)
val
mainHandler
=
Handler
(
context
.
mainLooper
)
...
@@ -73,15 +76,56 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -73,15 +76,56 @@ 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
)
val
messagesJSONArray
=
jSONObject
.
get
(
"messages"
)
as
JSONArray
val
messagesJSONArrayLength
=
messagesJSONArray
.
length
()
val
dataSet
=
ArrayList
<
Message
>(
messagesJSONArrayLength
)
(
0
until
messagesJSONArrayLength
).
mapTo
(
dataSet
)
{
val
userJSONArray
=
JSONArray
()
userJSONArray
.
put
(
messagesJSONArray
.
getJSONObject
(
it
).
get
(
"u"
))
val
user
=
User
.
builder
()
.
setId
(
userJSONArray
.
getJSONObject
(
0
).
optString
(
"_id"
))
.
setUsername
(
userJSONArray
.
getJSONObject
(
0
).
optString
(
"username"
))
.
setUtcOffset
(
0.0
)
.
build
()
val
timestampString
=
messagesJSONArray
.
getJSONObject
(
it
).
optString
(
"ts"
)
val
timestamp
=
if
(
timestampString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
timestampString
.
replace
(
"T"
,
" "
)
.
replace
(
"Z"
,
""
))
.
time
}
val
editedAtString
=
messagesJSONArray
.
getJSONObject
(
it
).
optString
(
"_updatedAt"
)
val
editedAt
=
if
(
editedAtString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
editedAtString
.
replace
(
"T"
,
" "
)
.
replace
(
"Z"
,
""
))
.
time
}
Message
.
builder
()
.
setId
(
messagesJSONArray
.
getJSONObject
(
it
).
optString
(
"_id"
))
.
setRoomId
(
messagesJSONArray
.
getJSONObject
(
it
).
optString
(
"rid"
))
.
setMessage
(
messagesJSONArray
.
getJSONObject
(
it
).
optString
(
"msg"
))
.
setTimestamp
(
timestamp
)
.
setEditedAt
(
editedAt
)
.
setGroupable
(
messagesJSONArray
.
getJSONObject
(
it
).
optBoolean
(
"groupable"
))
.
setUser
(
user
)
.
setSyncState
(
SyncState
.
SYNCED
)
.
build
()
}
mainHandler
.
post
{
view
.
showPinnedMessages
(
dataSet
)
}
}
else
{
}
else
{
// TODO("move to strings.xml")
mainHandler
.
post
{
view
.
showMessage
(
context
.
getString
(
R
.
string
.
dialog_room_could_not_load_your_request
,
response
.
message
()))
}
view
.
showMessage
(
"Response is not successful"
)
}
}
}
}
})
})
}
}
// TODO (need to create a proper POJO)
private
fun
getFavoriteMessages
(
roomId
:
String
,
private
fun
getFavoriteMessages
(
roomId
:
String
,
roomType
:
String
,
roomType
:
String
,
hostname
:
String
,
hostname
:
String
,
...
@@ -102,15 +146,14 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -102,15 +146,14 @@ 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
)
}
else
{
}
else
{
// TODO("move to strings.xml")
mainHandler
.
post
{
view
.
showMessage
(
context
.
getString
(
R
.
string
.
dialog_room_could_not_load_your_request
,
response
.
message
()))
}
view
.
showMessage
(
"Response is not successful"
)
}
}
}
}
})
})
}
}
// TODO (need test)
private
fun
getFileList
(
roomId
:
String
,
private
fun
getFileList
(
roomId
:
String
,
roomType
:
String
,
roomType
:
String
,
hostname
:
String
,
hostname
:
String
,
...
@@ -131,6 +174,8 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -131,6 +174,8 @@ 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
)
val
filesJSONArray
=
jSONObject
.
get
(
"files"
)
as
JSONArray
val
filesJSONArray
=
jSONObject
.
get
(
"files"
)
as
JSONArray
val
filesJSONArrayLength
=
filesJSONArray
.
length
()
val
filesJSONArrayLength
=
filesJSONArray
.
length
()
...
@@ -150,13 +195,13 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -150,13 +195,13 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
mainHandler
.
post
{
view
.
showFileList
(
dataSet
)
}
mainHandler
.
post
{
view
.
showFileList
(
dataSet
)
}
}
else
{
}
else
{
// TODO("move to strings.xml")
mainHandler
.
post
{
view
.
showMessage
(
context
.
getString
(
R
.
string
.
dialog_room_could_not_load_your_request
,
response
.
message
()))
}
view
.
showMessage
(
"Response is not successful"
)
}
}
}
}
})
})
}
}
// TODO (need test)
private
fun
getMemberList
(
roomId
:
String
,
private
fun
getMemberList
(
roomId
:
String
,
roomType
:
String
,
roomType
:
String
,
hostname
:
String
,
hostname
:
String
,
...
@@ -187,8 +232,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
...
@@ -187,8 +232,7 @@ class RoomDialogPresenter(val context: Context, val view: RoomDialogContract.Vie
mainHandler
.
post
{
view
.
showMemberList
(
dataSet
)
}
mainHandler
.
post
{
view
.
showMemberList
(
dataSet
)
}
}
else
{
}
else
{
// TODO("move to strings.xml")
mainHandler
.
post
{
view
.
showMessage
(
context
.
getString
(
R
.
string
.
dialog_room_could_not_load_your_request
,
response
.
message
()))
}
view
.
showMessage
(
"Response is not successful"
)
}
}
}
}
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment