Expose preference key to Converter
See original GitHub issueThe change from Adapter
to Converter
interface (#75) breaks some functionality use cases where serializing/deserializing from shared preferences depends on the preference key.
For example, I have an EncryptedPreferenceAdapter that worked as follows with the previous Adapter interface:
@Override
public Optional<T> get(@NonNull String key, @NonNull SharedPreferences preferences) {
final String serialized = preferences.getString(key, null);
if (serialized == null)
return Optional.empty();
final String decrypted = Obfuscator.decryptFromStorage(key, serialized);
return Optional.ofNullable(decrypted);
}
@Override
public void set(@NonNull String key, @NonNull Optional<T> optionalValue, @NonNull SharedPreferences.Editor editor) {
if (optionalValue.isPresent()) {
editor.putString(key, Obfuscator.encryptForStorage(key, optionalValue.get()));
}
else {
editor.putString(key, null);
}
}
Can Converters be updated to provide the preference key? Or can adapters be resurrected since there may be apps out in the wild that have adapters serializing to non-string types?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Inspecting the View Tree – Part 1: PreferenceKey
Introducing PreferenceKey · Value: is a typealias that indicates what type of information we want to expose through the preference. · defaultValue ...
Read more >Working with Preferences DataStore - Android Developers
DataStore is a new and improved data storage solution aimed at replacing SharedPreferences. Built on Kotlin coroutines and Flow, DataStore ...
Read more >Add a preference key to NSViewPepresentable ...
I have an instance of a custom AppKit/UIKit view, wrapped into an **ViewRepresentable that needs to communicate some diagnostic information up ...
Read more >IVIanuu/auto-rx-preferences: [DEPRECATED] Annotation ... - GitHub
Create a class and annotate it with the @Preferences annotation. Create some fields and annotate them with the @Key annotation. The class should...
Read more >EXPOSE to ETH Converter | ETH to EXPOSE Calculator | Nomics
Want Daily Price Updates? · Select your delivery preferences · Verify your email · Customize your newsletter and track additional cryptocurrencies.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the converter interface is very good. And your case is quite specific. Because I think that for you it will be a good option that something like this:
What say?
Gonna close this out, don’t have any plans to change this soon and I think there are a few options to make this work if needed (e.g. https://github.com/f2prateek/rx-preferences/issues/100#issuecomment-342676597).