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
Hide 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
package
chat.rocket.android.chatroom.presentation
import
android.graphics.Bitmap
import
android.net.Uri
import
android.net.Uri
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.analytics.AnalyticsManager
import
chat.rocket.android.analytics.AnalyticsManager
...
@@ -80,6 +81,7 @@ import org.threeten.bp.Instant
...
@@ -80,6 +81,7 @@ import org.threeten.bp.Instant
import
timber.log.Timber
import
timber.log.Timber
import
java.io.InputStream
import
java.io.InputStream
import
java.util.*
import
java.util.*
import
java.util.zip.DeflaterInputStream
import
javax.inject.Inject
import
javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
class
ChatRoomPresenter
@Inject
constructor
(
...
@@ -331,7 +333,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -331,7 +333,7 @@ class ChatRoomPresenter @Inject constructor(
view
.
showFileSelection
(
settings
.
uploadMimeTypeFilter
())
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
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
view
.
showLoading
()
try
{
try
{
...
@@ -348,12 +350,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -348,12 +350,8 @@ class ChatRoomPresenter @Inject constructor(
else
->
{
else
->
{
var
inputStream
:
InputStream
?
=
uriInteractor
.
getInputStream
(
uri
)
var
inputStream
:
InputStream
?
=
uriInteractor
.
getInputStream
(
uri
)
if
(
mimeType
.
contains
(
"image"
))
{
bitmap
?.
compressImageAndGetInputStream
(
mimeType
)
?.
let
{
uriInteractor
.
getBitmap
(
uri
)
?.
let
{
inputStream
=
it
it
.
compressImageAndGetInputStream
(
mimeType
)
?.
let
{
inputStream
=
it
}
}
}
}
retryIO
(
"uploadFile($roomId, $fileName, $mimeType"
)
{
retryIO
(
"uploadFile($roomId, $fileName, $mimeType"
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/Dialog.kt
View file @
de7eac9a
package
chat.rocket.android.chatroom.ui
package
chat.rocket.android.chatroom.ui
import
android.graphics.Bitmap
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.net.Uri
import
android.net.Uri
import
androidx.core.view.isVisible
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.getFileName
import
chat.rocket.android.util.extensions.getMimeType
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
)
{
fun
ChatRoomFragment
.
showFileAttachmentDialog
(
uri
:
Uri
)
{
activity
?.
let
{
fragmentActivity
->
var
bitmap
:
Bitmap
?
=
null
uri
.
getMimeType
(
fragmentActivity
).
let
{
mimeType
->
activity
?.
let
{
context
->
uri
.
getMimeType
(
context
).
let
{
mimeType
->
description
.
text
.
clear
()
description
.
text
.
clear
()
when
{
when
{
mimeType
.
startsWith
(
"image"
)
->
{
mimeType
.
startsWith
(
"image"
)
->
{
imagePreview
.
isVisible
=
true
GlideApp
imagePreview
.
setImageURI
(
uri
)
.
with
(
context
)
}
.
asBitmap
()
mimeType
.
startsWith
(
"video"
)
->
{
.
load
(
uri
)
audioVideoAttachment
.
isVisible
=
true
.
override
(
500
,
500
)
.
centerCrop
()
.
into
(
object
:
SimpleTarget
<
Bitmap
>()
{
override
fun
onResourceReady
(
resource
:
Bitmap
,
transition
:
Transition
<
in
Bitmap
>?
)
{
bitmap
=
resource
imagePreview
.
isVisible
=
true
imagePreview
.
setImageBitmap
(
resource
)
}
})
}
}
mimeType
.
startsWith
(
"video"
)
->
audioVideoAttachment
.
isVisible
=
true
else
->
{
else
->
{
textFile
.
isVisible
=
true
textFile
.
isVisible
=
true
textFile
.
text
=
uri
.
getFileName
(
fragmentActivity
)
textFile
.
text
=
uri
.
getFileName
(
context
)
}
}
}
}
}
}
}
}
sendButton
.
setOnClickListener
{
sendButton
.
setOnClickListener
{
presenter
.
uploadFile
(
chatRoomId
,
uri
,
(
citation
?:
""
)
+
description
.
text
.
toString
())
presenter
.
uploadFile
(
chatRoomId
,
uri
,
(
citation
?:
""
)
+
description
.
text
.
toString
(),
bitmap
)
alertDialog
.
dismiss
()
alertDialog
.
dismiss
()
}
}
cancelButton
.
setOnClickListener
{
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
...
@@ -10,15 +10,19 @@ import android.provider.DocumentsContract
import
android.provider.MediaStore
import
android.provider.MediaStore
import
android.provider.OpenableColumns
import
android.provider.OpenableColumns
import
android.webkit.MimeTypeMap
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
?
{
fun
Uri
.
getFileName
(
context
:
Context
):
String
?
{
val
cursor
=
context
.
contentResolver
.
query
(
this
,
null
,
null
,
null
,
null
,
null
)
val
cursor
=
context
.
contentResolver
.
query
(
this
,
null
,
null
,
null
,
null
,
null
)
var
fileName
:
String
?
=
null
var
fileName
:
String
?
=
null
cursor
.
use
{
cursor
->
cursor
?.
use
{
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
if
(
it
.
moveToFirst
())
{
fileName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
))
fileName
=
it
.
getString
(
it
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
))
}
}
}
}
return
fileName
return
fileName
...
@@ -29,7 +33,7 @@ fun Uri.getFileSize(context: Context): Int {
...
@@ -29,7 +33,7 @@ fun Uri.getFileSize(context: Context): Int {
if
(
scheme
==
ContentResolver
.
SCHEME_CONTENT
)
{
if
(
scheme
==
ContentResolver
.
SCHEME_CONTENT
)
{
try
{
try
{
val
fileInputStream
=
context
.
contentResolver
.
openInputStream
(
this
)
val
fileInputStream
=
context
.
contentResolver
.
openInputStream
(
this
)
fileSize
=
fileInputStream
.
available
().
toString
()
fileSize
=
fileInputStream
?
.
available
().
toString
()
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
e
.
printStackTrace
()
}
}
...
@@ -67,14 +71,17 @@ fun Uri.isVirtualFile(context: Context): Boolean {
...
@@ -67,14 +71,17 @@ fun Uri.isVirtualFile(context: Context): Boolean {
val
cursor
=
context
.
contentResolver
.
query
(
val
cursor
=
context
.
contentResolver
.
query
(
this
,
this
,
arrayOf
(
DocumentsContract
.
Document
.
COLUMN_FLAGS
),
arrayOf
(
DocumentsContract
.
Document
.
COLUMN_FLAGS
),
null
,
null
,
null
null
,
null
,
null
)
)
var
flags
=
0
var
flags
=
0
if
(
cursor
.
moveToFirst
())
{
cursor
?.
use
{
flags
=
cursor
.
getInt
(
0
)
if
(
it
.
moveToFirst
())
{
flags
=
it
.
getInt
(
0
)
}
}
}
cursor
.
close
()
return
flags
and
DocumentsContract
.
Document
.
FLAG_VIRTUAL_DOCUMENT
!=
0
return
flags
and
DocumentsContract
.
Document
.
FLAG_VIRTUAL_DOCUMENT
!=
0
}
}
...
@@ -104,4 +111,4 @@ fun Uri.getInputStream(context: Context): InputStream? {
...
@@ -104,4 +111,4 @@ fun Uri.getInputStream(context: Context): InputStream? {
fun
Uri
.
getBitmpap
(
context
:
Context
):
Bitmap
?
{
fun
Uri
.
getBitmpap
(
context
:
Context
):
Bitmap
?
{
return
MediaStore
.
Images
.
Media
.
getBitmap
(
context
.
contentResolver
,
this
)
return
MediaStore
.
Images
.
Media
.
getBitmap
(
context
.
contentResolver
,
this
)
}
}
\ 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