prefser
prefser copied to clipboard
Auto implementing of sharedpref client-defined interface
It would be great to have a functionality to let client define interface with all his preferences (getters&setter) and then generate implementation for him. I like this idea in https://github.com/martino2k6/StoreBox.
Thanks for reporting that issue. Actually, I wanted to add such feature. It requires to create additional project (annotation processor) for code generation and it needs to be added as a second library. I think, I'll add such feature in one of the next versions of the library or as a separate project, but I cannot promise, when it'll be available.
StoreBox implements it with Proxy+InvocationHandler, which is simpler than annotation processor. But I think using interface is overkill to implement the only 1-2 lines of code:
public void put(String key, String value) {
prefs.edit().setString(key, value).apply();
}
The other hand, retrofit is suitable case of interface because it uses Proxy to wrap complicated I/O logic in it, and to handle various request parameters (@Query, @POST, ...).
Just I like simplicity of this library. :)