permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.23k stars 1.44k forks source link

PermissionsDispatcher breaks Single Responsibility principle #561

Closed manishjaswal closed 5 years ago

manishjaswal commented 5 years ago

This is not an issue as such.

Just an observation.

PermissionsDispatcher implementation is tightly coupled with activity instance. I cannot separate permission model from activity, also I will have to reimplement permission in each activity I may want to check the permissions.

I tried defining the permissions in a separate class but I could not find a way to pass activity instance.

Is there any way I can define permissions in a separate class and use it through composition.

manishjaswal commented 5 years ago

Tried to create an interface with some default methods and annotating them with @NeedsPermission and @OnShowRationale.

I have my activity implement this interface and have annotated the activity with @RuntimePermissions.

But it seems that the annotation processor does not scan the methods from the interface.

Can annotation processor be modified to scan the default methods from an interface?

hotchemi commented 5 years ago

@manishjaswal our API design is merely based on Android framework. requestPermissions requires Activity or Fragment instance as an argument and it surely means permission handling is tightly coupled with UI for now. Of course you can encapsulate the fact but it's not our decision. We try to make API design simpler as much as we can to let user figure out what's going on under the hood.

https://developer.android.com/training/permissions/requesting

hotchemi commented 5 years ago

if you don't understand how to use the library we recommend reading README again carefully or go to stackoverflow.

manishjaswal commented 5 years ago

@hotchemi I was able to use the direct implementation as mentioned in the docs. My query was only related to the possibility of using default methods as a base implementation of permissions so that I do not have to write the same code in every class.

Anyways, existing implements does save a lot of time of developers, thanks.

tim4dev commented 5 years ago

@manishjaswal You misunderstand the Single Responsibility principle. I advise you to study the book R.C.Martin. Clean Architecture.