You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Is there a reason why the preference fields for shared preferences do not share a common interface that exposes the get and put methods? They all extend AbstractPrefField and all implement a get and put method, but it is not enforced.
However, (to clarify why I ask this question) I am trying to create a wrapper around these preference fields to make them observable (using rxjava). It is possible to make it work as follows:
I am obliged to use reflection to get the methods I need. I know these methods are there, so I ignore error handling. Therefore, it would be better practice to simply expose these methods to avoid having to use this approach? Or maybe I am doing something wrong?
Please note the methods have different arguments, so that's why a common method is not added to the superclass. Also the parameters are primitives, so we cannot add a generic super method.
But i think we can change them to use wrapper classes, so we could use generic super methods. @DayS, @yDelouis do you think any problem with that?
The only problem I see is that in the put method, what should we do if null is given as argument ?
Should we remove the preference or should we put 0 ? (I vote for the former proposition).
Another problem is that we just provide a more cleaner wrapper for the original Android class. And the original Android class uses primitive values... I am not sure we are in a position to define a new API, and decide what happens with nulls.
Isn't the current wrapper already breaking/extending the original API? E.g. in LongPrefField allowing the preference to possibly be a string and then convert it to long? However, it is true that deciding what happens with null is not on the same level. I would suggest that using null would reset the preference to its default value.
OK, i vote for this change. But we should add JavaDoc on the superclass to document this behavior, and highlight the diff to the original Android class.
Sorry, not yet. I used my work around for now in my project for which the deadline is next week monday. So, I had no time at all to do this. However, I still planned to do it after my project deadline.
Hi,
Is there a reason why the preference fields for shared preferences do not share a common interface that exposes the get and put methods? They all extend AbstractPrefField and all implement a get and put method, but it is not enforced.
However, (to clarify why I ask this question) I am trying to create a wrapper around these preference fields to make them observable (using rxjava). It is possible to make it work as follows:
I am obliged to use reflection to get the methods I need. I know these methods are there, so I ignore error handling. Therefore, it would be better practice to simply expose these methods to avoid having to use this approach? Or maybe I am doing something wrong?
Cheers,
Christophe