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

Refactor to delegate to helpers #110

Merged
merged 5 commits into from
Apr 21, 2017

Conversation

samtstern
Copy link
Contributor

Makes the EasyPermissions class less of a monster and centralizes switching on API version or host object class.

Copy link
Contributor

@SUPERCILEX SUPERCILEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty sweet refactor, it makes the EasyPermissions class way nicer! 😁

The one issue I see that would make me hesitate to update to v0.4 is that we're back to passing in Objects instead of the type checked Activitys and Fragments. I've elaborated further below.

*/
public static void requestPermissions(@NonNull Activity activity,
public static void requestPermissions(@NonNull Object host,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samtstern I feel like this is a step backwards in terms of the library's usability for the end user. I really liked the fact that v0.3 of EP had overloads for the activities and fragments. I do understand that you're trying to simplify the main EP class, but I feel like the priority is making a nice, type checked api for the end user.

In addition, you have PermissionHelper.newInstance(object) setup to accept any object without fuss so adding the other method overloads wouldn't require much extra work. (Excluding documentation copypasta)

private T mHost;

@NonNull
public static PermissionHelper getInstance(Object host) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name confused before I looked at its implementation: I think it should be called newInstance. Otherwise, it looks like you're getting a single PermissionHelper instance per Activity/Fragment (which set off alarm bells in my mind about memory leaks 🙀)

// ============================================================================

public PermissionHelper(@NonNull T host) {
this.mHost = host;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: this is why I like hungarian notation, no need to use this. 😁

@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean somePermissionDenied(@NonNull android.app.Fragment fragment, @NonNull String[] perms) {
return shouldShowRationale(fragment, perms);
public static boolean somePermissionDenied(@NonNull Object host, @NonNull String[] perms) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're refactoring, I just noticed: why aren't we using vargs? It would be a small yet sweet improvement.

@samtstern
Copy link
Contributor Author

@SUPERCILEX thanks for taking a look. You're right, keeping types is worth it (I was being lazy). Pretty sure I now have things to a point where we have no casting to Object or using instanceof at all while keeping 100% compatibility with the old API!

@samtstern
Copy link
Contributor Author

screenshot from 2017-04-21 13 40 46

@SUPERCILEX
Copy link
Contributor

@samtstern Awesome!!! 😁

PS: how did you generate that compatibility report? It looks really cool!

@samtstern
Copy link
Contributor Author

samtstern commented Apr 21, 2017

@SUPERCILEX I found this really cool tool the other day:
https://github.com/lvc/japi-compliance-checker

Here's my lame script for using it

# Variables
VERSION_1="0.3.1"
VERSION_2="0.4.0"

# Copy the two AARs into your local directory
cp ~/.m2/repository/pub/devrel/easypermissions/$VERSION_1/easypermissions-$VERSION_1.aar .
cp ~/.m2/repository/pub/devrel/easypermissions/$VERSION_2/easypermissions-$VERSION_2.aar .

# Unzip them into temp directories
mkdir $VERSION_1 $VERSION_2
unzip -d $VERSION_1 easypermissions-$VERSION_1.aar
unzip -d $VERSION_2 easypermissions-$VERSION_2.aar

# Compare them
japi-compliance-checker --lib=easypermissions \
  $VERSION_1/classes.jar $VERSION_2/classes.jar

@samtstern samtstern merged commit 1eb301d into googlesamples:master Apr 21, 2017
@SUPERCILEX
Copy link
Contributor

@samtstern Ooooooooo, that's really cool! I'll have to check it out with FirebaseUI v2.0 to see what it generates.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants