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
5b2fd03a
Commit
5b2fd03a
authored
Sep 29, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RoomListPresenter.kt
parent
2093a1a7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
4 deletions
+88
-4
RoomListPresenter.kt
...ocket/android/fragment/chatroom/list/RoomListPresenter.kt
+88
-4
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/list/RoomListPresenter.kt
View file @
5b2fd03a
...
@@ -2,11 +2,13 @@ package chat.rocket.android.fragment.chatroom.list
...
@@ -2,11 +2,13 @@ package chat.rocket.android.fragment.chatroom.list
import
android.content.Context
import
android.content.Context
import
android.os.Handler
import
android.os.Handler
import
android.util.Log
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.api.rest.RestApiHelper
import
chat.rocket.android.api.rest.RestApiHelper
import
chat.rocket.android.helper.OkHttpHelper
import
chat.rocket.android.helper.OkHttpHelper
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.core.SyncState
import
chat.rocket.core.SyncState
import
chat.rocket.core.models.Attachment
import
chat.rocket.core.models.AttachmentTitle
import
chat.rocket.core.models.Message
import
chat.rocket.core.models.Message
import
chat.rocket.core.models.User
import
chat.rocket.core.models.User
import
okhttp3.Call
import
okhttp3.Call
...
@@ -98,13 +100,43 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
...
@@ -98,13 +100,43 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
})
})
}
}
// TODO (after the REST api fixes)
override
fun
requestFileList
(
roomId
:
String
,
override
fun
requestFileList
(
roomId
:
String
,
roomType
:
String
,
roomType
:
String
,
hostname
:
String
,
hostname
:
String
,
token
:
String
,
token
:
String
,
userId
:
String
,
userId
:
String
,
offset
:
Int
)
{}
offset
:
Int
)
{
view
.
showWaitingView
(
true
)
OkHttpHelper
.
getClient
()
.
newCall
(
RestApiHelper
.
getRequestForFileList
(
roomId
,
roomType
,
hostname
,
token
,
userId
,
offset
.
toString
()))
.
enqueue
(
object
:
Callback
{
override
fun
onFailure
(
call
:
Call
,
e
:
IOException
)
{
if
(!
call
.
isCanceled
)
{
val
message
=
e
.
message
if
(
message
!=
null
)
{
showErrorMessage
(
message
)
}
}
}
@Throws
(
IOException
::
class
)
override
fun
onResponse
(
call
:
Call
,
response
:
Response
)
{
if
(
response
.
isSuccessful
)
{
val
result
=
response
.
body
()
?.
string
()
if
(
result
!=
null
)
{
handleFilesJson
(
result
,
hostname
)
}
}
else
{
showErrorMessage
(
response
.
message
())
}
}
})
}
override
fun
requestMemberList
(
roomId
:
String
,
override
fun
requestMemberList
(
roomId
:
String
,
roomType
:
String
,
roomType
:
String
,
...
@@ -202,6 +234,51 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
...
@@ -202,6 +234,51 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
}
}
}
}
private
fun
handleFilesJson
(
json
:
String
,
hostname
:
String
)
{
try
{
val
jsonObject
=
JSONObject
(
json
)
val
filesJsonArray
=
jsonObject
.
getJSONArray
(
"files"
)
val
total
=
filesJsonArray
.
length
()
val
dataSet
=
ArrayList
<
Attachment
>(
total
)
(
0
until
total
).
mapTo
(
dataSet
)
{
val
fileJsonObject
=
filesJsonArray
.
getJSONObject
(
it
)
val
fileLink
=
UrlHelper
.
getAttachmentLink
(
hostname
,
fileJsonObject
.
optString
(
"_id"
),
fileJsonObject
.
optString
(
"name"
))
val
attachmentTitle
=
AttachmentTitle
.
builder
()
.
setTitle
(
fileJsonObject
.
optString
(
"name"
))
.
setLink
(
fileLink
)
.
setDownloadLink
(
fileLink
)
.
build
()
val
attachment
=
Attachment
.
builder
()
val
type
=
fileJsonObject
.
optString
(
"type"
)
when
{
type
.
startsWith
(
"image"
)
->
attachment
.
setImageUrl
(
fileLink
)
type
.
startsWith
(
"audio"
)
->
attachment
.
setAudioUrl
(
fileLink
)
type
.
startsWith
(
"video"
)
->
attachment
.
setVideoUrl
(
fileLink
)
}
attachment
.
setCollapsed
(
false
)
.
setAttachmentTitle
(
attachmentTitle
)
.
build
()
}
if
(
dataSet
.
isEmpty
()
&&
!
hasItem
)
{
showEmptyViewMessage
(
context
.
getString
(
R
.
string
.
fragment_room_list_no_file_list_to_show
))
}
else
{
if
(
dataSet
.
isNotEmpty
())
{
hasItem
=
true
showFileList
(
dataSet
,
jsonObject
.
optString
(
"total"
))
}
}
}
catch
(
exception
:
JSONException
)
{
showInvalidRequest
()
}
}
private
fun
handleMembersJson
(
json
:
String
)
{
private
fun
handleMembersJson
(
json
:
String
)
{
try
{
try
{
val
jsonObject
=
JSONObject
(
json
)
val
jsonObject
=
JSONObject
(
json
)
...
@@ -221,7 +298,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
...
@@ -221,7 +298,7 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
showMemberList
(
dataSet
,
jsonObject
.
optString
(
"total"
))
showMemberList
(
dataSet
,
jsonObject
.
optString
(
"total"
))
}
}
}
}
}
catch
(
exception
:
JSONException
)
{
}
catch
(
exception
:
JSONException
)
{
showInvalidRequest
()
showInvalidRequest
()
}
}
}
}
...
@@ -250,6 +327,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
...
@@ -250,6 +327,13 @@ class RoomListPresenter(val context: Context, val view: RoomListContract.View) :
}
}
}
}
private
fun
showFileList
(
dataSet
:
ArrayList
<
Attachment
>,
total
:
String
)
{
mainHandler
.
post
{
view
.
showWaitingView
(
false
)
view
.
showFileList
(
dataSet
,
total
)
}
}
private
fun
showMemberList
(
dataSet
:
ArrayList
<
User
>,
total
:
String
)
{
private
fun
showMemberList
(
dataSet
:
ArrayList
<
User
>,
total
:
String
)
{
mainHandler
.
post
{
mainHandler
.
post
{
view
.
showWaitingView
(
false
)
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