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
805f30fe
Commit
805f30fe
authored
Apr 16, 2019
by
Divyanshu Bhargava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added all permission in AndroidPermissionHelper class
parent
490f0ed3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
36 deletions
+48
-36
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+10
-14
AndroidPermissionsHelper.kt
...va/chat/rocket/android/helper/AndroidPermissionsHelper.kt
+34
-2
ImageHelper.kt
app/src/main/java/chat/rocket/android/helper/ImageHelper.kt
+4
-20
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
805f30fe
...
...
@@ -12,6 +12,7 @@ import android.os.Bundle
import
android.os.Handler
import
android.provider.MediaStore
import
android.text.SpannableStringBuilder
import
android.util.Log
import
android.view.KeyEvent
import
android.view.LayoutInflater
import
android.view.Menu
...
...
@@ -66,6 +67,11 @@ import chat.rocket.android.helper.ImageHelper
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.helper.AndroidPermissionsHelper
import
chat.rocket.android.helper.AndroidPermissionsHelper.getCameraPermission
import
chat.rocket.android.helper.AndroidPermissionsHelper.getWriteExternalStoragePermission
import
chat.rocket.android.helper.AndroidPermissionsHelper.hasCameraPermission
import
chat.rocket.android.helper.AndroidPermissionsHelper.hasWriteExternalStoragePermission
import
chat.rocket.android.util.TimberLogger
import
chat.rocket.android.util.extension.asObservable
import
chat.rocket.android.util.extension.createImageFile
import
chat.rocket.android.util.extensions.circularRevealOrUnreveal
...
...
@@ -912,7 +918,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
if
(
hasCameraPermission
(
it
))
{
dispatchTakePictureIntent
()
}
else
{
getCameraPermission
()
getCameraPermission
(
it
)
}
}
handler
.
postDelayed
({
...
...
@@ -932,8 +938,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_drawing
.
setOnClickListener
{
activity
?.
let
{
fragmentActivity
->
if
(!
ImageHelper
.
canWriteToExternalStorage
(
fragmentActivity
))
{
ImageHelper
.
checkWriting
Permission
(
fragmentActivity
)
if
(!
hasWriteExternalStoragePermission
(
fragmentActivity
))
{
getWriteExternalStorage
Permission
(
fragmentActivity
)
}
else
{
val
intent
=
Intent
(
fragmentActivity
,
DrawingActivity
::
class
.
java
)
startActivityForResult
(
intent
,
REQUEST_CODE_FOR_DRAW
)
...
...
@@ -967,19 +973,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
private
fun
hasCameraPermission
(
context
:
Context
):
Boolean
{
return
AndroidPermissionsHelper
.
checkPermission
(
context
,
android
.
Manifest
.
permission
.
CAMERA
)
}
private
fun
getCameraPermission
()
{
requestPermissions
(
arrayOf
(
android
.
Manifest
.
permission
.
CAMERA
),
AndroidPermissionsHelper
.
CAMERA_CODE
)
}
override
fun
onRequestPermissionsResult
(
requestCode
:
Int
,
permissions
:
Array
<
out
String
>,
grantResults
:
IntArray
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
)
Log
.
e
(
"TAG_permission"
,
requestCode
.
toString
())
when
(
requestCode
)
{
AndroidPermissionsHelper
.
CAMERA_CODE
->
{
if
((
grantResults
.
isNotEmpty
()
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
))
{
...
...
app/src/main/java/chat/rocket/android/helper/AndroidPermissionsHelper.kt
View file @
805f30fe
package
chat.rocket.android.helper
import
android.Manifest
import
android.app.Activity
import
android.content.Context
import
android.content.pm.PackageManager
import
android.view.ContextThemeWrapper
import
androidx.core.app.ActivityCompat
import
androidx.core.content.ContextCompat
...
...
@@ -11,14 +13,44 @@ object AndroidPermissionsHelper {
const
val
WRITE_EXTERNAL_STORAGE_CODE
=
1
const
val
CAMERA_CODE
=
2
fun
checkPermission
(
context
:
Context
,
permission
:
String
):
Boolean
{
private
fun
checkPermission
(
context
:
Context
,
permission
:
String
):
Boolean
{
return
ContextCompat
.
checkSelfPermission
(
context
,
permission
)
==
PackageManager
.
PERMISSION_GRANTED
}
fun
requestPermission
(
context
:
Activity
,
permission
:
String
,
requestCode
:
Int
)
{
private
fun
requestPermission
(
context
:
Activity
,
permission
:
String
,
requestCode
:
Int
)
{
ActivityCompat
.
requestPermissions
(
context
,
arrayOf
(
permission
),
requestCode
)
}
fun
hasCameraPermission
(
context
:
Context
):
Boolean
{
return
AndroidPermissionsHelper
.
checkPermission
(
context
,
Manifest
.
permission
.
CAMERA
)
}
fun
getCameraPermission
(
context
:
Context
)
{
if
(
context
is
ContextThemeWrapper
)
{
val
activity
=
if
(
context
.
baseContext
is
Activity
)
context
.
baseContext
as
Activity
else
context
as
Activity
AndroidPermissionsHelper
.
requestPermission
(
activity
,
Manifest
.
permission
.
CAMERA
,
AndroidPermissionsHelper
.
WRITE_EXTERNAL_STORAGE_CODE
)
}
}
fun
hasWriteExternalStoragePermission
(
context
:
Context
):
Boolean
{
return
checkPermission
(
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
}
fun
getWriteExternalStoragePermission
(
context
:
Context
)
{
if
(
context
is
ContextThemeWrapper
)
{
val
activity
=
if
(
context
.
baseContext
is
Activity
)
context
.
baseContext
as
Activity
else
context
as
Activity
AndroidPermissionsHelper
.
requestPermission
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
WRITE_EXTERNAL_STORAGE_CODE
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/helper/ImageHelper.kt
View file @
805f30fe
...
...
@@ -18,6 +18,8 @@ import androidx.appcompat.widget.Toolbar
import
androidx.core.net.toUri
import
androidx.core.view.setPadding
import
chat.rocket.android.R
import
chat.rocket.android.helper.AndroidPermissionsHelper.getWriteExternalStoragePermission
import
chat.rocket.android.helper.AndroidPermissionsHelper.hasWriteExternalStoragePermission
import
com.facebook.binaryresource.FileBinaryResource
import
com.facebook.cache.common.CacheKey
import
com.facebook.imageformat.ImageFormatChecker
...
...
@@ -117,8 +119,8 @@ object ImageHelper {
}
private
fun
saveImage
(
context
:
Context
):
Boolean
{
if
(!
canWriteToExternalStorage
(
context
))
{
checkWriting
Permission
(
context
)
if
(!
hasWriteExternalStoragePermission
(
context
))
{
getWriteExternalStorage
Permission
(
context
)
return
false
}
if
(
ImagePipelineFactory
.
getInstance
().
mainFileCache
.
hasKey
(
cacheKey
))
{
...
...
@@ -152,22 +154,4 @@ object ImageHelper {
}
return
true
}
fun
canWriteToExternalStorage
(
context
:
Context
):
Boolean
{
return
AndroidPermissionsHelper
.
checkPermission
(
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
}
fun
checkWritingPermission
(
context
:
Context
)
{
if
(
context
is
ContextThemeWrapper
)
{
val
activity
=
if
(
context
.
baseContext
is
Activity
)
context
.
baseContext
as
Activity
else
context
as
Activity
AndroidPermissionsHelper
.
requestPermission
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
AndroidPermissionsHelper
.
WRITE_EXTERNAL_STORAGE_CODE
)
}
}
}
\ 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