Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 42056a1

Browse files
jmarkovicsamtstern
authored andcommitted
Remove suitability check for calling object after permission result callback (#39)
1 parent e2062b4 commit 42056a1

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

easypermissions/src/main/java/pub/devrel/easypermissions/EasyPermissions.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,18 @@ public static boolean permissionPermanentlyDenied(Object object, String deniedPe
193193
* {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}
194194
* method.
195195
* <p>
196-
* If any permissions were granted or denied, the Activity will receive the appropriate
196+
* If any permissions were granted or denied, the {@code object} will receive the appropriate
197197
* callbacks through {@link PermissionCallbacks} and methods annotated with
198198
* {@link AfterPermissionGranted} will be run if appropriate.
199199
*
200200
* @param requestCode requestCode argument to permission result callback.
201201
* @param permissions permissions argument to permission result callback.
202202
* @param grantResults grantResults argument to permission result callback.
203-
* @param object the calling Activity or Fragment.
204-
* @throws IllegalArgumentException if the calling Activity does not implement
205-
* {@link PermissionCallbacks}.
203+
* @param receivers an array of objects that have a method annotated with {@link AfterPermissionGranted}
204+
* or implement {@link PermissionCallbacks}.
206205
*/
207206
public static void onRequestPermissionsResult(int requestCode, String[] permissions,
208-
int[] grantResults, Object object) {
209-
210-
checkCallingObjectSuitability(object);
207+
int[] grantResults, Object... receivers) {
211208

212209
// Make a collection of granted and denied permissions from the request.
213210
ArrayList<String> granted = new ArrayList<>();
@@ -221,25 +218,28 @@ public static void onRequestPermissionsResult(int requestCode, String[] permissi
221218
}
222219
}
223220

224-
// Report granted permissions, if any.
225-
if (!granted.isEmpty()) {
226-
// Notify callbacks
227-
if (object instanceof PermissionCallbacks) {
228-
((PermissionCallbacks) object).onPermissionsGranted(requestCode, granted);
221+
// iterate through all receivers
222+
for (Object object : receivers) {
223+
// Report granted permissions, if any.
224+
if (!granted.isEmpty()) {
225+
if (object instanceof PermissionCallbacks) {
226+
((PermissionCallbacks) object).onPermissionsGranted(requestCode, granted);
227+
}
229228
}
230-
}
231229

232-
// Report denied permissions, if any.
233-
if (!denied.isEmpty()) {
234-
if (object instanceof PermissionCallbacks) {
235-
((PermissionCallbacks) object).onPermissionsDenied(requestCode, denied);
230+
// Report denied permissions, if any.
231+
if (!denied.isEmpty()) {
232+
if (object instanceof PermissionCallbacks) {
233+
((PermissionCallbacks) object).onPermissionsDenied(requestCode, denied);
234+
}
236235
}
237-
}
238236

239-
// If 100% successful, call annotated methods
240-
if (!granted.isEmpty() && denied.isEmpty()) {
241-
runAnnotatedMethods(object, requestCode);
237+
// If 100% successful, call annotated methods
238+
if (!granted.isEmpty() && denied.isEmpty()) {
239+
runAnnotatedMethods(object, requestCode);
240+
}
242241
}
242+
243243
}
244244

245245
@TargetApi(23)

0 commit comments

Comments
 (0)