Skip to content

Commit

Permalink
Merge pull request #40 from maortestim/skip_explanation
Browse files Browse the repository at this point in the history
Add option to show permission request without rational message.
  • Loading branch information
Kosh Sergani committed Jul 26, 2018
2 parents 93de75b + b8e4bd3 commit 04edce2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ permissionFragmentHelper
.request(isSingle ? SINGLE_PERMISSION : MULTIPLE_PERMISSIONS);
```

To request a permission without ask for explanation message even if the user press decline:
```java
permissionHelper
.setSkipExplanation(true)// true if you don't want to show expalanation message
.request(CAMERA_PERMISSION);


and finally in your `Activity/Fragment`
```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PermissionFragmentHelper implements OnActivityPermissionCallback {
@NonNull private final OnPermissionCallback permissionCallback;
@NonNull private final Fragment context;
private boolean forceAccepting;
private boolean skipExplanation;

private PermissionFragmentHelper(@NonNull Fragment context) {
this.context = context;
Expand Down Expand Up @@ -146,7 +147,7 @@ private void handleSingle(@NonNull String permissionName) {
// run time permission that does not exists in AndroidManifest.
if (!permissionName.equalsIgnoreCase(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
if (isPermissionDeclined(permissionName)) {
if (isExplanationNeeded(permissionName)) {
if (isExplanationNeeded(permissionName) && !skipExplanation) {
permissionCallback.onPermissionNeedExplanation(permissionName);
} else {
context.requestPermissions(new String[]{permissionName}, REQUEST_PERMISSIONS);
Expand Down Expand Up @@ -420,4 +421,8 @@ public static void removeGrantedPermissions(@NonNull Fragment context, @NonNull
models.removeAll(granted);
}
}

public void setSkipExplanation(boolean skipExplanation) {
this.skipExplanation = skipExplanation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PermissionHelper implements OnActivityPermissionCallback {
@NonNull private final OnPermissionCallback permissionCallback;
@NonNull private final Activity context;
private boolean forceAccepting;
private boolean skipExplanation;

private PermissionHelper(@NonNull Activity context) {
this.context = context;
Expand Down Expand Up @@ -145,7 +146,7 @@ private void handleSingle(@NonNull String permissionName) {
// run time permission that does not exists in AndroidManifest.
if (!permissionName.equalsIgnoreCase(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
if (isPermissionDeclined(permissionName)) {
if (isExplanationNeeded(permissionName)) {
if (isExplanationNeeded(permissionName) && !skipExplanation) {
permissionCallback.onPermissionNeedExplanation(permissionName);
} else {
ActivityCompat.requestPermissions(context, new String[]{permissionName}, REQUEST_PERMISSIONS);
Expand Down Expand Up @@ -417,4 +418,8 @@ public static void removeGrantedPermissions(@NonNull Context context, @NonNull L
models.removeAll(granted);
}
}

public void setSkipExplanation(boolean skipExplanation) {
this.skipExplanation = skipExplanation;
}
}

0 comments on commit 04edce2

Please sign in to comment.