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
3f4f20cb
Commit
3f4f20cb
authored
Apr 25, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement save image to gallery
parent
bdac1db4
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
8 deletions
+95
-8
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
ImageAttachmentViewHolder.kt
...ket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
+74
-7
image_actions.xml
app/src/main/res/menu/image_actions.xml
+9
-0
strings.xml
app/src/main/res/values-es/strings.xml
+2
-0
strings.xml
app/src/main/res/values-fr/strings.xml
+2
-0
strings.xml
app/src/main/res/values-hi-rIN/strings.xml
+2
-0
strings.xml
app/src/main/res/values-pt-rBR/strings.xml
+3
-1
strings.xml
app/src/main/res/values/strings.xml
+2
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
3f4f20cb
...
...
@@ -6,6 +6,7 @@
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"com.google.android.c2dm.permission.RECEIVE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<permission
android:name=
"${applicationId}.permission.C2D_MESSAGE"
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
View file @
3f4f20cb
package
chat.rocket.android.chatroom.adapter
import
android.graphics.Color
import
android.media.MediaScannerConnection
import
android.net.Uri
import
android.os.Environment
import
android.support.v7.widget.Toolbar
import
android.view.View
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.viewmodel.ImageAttachmentViewModel
import
com.facebook.drawee.backends.pipeline.Fresco
import
com.facebook.drawee.interfaces.DraweeController
import
chat.rocket.android.widget.emoji.EmojiReactionListener
import
com.facebook.binaryresource.FileBinaryResource
import
com.facebook.cache.common.CacheKey
import
com.facebook.drawee.backends.pipeline.Fresco
import
com.facebook.imageformat.ImageFormatChecker
import
com.facebook.imagepipeline.cache.DefaultCacheKeyFactory
import
com.facebook.imagepipeline.core.ImagePipelineFactory
import
com.facebook.imagepipeline.request.ImageRequest
import
com.facebook.imagepipeline.request.ImageRequestBuilder
import
com.stfalcon.frescoimageviewer.ImageViewer
import
kotlinx.android.synthetic.main.message_attachment.view.*
import
timber.log.Timber
import
java.io.File
class
ImageAttachmentViewHolder
(
itemView
:
View
,
listener
:
ActionsListener
,
reactionListener
:
EmojiReactionListener
?
=
null
)
:
BaseViewHolder
<
ImageAttachmentViewModel
>(
itemView
,
listener
,
reactionListener
)
{
private
var
cacheKey
:
CacheKey
?
=
null
init
{
with
(
itemView
)
{
setupActionMenu
(
attachment_container
)
...
...
@@ -31,9 +49,30 @@ class ImageAttachmentViewHolder(itemView: View,
file_name
.
text
=
data
.
attachmentTitle
image_attachment
.
setOnClickListener
{
view
->
// TODO - implement a proper image viewer with a proper Transition
val
request
=
ImageRequestBuilder
.
newBuilderWithSource
(
Uri
.
parse
(
data
.
attachmentUrl
))
.
setLowestPermittedRequestLevel
(
ImageRequest
.
RequestLevel
.
DISK_CACHE
)
.
build
()
cacheKey
=
DefaultCacheKeyFactory
.
getInstance
()
.
getEncodedCacheKey
(
request
,
null
)
val
toolbar
=
Toolbar
(
itemView
.
context
).
also
{
it
.
inflateMenu
(
R
.
menu
.
image_actions
)
it
.
overflowIcon
?.
setTint
(
Color
.
WHITE
)
it
.
setOnMenuItemClickListener
{
return
@setOnMenuItemClickListener
when
(
it
.
itemId
)
{
R
.
id
.
action_save_image
->
saveImage
()
else
->
super
.
onMenuItemClick
(
it
)
}
}
}
val
builder
=
ImageViewer
.
createPipelineDraweeControllerBuilder
()
.
setImageRequest
(
request
)
.
setAutoPlayAnimations
(
true
)
ImageViewer
.
Builder
(
view
.
context
,
listOf
(
data
.
attachmentUrl
))
.
setOverlayView
(
toolbar
)
.
setStartPosition
(
0
)
.
hideStatusBar
(
false
)
.
setCustomDraweeControllerBuilder
(
builder
)
...
...
@@ -42,4 +81,32 @@ class ImageAttachmentViewHolder(itemView: View,
}
}
private
fun
saveImage
():
Boolean
{
if
(
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
hasKey
(
cacheKey
))
{
val
context
=
itemView
.
context
val
resource
=
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
getResource
(
cacheKey
)
val
cachedFile
=
(
resource
as
FileBinaryResource
).
file
val
imageFormat
=
ImageFormatChecker
.
getImageFormat
(
resource
.
openStream
())
val
imageDir
=
"${Environment.DIRECTORY_PICTURES}/Rocket.Chat Images/"
val
imagePath
=
Environment
.
getExternalStoragePublicDirectory
(
imageDir
)
val
imageFile
=
File
(
imagePath
,
"${cachedFile.nameWithoutExtension}.${imageFormat.fileExtension}"
)
imagePath
.
mkdirs
()
imageFile
.
createNewFile
()
try
{
cachedFile
.
copyTo
(
imageFile
,
true
)
MediaScannerConnection
.
scanFile
(
context
,
arrayOf
(
imageFile
.
absolutePath
),
null
)
{
path
,
uri
->
Timber
.
i
(
"Scanned $path:"
)
Timber
.
i
(
"-> uri=$uri"
)
}
}
catch
(
ex
:
Exception
)
{
Timber
.
e
(
ex
)
val
message
=
context
.
getString
(
R
.
string
.
msg_image_saved_failed
)
Toast
.
makeText
(
context
,
message
,
Toast
.
LENGTH_SHORT
).
show
()
}
finally
{
val
message
=
context
.
getString
(
R
.
string
.
msg_image_saved_successfully
)
Toast
.
makeText
(
context
,
message
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
return
true
}
}
\ No newline at end of file
app/src/main/res/menu/image_actions.xml
0 → 100644
View file @
3f4f20cb
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/action_save_image"
android:title=
"Save to Gallery"
app:showAsAction=
"never"
/>
</menu>
\ No newline at end of file
app/src/main/res/values-es/strings.xml
View file @
3f4f20cb
...
...
@@ -93,6 +93,8 @@
<string
name=
"msg_http_insecure"
>
When using HTTP, you\'re connecting to an insecure server. We don\'t recommend you doing that.
</string>
<string
name=
"msg_error_checking_server_version"
>
An error has occurred while checking your server version, please try again
</string>
<string
name=
"msg_invalid_server_protocol"
>
The selected protocol is not accepted by this server, try using HTTPS
</string>
<string
name=
"msg_image_saved_successfully"
>
La imagen se ha guardado en la galería
</string>
<string
name=
"msg_image_saved_failed"
>
Error al guardar la imagen
</string>
<!-- System messages -->
<string
name=
"message_room_name_changed"
>
Room name changed to: %1$s by %2$s
</string>
...
...
app/src/main/res/values-fr/strings.xml
View file @
3f4f20cb
...
...
@@ -93,6 +93,8 @@
<string
name=
"msg_http_insecure"
>
When using HTTP, you\'re connecting to an insecure server. We don\'t recommend you doing that.
</string>
<string
name=
"msg_error_checking_server_version"
>
An error has occurred while checking your server version, please try again
</string>
<string
name=
"msg_invalid_server_protocol"
>
The selected protocol is not accepted by this server, try using HTTPS
</string>
<string
name=
"msg_image_saved_successfully"
>
L\'image a été enregistrée dans la galerie
</string>
<string
name=
"msg_image_saved_failed"
>
Échec de l\'enregistrement de l\'image
</string>
<!-- System messages -->
<string
name=
"message_room_name_changed"
>
Room name changed to: %1$s by %2$s
</string>
...
...
app/src/main/res/values-hi-rIN/strings.xml
View file @
3f4f20cb
...
...
@@ -95,6 +95,8 @@
<string
name=
"msg_http_insecure"
>
HTTP का उपयोग करते समय, आप एक असुरक्षित सर्वर से कनेक्ट हो रहे हैं। हम आपको ऐसा करने की सलाह नहीं देते हैं।
</string>
<string
name=
"msg_error_checking_server_version"
>
आपके सर्वर संस्करण की जांच करते समय एक त्रुटि आई है, कृपया पुनः प्रयास करें
</string>
<string
name=
"msg_invalid_server_protocol"
>
चयनित प्रोटोकॉल इस सर्वर द्वारा स्वीकार नहीं किया गया है, HTTPS का उपयोग करने का प्रयास करें
</string>
<string
name=
"msg_image_saved_successfully"
>
छवि गैलरी में सहेजा गया है
</string>
<string
name=
"msg_image_saved_failed"
>
छवि को सहेजने में विफल
</string>
<!-- System messages -->
<string
name=
"message_room_name_changed"
>
%2$s ने रूम का नाम बदलकर %1$s किया
</string>
...
...
app/src/main/res/values-pt-rBR/strings.xml
View file @
3f4f20cb
...
...
@@ -95,6 +95,8 @@
<string
name=
"msg_http_insecure"
>
Usando HTTP, você estará conectando a um servidor não seguro, não recomendamos sua utilização.
</string>
<string
name=
"msg_error_checking_server_version"
>
Ocorreu um erro verificando a versão do servidor, por favor tente novamente
</string>
<string
name=
"msg_invalid_server_protocol"
>
O protocolo selecionado não é suportado pelo servidor, por favor utilize HTTPS e tente novamente
</string>
<string
name=
"msg_image_saved_successfully"
>
Imagem salva na galeria
</string>
<string
name=
"msg_image_saved_failed"
>
Falha ao salvar a imagem
</string>
<!-- System messages -->
<string
name=
"message_room_name_changed"
>
Nome da sala alterado para: %1$s por %2$s
</string>
...
...
app/src/main/res/values/strings.xml
View file @
3f4f20cb
...
...
@@ -96,6 +96,8 @@
<string
name=
"msg_http_insecure"
>
When using HTTP, you\'re connecting to an insecure server. We don\'t recommend you doing that.
</string>
<string
name=
"msg_error_checking_server_version"
>
An error has occurred while checking your server version, please try again
</string>
<string
name=
"msg_invalid_server_protocol"
>
The selected protocol is not accepted by this server, try using HTTPS
</string>
<string
name=
"msg_image_saved_successfully"
>
Image has been saved to gallery
</string>
<string
name=
"msg_image_saved_failed"
>
Failed to save image
</string>
<!-- System messages -->
<string
name=
"message_room_name_changed"
>
Room name changed to: %1$s by %2$s
</string>
...
...
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