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
4c76d6ca
Commit
4c76d6ca
authored
Apr 25, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request for 'WRITE_EXTERNAL_STORAGE' permission
parent
3f4f20cb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
ImageAttachmentViewHolder.kt
...ket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
+22
-0
AndroidPermissionsHelper.kt
...va/chat/rocket/android/helper/AndroidPermissionsHelper.kt
+21
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
View file @
4c76d6ca
package
chat.rocket.android.chatroom.adapter
package
chat.rocket.android.chatroom.adapter
import
android.Manifest
import
android.app.Activity
import
android.graphics.Color
import
android.graphics.Color
import
android.media.MediaScannerConnection
import
android.media.MediaScannerConnection
import
android.net.Uri
import
android.net.Uri
import
android.os.Environment
import
android.os.Environment
import
android.support.v7.widget.Toolbar
import
android.support.v7.widget.Toolbar
import
android.view.ContextThemeWrapper
import
android.view.View
import
android.view.View
import
android.widget.Toast
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.viewmodel.ImageAttachmentViewModel
import
chat.rocket.android.chatroom.viewmodel.ImageAttachmentViewModel
import
chat.rocket.android.helper.AndroidPermissionsHelper
import
chat.rocket.android.widget.emoji.EmojiReactionListener
import
chat.rocket.android.widget.emoji.EmojiReactionListener
import
com.facebook.binaryresource.FileBinaryResource
import
com.facebook.binaryresource.FileBinaryResource
import
com.facebook.cache.common.CacheKey
import
com.facebook.cache.common.CacheKey
...
@@ -82,6 +86,10 @@ class ImageAttachmentViewHolder(itemView: View,
...
@@ -82,6 +86,10 @@ class ImageAttachmentViewHolder(itemView: View,
}
}
private
fun
saveImage
():
Boolean
{
private
fun
saveImage
():
Boolean
{
if
(!
canWriteToExternalStorage
())
{
checkWritingPermission
()
return
false
}
if
(
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
hasKey
(
cacheKey
))
{
if
(
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
hasKey
(
cacheKey
))
{
val
context
=
itemView
.
context
val
context
=
itemView
.
context
val
resource
=
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
getResource
(
cacheKey
)
val
resource
=
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
getResource
(
cacheKey
)
...
@@ -109,4 +117,18 @@ class ImageAttachmentViewHolder(itemView: View,
...
@@ -109,4 +117,18 @@ class ImageAttachmentViewHolder(itemView: View,
}
}
return
true
return
true
}
}
private
fun
canWriteToExternalStorage
():
Boolean
{
return
AndroidPermissionsHelper
.
checkPermission
(
itemView
.
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
}
private
fun
checkWritingPermission
()
{
val
context
=
itemView
.
context
if
(
context
is
ContextThemeWrapper
&&
context
.
baseContext
is
Activity
)
{
val
activity
=
context
.
baseContext
as
Activity
AndroidPermissionsHelper
.
requestPermission
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
AndroidPermissionsHelper
.
WRITE_EXTERNAL_STORAGE_CODE
)
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/helper/AndroidPermissionsHelper.kt
0 → 100644
View file @
4c76d6ca
package
chat.rocket.android.helper
import
android.app.Activity
import
android.content.Context
import
android.content.pm.PackageManager
import
android.support.v4.app.ActivityCompat
import
android.support.v4.content.ContextCompat
object
AndroidPermissionsHelper
{
const
val
WRITE_EXTERNAL_STORAGE_CODE
=
1
fun
checkPermission
(
context
:
Context
,
permission
:
String
):
Boolean
{
return
ContextCompat
.
checkSelfPermission
(
context
,
permission
)
==
PackageManager
.
PERMISSION_GRANTED
}
fun
requestPermission
(
context
:
Activity
,
permission
:
String
,
requestCode
:
Int
)
{
ActivityCompat
.
requestPermissions
(
context
,
arrayOf
(
permission
),
requestCode
)
}
}
\ 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