https://kotlinlang.org logo
Title
z

Zaidi

10/30/2018, 9:33 AM
if there any one who can read this article and suggest me is this the best approach to implement this https://medium.com/@skydoves/how-to-manage-sharedpreferences-on-android-project-5e6d5e28fee6
g

gildor

10/30/2018, 9:33 AM
Please, do not cross-post your messages to different channels
☝️ 1
z

Zaidi

10/30/2018, 9:34 AM
yes sure i am new user sorry for the inconvenience
l

louiscad

10/30/2018, 9:48 AM
I'd advertise my solution that is simpler: https://github.com/LouisCAD/Splitties/blob/master/preferences/README.md It solves the type safety and key safety problems the vanilla approach may have.
👍 1
g

gildor

10/30/2018, 9:49 AM
Nice, we use similar approach on one of our projects, but not so generic implementation
but in our implementation we override delegate for standard preferences class, so it works like
var magicNumber: Int by somePreferencesInstance
(if default value is not required)
l

louiscad

10/30/2018, 9:56 AM
I prefer to hide the underlying risky API as much as possible, that's why I went for a wrapper
p

Paul Woitaschek

10/30/2018, 9:56 AM
What do you think about my solution posted in #general ?
g

gildor

10/30/2018, 9:56 AM
we use it only for implementation of preferences class, so it will not be visble from outer API and real implementation that requires passing preferences is not available for any code, only to DI. Also this solves problem with multiple instances (just inject Singleton instance)
l

louiscad

10/30/2018, 10:01 AM
@Paul Woitaschek I think it's good because it's type and key safe, but maybe too tied to Rx (which is great when you use Rx!). I prefer what I did in Splitties (posted above) because its just properties (which can't be simpler I think), and you can implement custom logic and make the delegated properties private if needed, so you can have anything you want, backed by type and key safe shared preferences.