Bug 1064304 - Pre: Align PrefUtils.putStringSet docstring and reality. r=rnewman

This commit is contained in:
Nick Alexander 2014-09-16 15:41:07 -07:00
Родитель 2f15da9e36
Коммит 1671bd6291
2 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -219,7 +219,7 @@ class MultiChoicePreference extends DialogPreference implements DialogInterface.
protected boolean persist(SharedPreferences.Editor edit) {
if (isPersistent()) {
Set<String> vals = getValues();
PrefUtils.putStringSet(edit, getKey(), vals);
PrefUtils.putStringSet(edit, getKey(), vals).apply();;
return true;
}

Просмотреть файл

@ -54,19 +54,27 @@ public class PrefUtils {
return new HashSet<String>();
}
// Cross version compatible way to save a string set to a pref.
// NOTE: The editor that is passed in will not commit the transaction for you. It is up to callers to commit
// when they are done with any other changes to the database.
public static SharedPreferences.Editor putStringSet(final SharedPreferences.Editor edit,
/**
* Cross version compatible way to save a set of strings.
* <p>
* This method <b>does not commit</b> any transaction. It is up to callers
* to commit.
*
* @param editor to write to.
* @param key to write.
* @param vals comprising string set.
* @return
*/
public static SharedPreferences.Editor putStringSet(final SharedPreferences.Editor editor,
final String key,
final Set<String> vals) {
if (Versions.preHC) {
final JSONArray json = new JSONArray(vals);
edit.putString(key, json.toString()).apply();
editor.putString(key, json.toString());
} else {
edit.putStringSet(key, vals).apply();
editor.putStringSet(key, vals);
}
return edit;
return editor;
}
}