Conversation
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.
Code snippets are for:
Why the XML layouts were extracted too:
The Kotlin snippet on this page cannot compile on its own. It resolves
R.layout.notification_smallandR.layout.notification_largethroughRemoteViews(packageName, ...), so both layout resources have to exist in the module for:views:compileDebugKotlinto succeed. That is why the two<LinearLayout>blocks from the page were extracted into real layout resources inviews/src/main/res/layout/rather than left hardcoded on DAC. The same reasoning applies toR.drawable.notification_icon, whichsetSmallIcon(...)references. Hosting them also keeps the layouts and the Kotlin that inflates them in sync in one place, and it follows the precedent already set byviews/src/main/res/layout/widget_layout.xmlon the App Widgets pages.List of modifications:
views/src/main/res/layout/notification_small.xmlwith region tagandroid_views_notifications_custom_layout_small. Required for the Kotlin snippet to compile.views/src/main/res/layout/notification_large.xmlwith region tagandroid_views_notifications_custom_layout_large. Required for the Kotlin snippet to compile.views/src/main/java/com/example/example/snippet/views/notifications/CustomNotification.ktwith region tagandroid_views_notifications_custom_content_view.views/src/main/res/drawable/notification_icon.xml, a 24dp bell vector drawable required bysetSmallIcon(R.drawable.notification_icon)in the migrated Kotlin snippet. Origin: hand-authored<vector>based on the Material Symbols "notifications" (bell) path, Apache 2.0, matching the house style of the existingviews/src/main/res/drawable/ic_cloud.xml.No new top-level module was added; everything lands in the existing
viewsmodule.Code between region tags is byte-identical to the page, with these exceptions:
<?xml version="1.0" encoding="utf-8"?>declaration of both layouts sits outside the region tag, because an XML declaration must be the first line of the file and the license header must precede the region tag. This matches the existing precedent inviews/src/main/res/layout/widget_layout.xml.spotlessApplyre-indented the 5 chained builder calls in the Kotlin snippet from an 8-space to a 4-space continuation indent. No tokens changed.Boilerplate kept outside the region tags:
private const val CHANNEL_ID, theprivate class CustomNotificationActivity : ComponentActivity()wrapper (so the page's baregetSystemService(...)andpackageNamecalls resolve against a realContext), and theval context: Context = thisbinding. No@RequiresApiwas added, since theviewsmoduleminSdkis 36.Snippets not migrated:
<TextView>with no root element or namespace) whose teaching point relies on inline<b>highlighting. It stays hardcoded on the page and is wrapped withdisableFinding(SNIPPET_GITHUB).Verification:
./gradlew :views:compileDebugKotlinand./gradlew :views:spotlessApplyboth pass.