prefser icon indicating copy to clipboard operation
prefser copied to clipboard

Auto implementing of sharedpref client-defined interface

Open semanticer opened this issue 10 years ago • 2 comments

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.

semanticer avatar May 27 '15 22:05 semanticer

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.

pwittchen avatar May 28 '15 11:05 pwittchen

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. :)

ypresto avatar Aug 05 '15 01:08 ypresto