-
Notifications
You must be signed in to change notification settings - Fork 6
Adding permissions manager #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea of encapsulating permissions logic in one place, good job!
app/src/main/java/com/rootstrap/android/util/permissions/PermissionManager.kt
Outdated
Show resolved
Hide resolved
permissionListener = listener | ||
requestPermission(arrayOf(permission)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call checkPermissions(arrayOf(permission), listener)
to keep the logic in one place.
return | ||
} | ||
|
||
val permissionDenied = mutableListOf<String>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this deniedPermissions
.
} | ||
} | ||
|
||
val granted = permissionDenied.size == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use isEmpty
or something equivalent instead?
for (s in permissionDenied) { | ||
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, s)) { | ||
listener.foreverDenied() | ||
return | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (s in permissionDenied) { | |
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, s)) { | |
listener.foreverDenied() | |
return | |
} | |
} | |
for (deniedPermission in deniedPermission) { | |
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, deniedPermission)) { | |
listener.foreverDenied() | |
return | |
} | |
} |
fun checkPermission(permission: String, listener: PermissionResponse) { | ||
permissionListener = listener | ||
requestPermission(arrayOf(permission)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as in the activity.
return | ||
} | ||
|
||
val permissionDenied = mutableListOf<String>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, deniedPermissions
.
when { | ||
granted -> listener.granted() | ||
else -> { | ||
for (s in permissionDenied) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we should give the constant a more descriptive name than s
. It should be called deniedPermission
.
…ssionManager.kt Co-authored-by: Mathías Cabano <cabanomathias@gmail.com>
Description