Use ContextCompat when accessing color resources
See original GitHub issueAvoid duplicates
- This enhancement request has not already been raised before
- Enhancement request is specific for Android only, for general issues / questions that apply to iOS and Android please raise them in CWA-Wishlist
- If you are proposing a new feature, please do so in CWA-Wishlist
Current Implementation
You are already using ContextCompat
when accessing color resources at some locations, but Context.getColor
in most others, which is not compatible with API < 23.
In our fork of the app, where I am working on Android 5 support, it is a lot of manual work for me to spot calls to Context.getColor
and to replace them with a call that has the same functionality but supports API 21 (like Context.getResources().getColor
).
Suggested Enhancement
Use the utility class ContextCompat
when accessing color resources everywhere.
Expected Benefits
This would not change any functionality, but it would make things a lot easier for me as a maintainer of our fork, because there would be less discrepancies to keep track of.
If such a PR would get merged, I would like to open one to use this utility class every time color resources are accessed.
Thank you for your consideration.
Internal Tracking ID: EXPOSUREAPP-4419
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:7 (7 by maintainers)
Top GitHub Comments
Hello @dsarkar, thank you for your input; I have updated the issue to follow the template instead of closing and reopening, I hope that’s okay as well.
I did a quick search through the project and it looks okay to change. I’m not 100% sure how to handle this in unit tests, where the
getColor
calls also appear.Mock static? Or maybe mocking an extension function
Context.getColorCompat
🤔 .What would be your preferred solution @fynngodau ?
Should be against
release/1.11.x
and preferably after #1912 is merged to avoid conflicts.