-
Notifications
You must be signed in to change notification settings - Fork 48
[EPIC-6660] update snippets to new result api #414
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
base: android_ds_8.0.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates code snippets to migrate from the old activity result API to a new result API pattern. The changes modernize result handling by replacing registerForActivityResultOk with registerForActivityResult and using onSuccess/onFailure extension functions for cleaner error handling.
Key Changes
- Migrated from
registerForActivityResultOktoregisterForActivityResultwithonSuccess/onFailurehandlers - Added comprehensive error handling with specific error type cases (
InvalidLicenseError,OperationCanceledError) - Updated SDK version from
8.0.0.61-STAGING-SNAPSHOTto8.0.0.62-STAGING-SNAPSHOT
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| SinglePagePreviewActivity.kt | Updated cropping result handler to use new API |
| MainActivity.kt (document-scanner) | Updated document scanner result handler with error handling |
| StandaloneCropScreenSnippet.kt | Updated cropping UI snippet with comprehensive error handling |
| Multiple snippet files | Migrated all RTU UI snippets to new result API pattern |
| QuickStartSnippets.kt | Simplified result parameter naming |
| VinUiSnippet.kt | Added error handling to all VIN scanner snippets |
| TextPatternUiSnippet.kt | Added error handling to all text pattern scanner snippets |
| MrzUiSnippet.kt | Added error handling to all MRZ scanner snippets |
| RtuUi2DocumentSnippets.kt | Updated migration snippets to new API |
| DataExtractionUiSnippet.kt | Added error handling to all data extractor snippets |
| CreditCardUiSnippet.kt | Added error handling and fixed credit card result handling |
| CheckUiSnippet.kt | Added error handling to all check scanner snippets |
| MainActivity.kt (data-capture) | Updated multiple scanner result handlers |
| app/build.gradle files | Bumped SDK version to 8.0.0.62-STAGING-SNAPSHOT |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> | ||
| resultEntity.onSuccess { creditCardResult -> | ||
| creditCardResult.creditCard?.let { | ||
| val creditCard = CreditCard(creditCardResult.creditCard!!) |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant null check followed by non-null assertion. Line 51 already verifies creditCard is not null with let, but line 52 uses the non-null assertion operator (!!) which could fail if the value is actually null. Either remove the let check or use the safe reference it instead of creditCardResult.creditCard!!.
| val creditCard = CreditCard(creditCardResult.creditCard!!) | |
| val creditCard = CreditCard(it) |
...mple/app/src/main/java/io/scanbot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt
Outdated
Show resolved
Hide resolved
| resultEntity.result?.mrzDocument?.let { | ||
| showMrzDialog(it) | ||
| } | ||
| resultEntity?.mrzDocument?.let { |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resultEntity is nullable but registerForActivityResultOk should return a non-null result. This inconsistency suggests either the helper function signature is incorrect or the null-safe operator is unnecessary.
| resultEntity?.mrzDocument?.let { | |
| resultEntity.mrzDocument.let { |
| checkScannerResultLauncher = | ||
| registerForActivityResultOk(CheckScannerActivity.ResultContract()) { resultEntity -> | ||
| handleCheckScannerResult(resultEntity.result!!) | ||
| handleCheckScannerResult(resultEntity) |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function handleCheckScannerResult expects a non-null result, but if registerForActivityResultOk can return null, this will cause a runtime error. Consider adding a null check or verifying the return type of registerForActivityResultOk.
| handleCheckScannerResult(resultEntity) | |
| resultEntity?.let { handleCheckScannerResult(it) } |
…bot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.