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
de7eac9a
Unverified
Commit
de7eac9a
authored
Aug 31, 2018
by
Lucio Maciel
Committed by
GitHub
Aug 31, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1639 from RocketChat/fix/out-of-memory
[FIX] Out of memory when sending large image
parents
4df382a0
d4c2285d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
26 deletions
+54
-26
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+5
-7
Dialog.kt
app/src/main/java/chat/rocket/android/chatroom/ui/Dialog.kt
+32
-9
Uri.kt
app/src/main/java/chat/rocket/android/util/extensions/Uri.kt
+17
-10
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
de7eac9a
package
chat.rocket.android.chatroom.presentation
import
android.graphics.Bitmap
import
android.net.Uri
import
chat.rocket.android.R
import
chat.rocket.android.analytics.AnalyticsManager
...
...
@@ -80,6 +81,7 @@ import org.threeten.bp.Instant
import
timber.log.Timber
import
java.io.InputStream
import
java.util.*
import
java.util.zip.DeflaterInputStream
import
javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
...
...
@@ -331,7 +333,7 @@ class ChatRoomPresenter @Inject constructor(
view
.
showFileSelection
(
settings
.
uploadMimeTypeFilter
())
}
fun
uploadFile
(
roomId
:
String
,
uri
:
Uri
,
msg
:
String
)
{
fun
uploadFile
(
roomId
:
String
,
uri
:
Uri
,
msg
:
String
,
bitmap
:
Bitmap
?
=
null
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
...
...
@@ -348,13 +350,9 @@ class ChatRoomPresenter @Inject constructor(
else
->
{
var
inputStream
:
InputStream
?
=
uriInteractor
.
getInputStream
(
uri
)
if
(
mimeType
.
contains
(
"image"
))
{
uriInteractor
.
getBitmap
(
uri
)
?.
let
{
it
.
compressImageAndGetInputStream
(
mimeType
)
?.
let
{
bitmap
?.
compressImageAndGetInputStream
(
mimeType
)
?.
let
{
inputStream
=
it
}
}
}
retryIO
(
"uploadFile($roomId, $fileName, $mimeType"
)
{
client
.
uploadFile
(
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/Dialog.kt
View file @
de7eac9a
package
chat.rocket.android.chatroom.ui
import
android.graphics.Bitmap
import
android.graphics.drawable.Drawable
import
android.net.Uri
import
androidx.core.view.isVisible
import
chat.rocket.android.emoji.internal.GlideApp
import
chat.rocket.android.util.extensions.getFileName
import
chat.rocket.android.util.extensions.getMimeType
import
com.bumptech.glide.request.target.SimpleTarget
import
com.bumptech.glide.request.transition.Transition
fun
ChatRoomFragment
.
showFileAttachmentDialog
(
uri
:
Uri
)
{
activity
?.
let
{
fragmentActivity
->
uri
.
getMimeType
(
fragmentActivity
).
let
{
mimeType
->
var
bitmap
:
Bitmap
?
=
null
activity
?.
let
{
context
->
uri
.
getMimeType
(
context
).
let
{
mimeType
->
description
.
text
.
clear
()
when
{
mimeType
.
startsWith
(
"image"
)
->
{
GlideApp
.
with
(
context
)
.
asBitmap
()
.
load
(
uri
)
.
override
(
500
,
500
)
.
centerCrop
()
.
into
(
object
:
SimpleTarget
<
Bitmap
>()
{
override
fun
onResourceReady
(
resource
:
Bitmap
,
transition
:
Transition
<
in
Bitmap
>?
)
{
bitmap
=
resource
imagePreview
.
isVisible
=
true
imagePreview
.
setImageURI
(
uri
)
imagePreview
.
setImageBitmap
(
resource
)
}
mimeType
.
startsWith
(
"video"
)
->
{
audioVideoAttachment
.
isVisible
=
true
})
}
mimeType
.
startsWith
(
"video"
)
->
audioVideoAttachment
.
isVisible
=
true
else
->
{
textFile
.
isVisible
=
true
textFile
.
text
=
uri
.
getFileName
(
fragmentActivity
)
textFile
.
text
=
uri
.
getFileName
(
context
)
}
}
}
}
sendButton
.
setOnClickListener
{
presenter
.
uploadFile
(
chatRoomId
,
uri
,
(
citation
?:
""
)
+
description
.
text
.
toString
())
presenter
.
uploadFile
(
chatRoomId
,
uri
,
(
citation
?:
""
)
+
description
.
text
.
toString
(),
bitmap
)
alertDialog
.
dismiss
()
}
cancelButton
.
setOnClickListener
{
alertDialog
.
dismiss
()
}
...
...
app/src/main/java/chat/rocket/android/util/extensions/Uri.kt
View file @
de7eac9a
...
...
@@ -10,15 +10,19 @@ import android.provider.DocumentsContract
import
android.provider.MediaStore
import
android.provider.OpenableColumns
import
android.webkit.MimeTypeMap
import
java.io.*
import
java.io.File
import
java.io.FileInputStream
import
java.io.FileNotFoundException
import
java.io.IOException
import
java.io.InputStream
fun
Uri
.
getFileName
(
context
:
Context
):
String
?
{
val
cursor
=
context
.
contentResolver
.
query
(
this
,
null
,
null
,
null
,
null
,
null
)
var
fileName
:
String
?
=
null
cursor
.
use
{
cursor
->
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
fileName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
))
cursor
?.
use
{
if
(
it
.
moveToFirst
())
{
fileName
=
it
.
getString
(
it
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
))
}
}
return
fileName
...
...
@@ -29,7 +33,7 @@ fun Uri.getFileSize(context: Context): Int {
if
(
scheme
==
ContentResolver
.
SCHEME_CONTENT
)
{
try
{
val
fileInputStream
=
context
.
contentResolver
.
openInputStream
(
this
)
fileSize
=
fileInputStream
.
available
().
toString
()
fileSize
=
fileInputStream
?
.
available
().
toString
()
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
...
...
@@ -67,14 +71,17 @@ fun Uri.isVirtualFile(context: Context): Boolean {
val
cursor
=
context
.
contentResolver
.
query
(
this
,
arrayOf
(
DocumentsContract
.
Document
.
COLUMN_FLAGS
),
null
,
null
,
null
null
,
null
,
null
)
var
flags
=
0
if
(
cursor
.
moveToFirst
())
{
flags
=
cursor
.
getInt
(
0
)
cursor
?.
use
{
if
(
it
.
moveToFirst
())
{
flags
=
it
.
getInt
(
0
)
}
}
cursor
.
close
()
return
flags
and
DocumentsContract
.
Document
.
FLAG_VIRTUAL_DOCUMENT
!=
0
}
...
...
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