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
d675b1e8
Commit
d675b1e8
authored
Sep 28, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RoomListPresenter.kt
parent
aa288e56
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
52 deletions
+69
-52
RoomListPresenter.kt
...ocket/android/fragment/chatroom/list/RoomListPresenter.kt
+69
-52
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/list/RoomListPresenter.kt
View file @
d675b1e8
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom.list
import
android.content.Context
import
android.os.Handler
import
android.util.Log
import
chat.rocket.android.R
import
chat.rocket.android.api.rest.RestApiHelper
import
chat.rocket.android.helper.OkHttpHelper
...
...
@@ -11,6 +12,7 @@ import chat.rocket.core.models.User
import
okhttp3.Call
import
okhttp3.Callback
import
okhttp3.Response
import
org.json.JSONException
import
org.json.JSONObject
import
java.io.IOException
import
java.sql.Timestamp
...
...
@@ -147,72 +149,80 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
}
private
fun
handleMessagesJson
(
json
:
String
,
isPinnedMessage
:
Boolean
)
{
val
jSONObject
=
JSONObject
(
json
)
val
messagesJSONArray
=
jSONObject
.
getJSONArray
(
"messages"
)
try
{
val
jSONObject
=
JSONObject
(
json
)
val
messagesJSONArray
=
jSONObject
.
getJSONArray
(
"messages"
)
val
total
=
messagesJSONArray
.
length
()
val
dataSet
=
ArrayList
<
Message
>(
total
)
(
0
until
total
).
mapTo
(
dataSet
)
{
val
messageJsonObject
=
messagesJSONArray
.
getJSONObject
(
it
)
val
userJsonObject
=
messageJsonObject
.
getJSONObject
(
"u"
)
val
total
=
messagesJSONArray
.
length
()
val
dataSet
=
ArrayList
<
Message
>(
total
)
(
0
until
total
).
mapTo
(
dataSet
)
{
val
messageJsonObject
=
messagesJSONArray
.
getJSONObject
(
it
)
val
userJsonObject
=
messageJsonObject
.
getJSONObject
(
"u"
)
val
timestampString
=
messageJsonObject
.
optString
(
"ts"
)
val
timestamp
=
if
(
timestampString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
timestampString
.
replace
(
"T"
,
" "
).
replace
(
"Z"
,
""
)).
time
}
val
timestampString
=
messageJsonObject
.
optString
(
"ts"
)
val
timestamp
=
if
(
timestampString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
timestampString
.
replace
(
"T"
,
" "
).
replace
(
"Z"
,
""
)).
time
}
val
editedAtString
=
messageJsonObject
.
optString
(
"_updatedAt"
)
val
editedAt
=
if
(
editedAtString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
editedAtString
.
replace
(
"T"
,
" "
).
replace
(
"Z"
,
""
)).
time
}
val
editedAtString
=
messageJsonObject
.
optString
(
"_updatedAt"
)
val
editedAt
=
if
(
editedAtString
.
isBlank
())
{
0
}
else
{
Timestamp
.
valueOf
(
editedAtString
.
replace
(
"T"
,
" "
).
replace
(
"Z"
,
""
)).
time
}
Message
.
builder
()
.
setId
(
messageJsonObject
.
optString
(
"_id"
))
.
setRoomId
(
messageJsonObject
.
optString
(
"rid"
))
.
setMessage
(
messageJsonObject
.
optString
(
"msg"
))
.
setUser
(
getUserFromJsonObject
(
userJsonObject
))
.
setTimestamp
(
timestamp
)
.
setEditedAt
(
editedAt
)
.
setGroupable
(
messageJsonObject
.
optBoolean
(
"groupable"
))
.
setSyncState
(
SyncState
.
SYNCED
)
.
build
()
}
Message
.
builder
()
.
setId
(
messageJsonObject
.
optString
(
"_id"
))
.
setRoomId
(
messageJsonObject
.
optString
(
"rid"
))
.
setMessage
(
messageJsonObject
.
optString
(
"msg"
))
.
setUser
(
getUserFromJsonObject
(
userJsonObject
))
.
setTimestamp
(
timestamp
)
.
setEditedAt
(
editedAt
)
.
setGroupable
(
messageJsonObject
.
optBoolean
(
"groupable"
))
.
setSyncState
(
SyncState
.
SYNCED
)
.
build
()
}
if
(
dataSet
.
isEmpty
()
&&
!
hasItem
)
{
showEmptyViewMessage
(
context
.
getString
(
R
.
string
.
fragment_room_list_no_favorite_message_to_show
))
}
else
{
if
(
dataSet
.
isNotEmpty
())
{
hasItem
=
true
if
(
isPinnedMessage
)
{
showPinnedMessageList
(
dataSet
,
jSONObject
.
optString
(
"total"
))
}
else
{
showFavoriteMessageList
(
dataSet
,
jSONObject
.
optString
(
"total"
))
if
(
dataSet
.
isEmpty
()
&&
!
hasItem
)
{
showEmptyViewMessage
(
context
.
getString
(
R
.
string
.
fragment_room_list_no_favorite_message_to_show
))
}
else
{
if
(
dataSet
.
isNotEmpty
())
{
hasItem
=
true
if
(
isPinnedMessage
)
{
showPinnedMessageList
(
dataSet
,
jSONObject
.
optString
(
"total"
))
}
else
{
showFavoriteMessageList
(
dataSet
,
jSONObject
.
optString
(
"total"
))
}
}
}
}
catch
(
exception
:
JSONException
)
{
showInvalidRequest
()
}
}
private
fun
handleMembersJson
(
json
:
String
)
{
val
jsonObject
=
JSONObject
(
json
)
val
membersJsonArray
=
jsonObject
.
getJSONArray
(
"members"
)
try
{
val
jsonObject
=
JSONObject
(
json
)
val
membersJsonArray
=
jsonObject
.
getJSONArray
(
"members"
)
val
total
=
membersJsonArray
.
length
()
val
dataSet
=
ArrayList
<
User
>(
total
)
(
0
until
total
).
mapTo
(
dataSet
)
{
getUserFromJsonObject
(
membersJsonArray
.
getJSONObject
(
it
))
}
val
total
=
membersJsonArray
.
length
()
val
dataSet
=
ArrayList
<
User
>(
total
)
(
0
until
total
).
mapTo
(
dataSet
)
{
getUserFromJsonObject
(
membersJsonArray
.
getJSONObject
(
it
))
}
if
(
dataSet
.
isEmpty
()
&&
!
hasItem
)
{
showEmptyViewMessage
(
context
.
getString
(
R
.
string
.
fragment_room_list_no_member_list_to_show
))
}
else
{
if
(
dataSet
.
isNotEmpty
())
{
hasItem
=
true
showMemberList
(
dataSet
,
jsonObject
.
optString
(
"total"
))
if
(
dataSet
.
isEmpty
()
&&
!
hasItem
)
{
showEmptyViewMessage
(
context
.
getString
(
R
.
string
.
fragment_room_list_no_member_list_to_show
))
}
else
{
if
(
dataSet
.
isNotEmpty
())
{
hasItem
=
true
showMemberList
(
dataSet
,
jsonObject
.
optString
(
"total"
))
}
}
}
catch
(
exception
:
JSONException
)
{
showInvalidRequest
()
}
}
...
...
@@ -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
)
{
mainHandler
.
post
{
view
.
showWaitingView
(
false
)
...
...
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