File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
quickpermissions/src/main/java/com/livinglifetechway/quickpermissions/aspect Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -48,16 +48,18 @@ class PermissionsManager {
4848
4949 Log .d(TAG , " permissions to check: " + permissions)
5050
51- // cast target to context
51+ // get target
5252 val target = joinPoint.target
53- var context: Context ? = null
54- if (target is Context ) {
55- context = target
56- }
5753
58- if (context != null && (context is AppCompatActivity || context is Fragment )) {
54+ if (target != null && (target is AppCompatActivity || target is Fragment )) {
5955 Log .d(TAG , " weaveJoinPoint: context found" )
6056
57+ val context = when (target) {
58+ is Context -> target
59+ is Fragment -> target.context
60+ else -> null
61+ }
62+
6163 // check if we have the permissions
6264 if (PermissionUtil .hasSelfPermission(context, permissions)) {
6365 Log .d(TAG , " weaveJoinPoint: already has required permissions. Proceed with the execution." )
@@ -155,7 +157,7 @@ class PermissionsManager {
155157 // context is null
156158 // cannot handle the permission checking from the any class other than AppCompatActivity/Fragment
157159 // crash the app RIGHT NOW!
158- throw IllegalStateException (" Found " + context !! ::class .java.canonicalName + " : No support from any classes other than AppCompatActivity/Fragment" )
160+ throw IllegalStateException (" Found " + target !! ::class .java.canonicalName + " : No support from any classes other than AppCompatActivity/Fragment" )
159161 }
160162 return null
161163 }
You can’t perform that action at this time.
0 commit comments