Skip to content

Commit

Permalink
fixed dispatcher behavior when rationale is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofelletti committed Dec 8, 2022
1 parent b435dcb commit 2eff62c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Permissions
[![](https://jitpack.io/v/lorenzofelletti/permissions.svg)](https://jitpack.io/#lorenzofelletti/permissions)

## Easy permissions management library for Android

An easy to use permissions management library.
An easy to use permissions management library designed to be used with Kotlin.

The library is deployed on JitPack here, follow the steps indicated in the link to add it to your project.

To use it, just:
To use it in your project, just:
* Declare the permissions your app will use in your application's Manifest
* Example: add to the app `AndroidManifest.xml`
```xml
Expand Down
2 changes: 1 addition & 1 deletion permissions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ publishing {
release(MavenPublication) {
groupId 'com.github.lorenzofelletti'
artifactId 'permissions'
version '0.3.0'
version '0.3.1'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,23 @@ class PermissionManager(val activity: Activity) {
}

if (shouldShowRationale && !comingFromRationale) {
requestResultsDispatcher.getOnShowRationale(requestCode)
?.invoke(permissionsNotGranted.toList(), requestCode)
dispatchRationale(permissionsNotGranted, requestCode)
} else {
ActivityCompat.requestPermissions(activity, permissionsNotGranted, requestCode)
}
}
}

private fun dispatchRationale(permissionsNotGranted: Array<out String>, requestCode: Int) {
val toInvoke = requestResultsDispatcher.getOnShowRationale(requestCode) ?: fun(
_: List<String>,
requestCode: Int
) {
checkRequestAndDispatch(requestCode, true)
}
toInvoke.invoke(permissionsNotGranted.toList(), requestCode)
}

/**
* Checks whether a set of permissions is granted or not.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DispatcherEntry(
/**
* The rationale to be shown
*/
var onShowRationale: (List<String>, requestCode: Int) -> Unit = { _, _ -> }
var onShowRationale: ((List<String>, requestCode: Int) -> Unit)? = null
private set

override fun equals(other: Any?): Boolean {
Expand Down

0 comments on commit 2eff62c

Please sign in to comment.