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
89f38952
Commit
89f38952
authored
Feb 09, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implements the file upload using RocketChatClient.
parent
2e5f7c8b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
13 deletions
+55
-13
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+13
-4
ChatRoomView.kt
...chat/rocket/android/chatroom/presentation/ChatRoomView.kt
+2
-2
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+17
-5
String.kt
...c/main/java/chat/rocket/android/util/extensions/String.kt
+23
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
89f38952
...
...
@@ -15,13 +15,14 @@ import chat.rocket.core.internal.realtime.subscribeRoomMessages
import
chat.rocket.core.internal.realtime.unsubscibre
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.sendMessage
import
chat.rocket.core.internal.rest.uploadFile
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.attachment.Attachment
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
java.io.File
import
javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomView
,
...
...
@@ -90,13 +91,21 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
fun
sendFile
(
chatRoomId
:
String
,
fileName
:
String
)
{
fun
uploadFile
(
roomId
:
String
,
file
:
File
,
mimeType
:
String
,
msg
:
String
,
description
:
String
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
// client.sendMessage(chatRoomId
)
client
.
uploadFile
(
roomId
,
file
,
mimeType
,
msg
,
description
)
}
catch
(
ex
:
RocketChatException
)
{
ex
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
finally
{
view
.
hideLoading
()
}
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomView.kt
View file @
89f38952
...
...
@@ -22,11 +22,11 @@ interface ChatRoomView : LoadingView, MessageView {
fun
sendMessage
(
text
:
String
)
/**
*
Send
a file to a chat room.
*
Uploads
a file to a chat room.
*
* @param uri The file URI to send.
*/
fun
sen
dFile
(
uri
:
Uri
)
fun
uploa
dFile
(
uri
:
Uri
)
/**
* Shows a (recent) message sent to a chat room.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
89f38952
...
...
@@ -23,6 +23,7 @@ import dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_attachment_options.*
import
kotlinx.android.synthetic.main.message_composer.*
import
java.io.File
import
javax.inject.Inject
fun
newInstance
(
chatRoomId
:
String
,
chatRoomName
:
String
,
chatRoomType
:
String
,
isChatRoomReadOnly
:
Boolean
):
Fragment
{
...
...
@@ -88,7 +89,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
resultData
:
Intent
?)
{
if
(
requestCode
==
REQUEST_CODE_FOR_PERFORM_SAF
&&
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
resultData
!=
null
)
{
sen
dFile
(
resultData
.
data
)
uploa
dFile
(
resultData
.
data
)
}
}
}
...
...
@@ -120,13 +121,24 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
}
}
override
fun
sen
dFile
(
uri
:
Uri
)
{
override
fun
uploa
dFile
(
uri
:
Uri
)
{
var
fileName
:
String
?
=
null
var
mimeType
:
String
?
=
null
var
fileRealPath
:
String
?
=
null
activity
?.
apply
{
fileName
=
uri
.
getFileName
(
this
)
}
if
(
fileName
!=
null
)
{
presenter
.
sendFile
(
chatRoomId
,
fileName
.
toString
())
mimeType
=
uri
.
getMimeType
(
this
)
fileRealPath
=
uri
.
getRealPathFromURI
(
this
)
if
(
fileName
!=
null
&&
mimeType
!=
null
&&
fileRealPath
!=
null
)
{
presenter
.
uploadFile
(
chatRoomId
,
File
(
fileRealPath
),
mimeType
.
toString
(),
""
,
// TODO Just leaving it for now, in the future lets add the possibility to add a message with the file to be uploaded.
fileName
.
toString
()
)
}
}
}
...
...
app/src/main/java/chat/rocket/android/util/extensions/String.kt
View file @
89f38952
package
chat.rocket.android.util.extensions
import
android.app.Activity
import
android.content.ContentResolver
import
android.content.Context
import
android.net.Uri
import
android.widget.TextView
import
android.provider.OpenableColumns
import
android.webkit.MimeTypeMap
import
android.provider.MediaStore
fun
String
.
ifEmpty
(
value
:
String
):
String
{
if
(
isEmpty
())
{
...
...
@@ -51,4 +53,23 @@ fun Uri.getFileSize(activity: Activity): String? {
}
}
return
fileSize
}
fun
Uri
.
getMimeType
(
context
:
Context
):
String
{
return
if
(
scheme
==
ContentResolver
.
SCHEME_CONTENT
)
{
context
.
contentResolver
.
getType
(
this
)
}
else
{
val
fileExtension
=
MimeTypeMap
.
getFileExtensionFromUrl
(
toString
())
MimeTypeMap
.
getSingleton
().
getMimeTypeFromExtension
(
fileExtension
.
toLowerCase
())
}
}
fun
Uri
.
getRealPathFromURI
(
context
:
Context
):
String
?
{
val
cursor
=
context
.
contentResolver
.
query
(
this
,
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
),
null
,
null
,
null
)
cursor
.
use
{
cursor
->
val
columnIndex
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
)
cursor
.
moveToFirst
()
return
cursor
.
getString
(
columnIndex
)
}
}
\ No newline at end of file
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