-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add new builder API and support customizing rationale dialog theme #180
Conversation
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
@SUPERCILEX this is a nice API but I am wary of making a breaking change for this (relatively) minor feature request of theme changing. The API right now is simple and has a lot of users.
Is there anything else you think we'd add to the API in the future if it was Builder-style?
@samtstern Nope, I can't think of anything. However, here's my reasoning:
requestPermissionshas way too many parameters: a common limit I've seen is 3 and then you consider a different way of passing in parameters. In our case, we can go up to 5 plus the varargs one which is unlimited. When you consider adding yet another parameter (now 6), things get tearfully messy.- We already have way too many
intparameters: the signature =requestPermissions(Host, String, int, int, int, String...). Adding the themeintturns those 3 into now 4ints in a row! - Overloads: it's getting ridiculous. To not break backwards compatibility, we need to add at least another 3 overloads. If we want to improve flexibility, we'd need to add 6 to the existing 6!
- Current API limitations: a minor pet peeve of mine has been the inability to pass in a string resource int for the rationale and vice versa for the yes and no buttons. The new builder has String/int overloads for each of those options.
- I don't see any reason to release a v2.0 anytime soon. I was basically thinking we could leave people a year or more to migrate away from the old API which should be more than enough time to migrate away from a method that's only used once per set of permissions.
@samtstern Maybe I've changed your mind? 😄 If not, we need to decide which overloads to add.
Ok I agree with you completely, I hate all the overloads and they're not scalable.
So maybe let's take a middle-road approach:
- Keep supporting the
EasyPermissions.requestPermissions(context, rationaleString, requestCode, perms)method call indefinitely. That's the most common use case (99%) and it doesn't require too many overloads. - Introduce a new method:
EasyPermissions.requestPermissions(PermissionsRequest)which uses the builder. - Mark all other overloads of
EasyPermissions.requestPermissions()as@Deprecatedso this can be just a minor version bump and won't break anyone.
@samtstern I like it, that's a perfect compromise! 😄
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can probably say something more descriptive here like "A model object that holds all of the parameters associate with a permission request, such as the request code or the rationale"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with the double cast? (PermissionHelper<Activity>) (Object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, here's the error I get otherwise:
untitled
It works just fine at runtime so I'd guess we need to use some sort of type variance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised to see the <> here, do we get a warning without that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I added a type T to the helper.
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
@SUPERCILEX awesome! I think all that's left is the README, right?
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Sweet! (Thanks for reminding me, I'd forgotten 😄)
README.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last comment:
Developers tend to copy-and-paste so I'd avoid putting both of these in the same snippet as developers will end up with double requests.
I'd say:
// old snippet here
Or for finer control over the rationale dialog, use PermissionRequest:
// new snippet here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raises hand. Haha, yeah, I've done that too. It should be fixed now.
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
#174
@samtstern What do you think of this PR? I'm using our new builder style to add the theme option. If you think the idea is good, I'll add documentation and all that good stuff and prep this PR for merging.