feat: resource additions & API improvements (cleaned up from #15)#16
Merged
Conversation
…ts, code quality New resource types: - fraction (addFraction) - int-quantity / int-quantity-array (addIntQuantity, addIntQuantityArray) - color-array (addColorArray) - bool-array (addBoolArray) - reference (addReference with Reference data class) API improvements: - addColor(name, Int) overload for integer color values - buildBytes() for ByteArray output - create(file, indent, elementType) for font-family files - translatable attribute on addStringArray and addTypedArray - format attribute on addStyle - FontFamilyRes data class with addFontFamilyRes method Code quality: - Replace manual format string concatenation with joinToString - Remove stale 'Does this mess up ordering?' comments - Expand add(type, name, value) to support FRACTION, COLOR_ARRAY, BOOL_ARRAY - Update add(type) doc to reflect expanded support Tests: 13 new test files, 73 total tests passing README: Updated with all new features and examples
…docs Keeps the additions from the comprehensive-improvements work that produce valid Android resource XML and removes the ones aapt2 would reject. Removed (emitted non-standard XML): - FontFamilyRes / addFontFamilyRes — produced @font/<int>, which never resolves (a resource id can't be turned back into @font/name) - int-quantity / int-quantity-array and the Quantity class — not Android resource types (plurals are string-only) - color-array / bool-array — not real resource types - the corresponding Type enum entries, plus the unused REFERENCE constant Kept and fixed: - Reference.type is now required; a type-less @name is not a valid reference - add() drops the COLOR_ARRAY/BOOL_ARRAY branches, keeps FRACTION - README: corrected the addColor(Int) examples (wrong output comment, and the 0xFF0000FF literal is a Long that did not compile against the Int overload), and removed docs for the non-existent addString(comment=) API - tests: replaced no-op assert() with golden-file / assertTrue assertions Retained valid additions: fraction, reference, addColor(Int), buildBytes, translatable on arrays, style format, and create(file, indent, elementType). All 61 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
No correct use in a build-time resource generator: the documented R.color.* example is a resource id, not a color value, and would format to garbage; it silently dropped alpha so it couldn't express #AARRGGBB; and addColor(String) already covers the real cases. Removes the method, its tests, golden files, and README section. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Supersedes #15 — same valid additions, with the invalid-XML features removed and the docs/tests fixed. Branched from that work so contributor history is preserved.
Adds (valid, tested)
fractionresourcereferenceresource (<item type="reference">;typeis required)buildBytes()→ByteArraytranslatable = falseon string-array / typed-arrayformatattribute on stylescreate(file, indent, elementType)for font-family filesjoinToStringcleanup of the attrformatbuilderRemoved from #15 (aapt2 rejects these / no valid use)
FontFamilyRes— emitted@font/<int>; a resource id can't become@font/nameint-quantity/int-quantity-array— not Android resource types (plurals are string-only)color-array/bool-array— not real resource types (use<array>/<integer-array>)addColor(name, Int)— no correct use in a build-time generator (anR.color.*id isn't a color value, and it silently dropped alpha); useaddColor(name, String)addString(comment = …)APIFixes
Reference.typenow required — a type-less@nameisn't a valid referenceassert(...)tests converted to golden-file /assertTrueassertionsVerification
./gradlew test→ BUILD SUCCESSFUL, 58 tests passing.🤖 Generated with Claude Code