SharefPref StringSet implementation #962
SharefPref StringSet implementation #962
Conversation
…tring_set Conflicts: AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/SharedPrefProcessor.java
… into 264_sharedpref_string_set Conflicts: AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/prefs/SomePrefs.java
…ef_string_set Conflicts: AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/SharedPrefProcessor.java
Conflicts: AndroidAnnotations/functional-test-1-5-tests/src/test/java/org/androidannotations/test15/prefs/PrefsActivityTest.java
PR is updated and ready to be merged. |
try { | ||
Class<Editor> cls = SharedPreferences.Editor.class; | ||
return cls.getMethod("apply"); | ||
return invoke(sGetStringSetMethod, preferences, key, defValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using the same trick than android-support libraries ? It may be something like this :
public static Set<String> getStringSet(SharedPreferences preferences, String key, Set<String> defValues) {
if (Build.VERSION.SDK_INT >= 11) {
return getStringSetNative(preferences, key, defValues);
else {
String serializedSet = preferences.getString(key, null);
return SetXmlSerializer.deserialize(serializedSet);
}
}
@TargetApi(11)
public static Set<String> getStringSetNative(SharedPreferences preferences, String key, Set<String> defValues) {
return preferences.getStringSet(key, defValues);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this Reflection method was already used for SharedPreferences.Editor.apply()
before my PR, i just followed that. But you are right, i'll use the API level so we can get rid of reflection and the whole SharedPreferencesCompat
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, i am stupid... We use Reflection because we are linking agains Android 1.6 where these methods do not exist so we cannot call them directly...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right.. Now, the question is : should we stick to this version ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question indeed. I opened #1039 to discuss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a long-awaited feature. What about merging the current implementation and creating a follow-up commit if we will change the Android version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this. I'll review it this afternoon
SharefPref StringSet implementation
Seems good. Good job 👍 |
This is implementing #264. The code is based on #543, but i changed the serialization to XML, as the conversion has come to this.