ADFA-3813 | Fix OCR image metadata parsing and refactor CV domain#1300
ADFA-3813 | Fix OCR image metadata parsing and refactor CV domain#1300jatezzz wants to merge 3 commits into
Conversation
…omain logic into use cases.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR refactors the computer-vision architecture by decomposing a monolithic repository and geometry processor into a simplified repository interface, domain use cases, and focused geometry utilities. It removes ChangesRepository Layer Refactoring
Geometry and Layout Utilities Decomposition
Domain Use Cases Layer
Converter and XML Generator Updates
ViewModel and DI Integration
Minor Logic Fix
Sequence Diagram(s)sequenceDiagram
participant ViewModel as ComputerVisionViewModel
participant PrepareUC as PrepareImageUC
participant RunVisionUC as RunVisionUC
participant VisionRepo as VisionRepository
participant YoloSource as YoloModelSource
participant OCRSource as OcrSource
participant GenerateUC as GenerateXmlUC
participant Converter as YoloToXmlConverter
ViewModel->>PrepareUC: invoke(uri)
activate PrepareUC
PrepareUC->>PrepareUC: decode & rotate image
PrepareUC->>PrepareUC: compute left/right boundaries
PrepareUC-->>ViewModel: Result<PreparedImage>
deactivate PrepareUC
ViewModel->>RunVisionUC: invoke(bitmap, leftPct, rightPct, onProgress)
activate RunVisionUC
RunVisionUC->>VisionRepo: detectWidgets(bitmap)
activate VisionRepo
VisionRepo->>YoloSource: runInference(bitmap)
YoloSource-->>VisionRepo: List<DetectionResult>
VisionRepo-->>RunVisionUC: Result<List<DetectionResult>>
deactivate VisionRepo
RunVisionUC->>VisionRepo: recognizeText(bitmap)
activate VisionRepo
VisionRepo->>OCRSource: recognize(bitmap)
OCRSource-->>VisionRepo: List<TextBlock>
VisionRepo-->>RunVisionUC: Result<List<TextBlock>>
deactivate VisionRepo
RunVisionUC->>RunVisionUC: merge detections & parse annotations
RunVisionUC-->>ViewModel: Result<VisionResult>
deactivate RunVisionUC
ViewModel->>GenerateUC: invoke(detections, annotations, ...)
activate GenerateUC
GenerateUC->>Converter: generateXmlLayout(...)
activate Converter
Converter->>Converter: scale, associate text, build layout
Converter-->>GenerateUC: Pair<layoutXml, stringsXml>
deactivate Converter
GenerateUC-->>ViewModel: Result<Pair<String, String>>
deactivate GenerateUC
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/DetectionScaler.kt`:
- Around line 26-27: Integer division in DetectionScaler.kt causes normW and
normH to lose precision; cast operands to floating-point before dividing (e.g.,
convert (rect.right - rect.left) and sourceWidth/sourceHeight to Float/Double)
so normalization uses floating-point math, and ensure normW/normH types match
(Float/Double) where they are used; update the normalization lines referencing
rect, normW, normH, sourceWidth and sourceHeight accordingly.
In
`@cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/parser/ValueCleanersImpl.kt`:
- Around line 167-168: The current cleanup replaces "im_age" but leaves the OCR
variant "im" producing "@drawable/im"; in ValueCleanersImpl (the cleaned ->
finalCleaned flow) update the replacement logic to also normalize standalone
"im" to "image" (use a word-boundary or equivalent check so you don't
accidentally change substrings) before returning "@drawable/$finalCleaned";
ensure you apply this to the same cleaned/finalCleaned variable used in the
return path so empty-value fallback still returns rawValue.
In
`@cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/PrepareImageUC.kt`:
- Around line 45-51: The code in PrepareImageUC.kt that computes orientation
currently catches all Exceptions; narrow this to specific expected exceptions
(e.g., catch (ioe: IOException)) around the
contentResolver.openInputStream(uri)?.use { ... } / ExifInterface(...) call so
only IO problems are swallowed and other unexpected errors still surface;
optionally add an additional catch for SecurityException if permission issues
are possible. Ensure the fallback to ExifInterface.ORIENTATION_NORMAL remains in
the catch block.
In
`@cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/ui/viewmodel/ComputerVisionViewModel.kt`:
- Line 70: When handling ComputerVisionEvent.UpdateGuides in the ViewModel,
sanitize the incoming event.leftPct and event.rightPct before storing: clamp
both values to the [0f, 1f] range, then order them so leftGuidePct <=
rightGuidePct, and finally call _uiState.update with the normalized values
(leftGuidePct and rightGuidePct) to prevent crossed or out-of-range guides from
affecting downstream filtering and annotation parsing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ce97d103-0463-426a-8c1d-8d278e025120
📒 Files selected for processing (18)
cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/ComputerVisionRepository.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/ComputerVisionRepositoryImpl.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/VisionRepository.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/VisionRepositoryImpl.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/di/ComputerVisionModule.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/DetectionScaler.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/LayoutGeometryProcessor.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/LayoutTreeBuilder.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/TextAssociator.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/YoloToXmlConverter.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/parser/ValueCleanersImpl.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/GenerateXmlUC.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/ImportPlaceholderImageUC.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/PrepareImageUC.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/RemovePlaceholderImageUC.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/usecase/RunVisionUC.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/xml/AndroidXmlGenerator.ktcv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/ui/viewmodel/ComputerVisionViewModel.kt
💤 Files with no reviewable changes (3)
- cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/ComputerVisionRepository.kt
- cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/data/repository/ComputerVisionRepositoryImpl.kt
- cv-image-to-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/LayoutGeometryProcessor.kt
Encapsulate guide limits, narrow EXIF exceptions, and fix 'im' drawable regex.
Description
Fixes an OCR issue where arbitrary metadata values for image files were parsed incorrectly (e.g., reading "image" as "im" or "im_age"), causing broken
android:srcreferences in the generated XML. Alongside this fix, the Computer Vision architecture was heavily refactored: complex domain logic was extracted fromComputerVisionViewModeland the monolithic repository into focused, single-responsibility UseCases (RunVisionUC,GenerateXmlUC,PrepareImageUC, etc.) and helper objects (DetectionScaler,LayoutTreeBuilder,TextAssociator).Details
DrawableCleaner(ValueCleanersImpl.kt) to correct common OCR misinterpretations for the word "image".ComputerVisionRepositorywithVisionRepositoryto purely handle ML operations.GenerateXmlUC,ImportPlaceholderImageUC,PrepareImageUC,RemovePlaceholderImageUC,RunVisionUC).LayoutTreeBuilder,TextAssociator, andDetectionScaler).Screen.Recording.2026-05-13.at.11.22.18.AM.mov
Ticket
ADFA-3813
Observation
The domain refactoring drastically reduces the bloat in the
ComputerVisionViewModel, effectively decoupling the UI state management from ML detection and XML generation logic.