{"action":"created","issue":{"url":"https://api.github.com/repos/dkunzler/esperandro/issues/30","labels_url":"https://api.github.com/repos/dkunzler/esperandro/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/dkunzler/esperandro/issues/30/comments","events_url":"https://api.github.com/repos/dkunzler/esperandro/issues/30/events","html_url":"https://github.com/dkunzler/esperandro/issues/30","id":63519925,"number":30,"title":"Get rid of repeated SDK version checks","user":{"login":"scompt","id":277576,"avatar_url":"https://avatars.githubusercontent.com/u/277576?v=3","gravatar_id":"","url":"https://api.github.com/users/scompt","html_url":"https://github.com/scompt","followers_url":"https://api.github.com/users/scompt/followers","following_url":"https://api.github.com/users/scompt/following{/other_user}","gists_url":"https://api.github.com/users/scompt/gists{/gist_id}","starred_url":"https://api.github.com/users/scompt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scompt/subscriptions","organizations_url":"https://api.github.com/users/scompt/orgs","repos_url":"https://api.github.com/users/scompt/repos","events_url":"https://api.github.com/users/scompt/events{/privacy}","received_events_url":"https://api.github.com/users/scompt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-22T10:33:24Z","updated_at":"2015-03-22T12:53:18Z","closed_at":null,"body":"Thanks for creating this project. We're using it in our and and we're quite happy with it.\r\n\r\nThere's one thing I'd like to get rid of if possible. In all of the editing calls, since #11, there's a check of the current SDK version to see if it's possible to call `apply()`:\r\n\r\n    @Override\r\n    @SuppressLint(\"NewApi\")\r\n    public void registrationId(String registrationId) {\r\n      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {\r\n        preferences.edit().putString(\"registrationId\", registrationId).commit();\r\n      } else {\r\n        preferences.edit().putString(\"registrationId\", registrationId).apply();\r\n      }\r\n    }\r\n\r\nOur app is has a minSdkVersion of 15, so these calls are useless. I figure there are three ways to get rid of them:\r\n\r\n1. Generate 2 implementations of the preference interface: one for Gingerbread containing `apply()` and one for pre-Gingerbread containing `commit()`. In the constructor of `Esperandro`, the current SDK could be checked and the suffix could be determined to be `$$GingerbreadImpl` or `$$PreGingerbreadImpl`. The benefit of this approach is that there would only be one SDK check per execution. The downside is that there would be twice as many classes generated and deployed with the APK. A note could be added to the README with the necessary ProGuard lines to delete the pre-Gingerbread implementations if the minSdkVersion is 9 or above.\r\n\r\n2. Instead of, or in addition to approach 1 would be to detect the minSdkVersion in the annotation processor and not generate the `commit()` calls if the minSdkVersion is 9 or above. I'm not sure how easy it is to get the minSdkVersion from the processor, so this might be impossible.\r\n\r\n3. Just get rid of the calls to `commit()` completely and say that Esperandro can only be used when minSdkVersion is 9 or above. :-)\r\n\r\nIf you have a preferred approach, I'd be willing to implement it if it would be merged."},"comment":{"url":"https://api.github.com/repos/dkunzler/esperandro/issues/comments/84601325","html_url":"https://github.com/dkunzler/esperandro/issues/30#issuecomment-84601325","issue_url":"https://api.github.com/repos/dkunzler/esperandro/issues/30","id":84601325,"user":{"login":"dkunzler","id":2612940,"avatar_url":"https://avatars.githubusercontent.com/u/2612940?v=3","gravatar_id":"","url":"https://api.github.com/users/dkunzler","html_url":"https://github.com/dkunzler","followers_url":"https://api.github.com/users/dkunzler/followers","following_url":"https://api.github.com/users/dkunzler/following{/other_user}","gists_url":"https://api.github.com/users/dkunzler/gists{/gist_id}","starred_url":"https://api.github.com/users/dkunzler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkunzler/subscriptions","organizations_url":"https://api.github.com/users/dkunzler/orgs","repos_url":"https://api.github.com/users/dkunzler/repos","events_url":"https://api.github.com/users/dkunzler/events{/privacy}","received_events_url":"https://api.github.com/users/dkunzler/received_events","type":"User","site_admin":false},"created_at":"2015-03-22T12:53:18Z","updated_at":"2015-03-22T12:53:18Z","body":"ACK.\r\n\r\nSaves a lot of complexity on the processor side and some calculations at runtime.\r\nIf someone does it, I will merge and release asap. Otherwise try to do it within the next three days."}}