Skip to content

Commit

Permalink
Clean up dependencies in Granter before PR of main project
Browse files Browse the repository at this point in the history
  • Loading branch information
erikeelde committed Sep 15, 2017
1 parent cbaf753 commit 04fd3fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
7 changes: 0 additions & 7 deletions granter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android {
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
Expand All @@ -26,11 +25,5 @@ android {
dependencies {
implementation 'com.android.support:appcompat-v7:26.0.2'

annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9"

implementation 'android.arch.lifecycle:runtime:1.0.0-alpha9'
implementation 'android.arch.lifecycle:extensions:1.0.0-alpha9'

api 'pub.devrel:easypermissions:1.0.0'

}
28 changes: 7 additions & 21 deletions granter/src/main/java/se/eelde/granter/Stolen.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/**
* "Stolen" from EasyPermissions. If the time presents itself we should arrange a PR
* towards Easypermissions to provide this functionality.
*/
class Stolen {
static void callGrantedCallback(Object callee, int requestCode, List<String> perms) {
if (callee instanceof EasyPermissions.PermissionCallbacks) {
Expand All @@ -26,16 +30,13 @@ static void callDeniedCallback(Object callee, int requestCode, List<String> perm

static void callAnnotations(Object object, int requestCode) {
Class clazz = object.getClass();
if (isUsingAndroidAnnotations(object)) {
clazz = clazz.getSuperclass();
}

while (clazz != null) {
for (Method method : clazz.getDeclaredMethods()) {
AfterPermissionGranted ann = method.getAnnotation(AfterPermissionGranted.class);
if (ann != null) {
AfterPermissionGranted annotation = method.getAnnotation(AfterPermissionGranted.class);
if (annotation != null) {
// Check for annotated methods with matching request code.
if (ann.value() == requestCode) {
if (annotation.value() == requestCode) {
// Method must be void so that we can invoke it
if (method.getParameterTypes().length > 0) {
throw new RuntimeException(
Expand All @@ -59,21 +60,6 @@ static void callAnnotations(Object object, int requestCode) {
}
}

/**
* Determine if the project is using the AndroidAnnotations library.
*/
private static boolean isUsingAndroidAnnotations(@NonNull Object object) {
if (!object.getClass().getSimpleName().endsWith("_")) {
return false;
}
try {
Class clazz = Class.forName("org.androidannotations.api.view.HasViews");
return clazz.isInstance(object);
} catch (ClassNotFoundException e) {
return false;
}
}

static boolean shouldShowRationale(Fragment fragment, String[] permissions) {
for (String permission : permissions) {
if (fragment.shouldShowRequestPermissionRationale(permission)) {
Expand Down

0 comments on commit 04fd3fe

Please sign in to comment.