syncthing-android
syncthing-android copied to clipboard
Update providing of SharedPreferences
Description
Refactor a bit the way the default preferences are provided by making it more explicit they are the default ones. There are only the default ones at the moment but it may change in the future.
In the next step I'd also want to make the SyncthingModule
the single source of these SharedPreferences.
At the moment there are 19 places where PreferenceManager.getDefaultSharedPreferences(...)
is invoked.
There should be only one source of it, the SyncthingModule, and there should be only one way of getting these preferences: injecting them where needed.
Changes
- move the dagger component and module to a dedicated package
- add an annotation,
DefaultSharedPreferences
, to distinguish which preferences are provided/injected - annotate the provider function and injection sites with
DefaultSharedPreferences
Why differentiate between different SharedPrefernces?
For additional clarity.
It may not be needed now, as everything is stored inside a single instance of SharedPrefences, the default one, but we may want to change that in the future.
Ideally each feature screen that needs to store small bits of data should be able to do so in its own dedicated SharedPreferences instance (also dedicated xml file on the device) that is independent from other features.
This also helps to decouple features as it's always painful to decouple screens that are tightly coupled because of same storage.
Example:
The same key is used in five different places. Trying to modify anything related to that key in one screen may break unexpectedly functionalities in other screens.
This is fine for now, but we should strive to avoid this kind of accidental complexity in the future in my opinion.