Work with custom SharedPreferences implementation (#571)

Summary:
see https://github.com/facebook/flipper/issues/450
If we want to control a custom SharedPreferences, we can create a Class as SharedPreferencesDescriptor's Subclass, override the getSharedPreferences() function to return a custom SharedPreferences instance.

## Changelog
add getSharedPreferences() function in SharedPreferencesDescriptor Class
Pull Request resolved: https://github.com/facebook/flipper/pull/571

Test Plan: No

Reviewed By: jknoxville

Differential Revision: D17738675

Pulled By: passy

fbshipit-source-id: d227e7d6461194f7a01ae7b2ba53434dd71fc0d2
This commit is contained in:
s1rius
2019-10-08 01:49:27 -07:00
committed by Facebook Github Bot
parent 8f719b17e3
commit 86eb24b02c

View File

@@ -101,8 +101,7 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
}
mSharedPreferences = new HashMap<>(descriptors.size());
for (SharedPreferencesDescriptor descriptor : descriptors) {
SharedPreferences preferences =
context.getSharedPreferences(descriptor.name, descriptor.mode);
SharedPreferences preferences = descriptor.getSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
mSharedPreferences.put(preferences, descriptor);
}
@@ -252,5 +251,9 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
this.name = name;
this.mode = mode;
}
public SharedPreferences getSharedPreferences(Context context) {
return context.getSharedPreferences(name, mode);
}
}
}