refactor(Prefs): use XML constants everywhere#17869
Merged
mikehardy merged 2 commits intoankidroid:mainfrom Jan 26, 2025
Merged
refactor(Prefs): use XML constants everywhere#17869mikehardy merged 2 commits intoankidroid:mainfrom
mikehardy merged 2 commits intoankidroid:mainfrom
Conversation
BrayanDSO
commented
Jan 25, 2025
| private val sharedPrefs get() = AnkiDroidApp.sharedPrefs() | ||
|
|
||
| @VisibleForTesting | ||
| val resources get() = AnkiDroidApp.appResources |
Member
Author
There was a problem hiding this comment.
I want to inline this, but I had some trouble mocking Prefs::key() to avoid trying to get the app instance
AnkiDroid/src/test/java/com/ichi2/anki/analytics/PreferencesAnalyticsTest.kt
Show resolved
Hide resolved
AnkiDroid/src/test/java/com/ichi2/anki/analytics/PreferencesAnalyticsTest.kt
Show resolved
Hide resolved
d534fbe to
a297fd6
Compare
adding a preference key leads to a lot of boilerplate (mostly caused by me) because it is necessary to 1. add a constant in preferences.xml 2. add the string for analytics 3. add the string to PrefKey To reduce the boiler, `PrefKey` is being replaced with the preferences.xml constants. Since the XMLs keys can be used in both code and XMLs, keeping it as default seems like the best option. Some of PrefKey strings were just inlined to reduce the scope of the PR
mikehardy
approved these changes
Jan 26, 2025
Member
mikehardy
left a comment
There was a problem hiding this comment.
all works for me, definitely less boilerplate this way
Member
|
This is going to affect ...and I'm about to get that one in as well, I want to get this in first then I can clean up the collision in 17826 the code being moved around (or, deleted really) here is pretty new and if it needs another tuning that's fine in another PR |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Description
adding a preference key leads to a lot of boilerplate (mostly caused by me) because it is necessary to
To reduce the boiler,
PrefKeyis being replaced with the preferences.xml constants.I'm sorry for the churn, but I'm trying to clean up my own mess.
Approach
In the commits
How Has This Been Tested?
Unit Tests + checking if the
Frame stylepref works (just as an example)Learning (optional, can help others)
More random stuff around testing, like mockkObject
Checklist
Please, go through these checks before submitting the PR.