"keys" should be moved from strings.xml to keys.xml #278

eisbehr opened this Issue Jul 19, 2012 · 1 comment


None yet

2 participants


The keys (e.g. TODOTXTPATH_key) are used for storing and accessing shared preferences. Currently they are located in the strings.xml which contains the strings that are meant to be localized. As changing the keys during localization (for whatever reason) would potentially break the app (if the user changes the phone's locale), the keys shouldn't be mixed together with other strings.

I also noticed that some of the keys are used as hardcoded strings at some occasions throughout the code. When moving them to the new xml this should also be fixed.

There are also some of the shared preferences keys stored in Constants.java (The ones not used in the preference activity) that should probably be moved to the keys.xml as well

@chuckbjones chuckbjones added a commit to chuckbjones/todo.txt-touch that referenced this issue Jan 8, 2013
@chuckbjones chuckbjones Keys should be DRY
Partially fixes #278

Move sharedPreferences keys from strings.xml to keys.xml.
Remove keys from Constants.java.
Implement Keys.java to read keys from the xml file.
Use methods in Keys.java instead of hard coding the key strings
or duplicating them in Constants.java.

This is not an ideal solution, as we need a Context to look up the
key values in the resource file. A Context is not always available,
and makes the code ugly.

Will refactor into a better solution before submitting pull request.

Started working on this (see chuckbjones/todo.txt-touch@f0f568e). The only issue with putting the keys in a resource file is that we need a context in order to retrieve them (assuming we don't want to duplicate the strings in, e.g, in Constants.java). Will have to refactor the code a bit to remedy this, probably by subclassing SharedPreferences and creating dedicated methods for getting and setting the various values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment