Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

SharefPref StringSet implementation #962

Merged

Conversation

WonderCsabo
Copy link
Member

This is implementing #264. The code is based on #543, but i changed the serialization to XML, as the conversion has come to this.

@WonderCsabo WonderCsabo changed the title SharefPreferences StringSet implementation SharefPref StringSet implementation Apr 9, 2014
Conflicts:
	AndroidAnnotations/functional-test-1-5-tests/src/test/java/org/androidannotations/test15/prefs/PrefsActivityTest.java
@WonderCsabo
Copy link
Member Author

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);
Copy link
Contributor

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);
}

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Contributor

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 ?

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Contributor

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

DayS added a commit that referenced this pull request Jun 9, 2014
@DayS DayS merged commit ccf9742 into androidannotations:develop Jun 9, 2014
@DayS
Copy link
Contributor

DayS commented Jun 9, 2014

Seems good. Good job 👍

@WonderCsabo WonderCsabo deleted the 264_sharedpref_string_set branch June 9, 2014 19:04
@yDelouis yDelouis added this to the 3.1 milestone Aug 23, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants