Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Prefs): use XML constants everywhere #17869

Merged
merged 2 commits into from
Jan 26, 2025

Conversation

BrayanDSO
Copy link
Member

Purpose / Description

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.

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 style pref 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.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@@ -30,47 +32,55 @@ import kotlin.reflect.KProperty
object Prefs {
private val sharedPrefs get() = AnkiDroidApp.sharedPrefs()

@VisibleForTesting
val resources get() = AnkiDroidApp.appResources
Copy link
Member Author

@BrayanDSO BrayanDSO Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to inline this, but I had some trouble mocking Prefs::key() to avoid trying to get the app instance

@BrayanDSO BrayanDSO marked this pull request as draft January 25, 2025 00:05
@BrayanDSO BrayanDSO marked this pull request as ready for review January 25, 2025 00:06
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
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all works for me, definitely less boilerplate this way

@mikehardy mikehardy added Needs Second Approval Has one approval, one more approval to merge cleanup Non functional change that would improve the code readability and removed Needs Review labels Jan 26, 2025
@mikehardy
Copy link
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

@mikehardy mikehardy added this pull request to the merge queue Jan 26, 2025
Merged via the queue into ankidroid:main with commit fbd6dce Jan 26, 2025
9 checks passed
@github-actions github-actions bot added this to the 2.21 release milestone Jan 26, 2025
@github-actions github-actions bot removed the Needs Second Approval Has one approval, one more approval to merge label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Non functional change that would improve the code readability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants