Skip to content

Commit

Permalink
Merge pull request #5 from erikeelde/feature/modernize_2
Browse files Browse the repository at this point in the history
Easy permissions now callbacks if permission were previously granted
  • Loading branch information
erikeelde authored Mar 6, 2019
2 parents 9cbc22e + da7f7ba commit d841438
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions granter/src/main/java/se/eelde/granter/GranterFragment.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package se.eelde.granter;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import androidx.annotation.NonNull;
Expand All @@ -18,6 +15,7 @@
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;
import pub.devrel.easypermissions.PermissionRequest;

public class GranterFragment extends Fragment implements EasyPermissions.PermissionCallbacks {

Expand Down Expand Up @@ -47,10 +45,6 @@ static GranterFragment newInstance(@NonNull ArrayList<String> permissions, int r
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context context = getContext();
if (context == null) {
throw new IllegalStateException("Context cannot be null");
}
Bundle arguments = getArguments();
if (arguments == null) {
throw new IllegalStateException("Arguments cannot be null");
Expand All @@ -67,16 +61,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
shouldHaveShownRationale = Stolen.shouldShowRationale(this, requestedPermissions);

if (savedInstanceState == null) {
if (!EasyPermissions.hasPermissions(getContext(), requestedPermissions)) {
EasyPermissions.requestPermissions(this,
rationale,
RC_PERMISSIONS,
requestedPermissions);
} else {
int[] ints = new int[requestedPermissions.length];
Arrays.fill(ints, PackageManager.PERMISSION_GRANTED);
callback(requestedPermissions, ints);
}
PermissionRequest permissionRequest = new PermissionRequest.Builder(this, RC_PERMISSIONS, requestedPermissions).setRationale(rationale).build();
EasyPermissions.requestPermissions(permissionRequest);
}
}

Expand Down
2 changes: 1 addition & 1 deletion granter/src/main/java/se/eelde/granter/Stolen.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int[] grantsFromPermissions(@NonNull Fragment fragment, @NonNull String[]
int[] grantResults = new int[requestedPermissions.length];

for (int i = 0; i < requestedPermissions.length; i++) {
grantResults[i] = EasyPermissions.hasPermissions(fragment.getContext(), requestedPermissions[i]) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
grantResults[i] = EasyPermissions.hasPermissions(fragment.requireContext(), requestedPermissions[i]) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
}

return grantResults;
Expand Down

0 comments on commit d841438

Please sign in to comment.