{"action":"closed","issue":{"url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1926","repository_url":"https://api.github.com/repos/androidannotations/androidannotations","labels_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1926/labels{/name}","comments_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1926/comments","events_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1926/events","html_url":"https://github.com/androidannotations/androidannotations/issues/1926","id":196872026,"number":1926,"title":"Support for permissions","user":{"login":"Draftdog","id":8707823,"avatar_url":"https://avatars.githubusercontent.com/u/8707823?v=3","gravatar_id":"","url":"https://api.github.com/users/Draftdog","html_url":"https://github.com/Draftdog","followers_url":"https://api.github.com/users/Draftdog/followers","following_url":"https://api.github.com/users/Draftdog/following{/other_user}","gists_url":"https://api.github.com/users/Draftdog/gists{/gist_id}","starred_url":"https://api.github.com/users/Draftdog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Draftdog/subscriptions","organizations_url":"https://api.github.com/users/Draftdog/orgs","repos_url":"https://api.github.com/users/Draftdog/repos","events_url":"https://api.github.com/users/Draftdog/events{/privacy}","received_events_url":"https://api.github.com/users/Draftdog/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-21T08:19:13Z","updated_at":"2016-12-21T12:03:08Z","closed_at":"2016-12-21T12:03:08Z","body":"This ticket is about a feature request.\r\n\r\nCurrently there is the [PermissionsDispatcherPlugin](https://github.com/AleksanderMielczarek/AndroidAnnotationsPermissionsDispatcherPlugin) to handle requests for runtime permissions since Android 6.0. It integrates with AA but is still quite cumbersome to use.\r\nThe list of annotations can be found here: https://github.com/hotchemi/PermissionsDispatcher\r\n\r\nThe problem with the current usage is that we still need to manually delegate from our code to a static dispatcher. The dispatchers are generated by the plugin but since AA is agnostic of what actually happens it doesn't delegate the calls automatically and we have to write the same boilerplate code over and over again (once per activity and once per fragment, but only when annotated with `@RuntimePermissions`)\r\n\r\nHere's a short example to illustrate the problem, I have omitted the imports for brevity:\r\n```\r\n@RuntimePermissions\r\n@EActivity(R.layout.map_layout)\r\npublic class MapActivity extends Activity\r\n{\r\n   ...\r\n\r\n   @Click(R.id.myLocationButton)\r\n   void onMyLocationClick()\r\n   {\r\n      zoomIntoMyLocation();\r\n   }\r\n\r\n   @NeedsPermission(ACCESS_FINE_LOCATION)\r\n   void zoomIntoMyLocation()\r\n   {\r\n      // code to execute when the permission has been granted\r\n   }\r\n\r\n   @OnPermissionDenied(ACCESS_FINE_LOCATION)\r\n   void onLocationPermissionDenied()\r\n   {\r\n       // do something to handle the fact the user did not grant us this permission, e.g. a dialog\r\n   }\r\n}\r\n```\r\n\r\nThese annotations generate a `MapActivityPermissionsDispatcher` class that is to be used in `MapActivity` like so:\r\n```\r\n{\r\n\r\n   // IMPORTANT: all calls to zoomIntoMyLocation() will need to be replaced with calls to\r\n   // MapActivityPermissionsDispatcher.zoomIntoMyLocationWithCheck(MapActivity)\r\n\r\n   // we need to add this override\r\n   @Override\r\n   public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)\r\n   {\r\n      // we just need to delegate\r\n      super.onRequestPermissionsResult(requestCode, permissions, grantResults);\r\n      MapActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);\r\n   }\r\n\r\n}\r\n```\r\n\r\nI don't think I need to explain the ugliness of these calls to the dispatcher, they are error prone because it is easy to forget to replace the calls to the original (annotated) method.\r\n\r\nHowever, this is the best the plugin can do .. it cannot generate code into the same file that is generated by AA. And that's exactly why I am writing this feature request. It would already be great if AA would process the annotations and do the following:\r\n\r\n- generate the `onRequestPermissionsResult(..)` override in the `MapActivity_` subclass\r\n- generate a `zoomIntoMyLocationWithCheck()` method that will simply delegate to the dispatcher, that way we would just need to call this new method instead .. which is not too bad\r\n\r\nThe ideal, however, would be to just be able to call `zoomIntoMyLocation()` and have everything handled in the subclass somehow, but I don't think this is possible unless AA generates all of the dispatcher code in the `MapActivity_` subclass. Would this be a possibility?\r\n\r\nOne thing that comes to mind is when the activity has an AA-annotated abstract parent, if this parent also carries the `@NeedsPermission` on one of its methods then things could get ugly (since static calls don't cleanly override).\r\n\r\nAnyway, this is just a suggestion, perhaps it would be even better to just write something new, independently from the 3rd-party plugin .. any ideas?\r\n\r\nCheers\r\n-- Wouter\r\n\r\n\r\n"}}
{"actor":{"display_login":"dodgex"}}