Skip to content

Adding permissions manager#34

Merged
amaury901130 merged 3 commits intomasterfrom
feature/permission_manager
Aug 13, 2020
Merged

Adding permissions manager#34
amaury901130 merged 3 commits intomasterfrom
feature/permission_manager

Conversation

@amaury901130
Copy link
Copy Markdown
Collaborator

Description

  • Adding permissions manager and util functions for permissions.

Screen Shot 2020-08-11 at 14 57 38

@amaury901130 amaury901130 linked an issue Aug 11, 2020 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@ximenaperez ximenaperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Copy link
Copy Markdown
Contributor

@mato2593 mato2593 left a 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!

Comment thread app/src/main/java/com/rootstrap/android/util/permissions/PermissionManager.kt Outdated
Comment on lines +25 to +26
permissionListener = listener
requestPermission(arrayOf(permission))
Copy link
Copy Markdown
Contributor

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>()
Copy link
Copy Markdown
Contributor

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
Copy link
Copy Markdown
Contributor

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?

Comment on lines +57 to +62
for (s in permissionDenied) {
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, s)) {
listener.foreverDenied()
return
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (s in permissionDenied) {
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, s)) {
listener.foreverDenied()
return
}
}
for (deniedPermission in deniedPermission) {
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, deniedPermission)) {
listener.foreverDenied()
return
}
}

Comment on lines +24 to +27
fun checkPermission(permission: String, listener: PermissionResponse) {
permissionListener = listener
requestPermission(arrayOf(permission))
}
Copy link
Copy Markdown
Contributor

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>()
Copy link
Copy Markdown
Contributor

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) {
Copy link
Copy Markdown
Contributor

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.

amaury901130 and others added 2 commits August 13, 2020 10:35
…ssionManager.kt

Co-authored-by: Mathías Cabano <cabanomathias@gmail.com>
@amaury901130 amaury901130 merged commit f6505b1 into master Aug 13, 2020
@CamilaMoscatelli CamilaMoscatelli deleted the feature/permission_manager branch November 17, 2020 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permission Manager

3 participants