Skip to content

Commit

Permalink
Add Support for fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtan403 committed Feb 15, 2018
1 parent 9f214b9 commit 763a315
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ class PermissionsManager {

Log.d(TAG, "permissions to check: " + permissions)

// cast target to context
// get target
val target = joinPoint.target
var context: Context? = null
if (target is Context) {
context = target
}

if (context != null && (context is AppCompatActivity || context is Fragment)) {
if (target != null && (target is AppCompatActivity || target is Fragment)) {
Log.d(TAG, "weaveJoinPoint: context found")

val context = when (target) {
is Context -> target
is Fragment -> target.context
else -> null
}

// check if we have the permissions
if (PermissionUtil.hasSelfPermission(context, permissions)) {
Log.d(TAG, "weaveJoinPoint: already has required permissions. Proceed with the execution.")
Expand Down Expand Up @@ -155,7 +157,7 @@ class PermissionsManager {
// context is null
// cannot handle the permission checking from the any class other than AppCompatActivity/Fragment
// crash the app RIGHT NOW!
throw IllegalStateException("Found " + context!!::class.java.canonicalName + " : No support from any classes other than AppCompatActivity/Fragment")
throw IllegalStateException("Found " + target!!::class.java.canonicalName + " : No support from any classes other than AppCompatActivity/Fragment")
}
return null
}
Expand Down

0 comments on commit 763a315

Please sign in to comment.