konmik / proxypref Goto Github PK
View Code? Open in Web Editor NEWProxyPref is an Android library, which represents SharedPreferences as an interface
License: MIT License
ProxyPref is an Android library, which represents SharedPreferences as an interface
License: MIT License
Hi. I've been using this library for a few days with dagger2 attached.
It worked fine. But as soon as I introduced Nucleous, proxyPref had broken.
Here is some code:
Proxy pref is built in NetModule:
@Module
public class NetModule {
@Provides
@Singleton
FixedPreferences providesFixedPrefs(Application application) {
return ProxyPreferences
.build(FixedPreferences.class, application.getSharedPreferences("fixedprefs", Context.MODE_PRIVATE));
}
}
My interface:
public interface FixedPreferences {
@DefaultString("a")
String getAuthToken();
void setAuthToken(String x);
@DefaultLong(0l)
Long getLastUploadUpdate();
void setLastUploadUpdate(Long x);
@DefaultLong(0l)
Long getLastDownloadUpdate();
void setLastDownloadUpdate(Long x);
}
I'm trying to inject it in BasePresenter:
public class BasePresenter<V extends NucleusAppCompatActivity> extends RxPresenter<V> {
private static final String TAG = LogUtils.makeLogTag(BasePresenter.class.getSimpleName());
@Inject
FixedPreferences pref;
@Inject
FixedRecApi fixedRecApi; //this is a Retrofit Api. It works fine with dagger2 and Nucleous.
}
Then I extends BasePresenter by other presenters I have.
Also please take into account this debug window. It says that proxyPrefs are loaded, but unaccessable.
Hi, I know that proxyPref wants boxed types in getters and setters.
Kotlin make ? sign to make primitive "boxed".
https://discuss.kotlinlang.org/t/relationship-between-classes-like-kotlin-int-and-java-integer-and-int-primitive/671
I've made this trick and still getting this error.
Is this library compatible with Kotlin?
Hey! Can you please share some example of how to use observables with proxypref.
I want to wrap all my access to shared preferences in rx chain.
// @DefaultBoolean(false)
// @Preference(PREF_ENABLE_NOTIFICATION)
Observable<Boolean> isNotificationEnabled();
// @Preference(PREF_ENABLE_NOTIFICATION)
Observable<Void> setNotificationEnabled(Boolean b);
I've tried to do this, but it gives me the error in the title.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.