fix: use standard res-auto namespace for app attributes#20022
fix: use standard res-auto namespace for app attributes#20022BrayanDSO merged 1 commit intoankidroid:mainfrom
Conversation
BrayanDSO
left a comment
There was a problem hiding this comment.
Haven't tested, but the code looks good
BrayanDSO
left a comment
There was a problem hiding this comment.
Needs fixing in IncrementerNumberRangePreference as well
| val resAuto = attrs.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "min", Int.MIN_VALUE) | ||
| if (resAuto != Int.MIN_VALUE) return resAuto | ||
|
|
||
| return attrs.getAttributeIntValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "min", 0) |
There was a problem hiding this comment.
Is there a reason AnkiDroidApp.XML_CUSTOM_NAMESPACE is still in use?
There was a problem hiding this comment.
It’s still used for backwards compatibility with legacy android.preference.* preferences (NumberRangePreference, StepsPreference) that read custom attrs via getAttribute*Value(namespaceUri, ...). I’m reading res-auto first and keeping AnkiDroidApp.XML_CUSTOM_NAMESPACE as a fallback to avoid breaking any older XML.
Would you like me to remove the legacy namespace support from this and the StepsPreference code?
There was a problem hiding this comment.
As far as I understand it, Brayan would like the entire namespace gone.
The details of custom XML namespaces in Android aren't something I'm familiar with, but I can't see a reason we'd want to keep it if the default app: namespace would work, and from a high-level perspective, removing the whole namespace is cleaner architecturally.
@BrayanDSO am I correct in my thinking here?
There was a problem hiding this comment.
If it's only used at cram_deck_options, it can be ignored since #19669 will be merged soon.
About the rest, I couldn't have said it better myself.
AnkiDroid/src/main/java/com/ichi2/preferences/NumberRangePreferenceCompat.kt
Show resolved
Hide resolved
|
Now I am using |
david-allison
left a comment
There was a problem hiding this comment.
as-per comment
Please check the 'files changed' before submitting so we're reviewing a clean & final change
| <attr name="summaryFormat" format="string"/> | ||
| </declare-styleable> | ||
|
|
||
| <declare-styleable name="NumberRangePreferenceCompat"> |
There was a problem hiding this comment.
This appears to be unused. I would have expected a declare-styleable for each preference, rather than using the hardcoded namespace.
Why did you choose the namespace option?
There was a problem hiding this comment.
Yes this is unused because I'm not reading min/max via R.styleable in preference, I used http://schemas.android.com/apk/res-auto as a shortcut.
Should I define a declare-styleable for each preference(NumberRangePreference, NumberRangePreferenceCompat & StepsPreference) and read attributes via R.styleable, instead of using the namespace approach?
There was a problem hiding this comment.
I don't get why you chose the hardcoded namespace option. It's not something I'm too familiar with.
declare-styleable seems better intuitively, but I want to understand your reasoning.
There was a problem hiding this comment.
Actually I did it this way because the preference was using XML_CUSTOM_NAMESPACE so I thought to use RES_AUTO_NAMESPACE the similar way. But now I will use declare-styleable which is better and update the code accordingly.
david-allison
left a comment
There was a problem hiding this comment.
cheers. Needs squashing
| <attr name="min" /> | ||
| <attr name="max"/> |
fix NumberRangePreference remove XML_CUSTOM_NAMESPACE used RES_AUTO_NAMESPACE everywhere its needed and change app1 to app Remove RES_AUTO_NAMESPACE and instead used declare-styleable fix spacing in attrs.xml



Purpose / Description
Some preference XML files used a deprecated custom app namespace URI (http://arbitrary.app.namespace/com.ichi2.anki) instead of the standard http://schemas.android.com/apk/res-auto and/or a non-standard prefix (
app1) for custom attributes.This caused aapt to fail resolving custom attributes and resulted in build errors like attribute max not found.
Fixes
app1in preferences #20018Approach
Replaced the deprecated
appnamespace URI with the standardxmlns:app="http://schemas.android.com/apk/res-auto"in affected preference XML files.Renamed the custom attribute prefix from
app1toappso the custom attributes resolve consistently viares-auto.How Has This Been Tested?
Tested on Android Studio emulator: Medium Phone, API 29 (Android 10).
Verified the affected preference screens load correctly and the app builds without aapt attribute/namespace errors.
Checklist
Please, go through these checks before submitting the PR.