Skip to content

fix: move clickable to content element to fix Glance layout ID collision#20

Merged
wassupluke merged 2 commits into
mainfrom
feature/alarm-widget-font-size
Apr 2, 2026
Merged

fix: move clickable to content element to fix Glance layout ID collision#20
wassupluke merged 2 commits into
mainfrom
feature/alarm-widget-font-size

Conversation

@wassupluke
Copy link
Copy Markdown
Owner

@wassupluke wassupluke commented Apr 2, 2026

Summary

  • Both widgets had a Box(fillMaxSize) > Box(clickable) > Content structure, which caused Glance to assign the same layout resource ID to both — making one widget display the other's content
  • Removed the intermediate clickable Box wrapper from both widgets; .clickable() now lives directly on the content element (Text in WeatherWidget, Row in AlarmWidget)
  • The composable trees are now structurally distinct (Box > Text vs Box > Row > …), preventing the layout ID collision
  • Also narrows the tap target to the content only, not the full widget surface

Test plan

  • ./gradlew :app:compileDebugKotlin passes cleanly
  • Place both widgets on the launcher; confirm WeatherWidget shows temperature and AlarmWidget shows alarm text with no content bleed in either direction
  • Tap each widget; confirm it launches the correct configured app (or MainActivity)

Summary by Sourcery

Prevent content bleed and layout ID collisions between the Weather and Alarm Glance widgets.

Bug Fixes:

  • Constrain widget click handling to the content elements instead of an intermediate full-size container to avoid Glance layout ID collisions.
  • Ignore next-alarm entries coming from non-user-facing packages when deriving the Alarm widget display text to prevent showing invalid or misleading alarms.

getNextAlarmClock() returns the next AlarmClockInfo alarm from any app,
not just the Clock app. Background system processes can set alarm clock
alarms that fire before the user's actual Clock alarm. Check the alarm's
showIntent.creatorPackage against PackageManager to verify it belongs to
a user-facing app (has a launcher icon); if not, display "No alarm".
Both widgets sharing a Box > Box(clickable) > Content structure caused
Glance to assign the same layout resource ID to both widgets, making one
display the other's content.

Move .clickable() directly onto the content element (Text for
WeatherWidget, Row for AlarmWidget) so their composable trees are
structurally distinct. Also narrows the tap target to the content only.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 2, 2026

Reviewer's Guide

Moves Glance widget click handling from a wrapper Box to the actual content elements to avoid layout ID collisions between Weather and Alarm widgets, and tightens Alarm widget alarm-text computation to only show real user-facing alarms from clock apps.

Sequence diagram for Glance layout ID assignment for Weather and Alarm widgets

sequenceDiagram
    participant Launcher
    participant AppWidgetManager
    participant Glance
    participant WeatherWidget
    participant AlarmWidget

    Launcher->>AppWidgetManager: Request to pin WeatherWidget
    AppWidgetManager->>Glance: Create WeatherWidget instance
    Glance->>WeatherWidget: WeatherWidgetContent()
    WeatherWidget-->>Glance: Box > Text(clickable)
    Glance->>Glance: Generate layoutId_Weather based on tree

    Launcher->>AppWidgetManager: Request to pin AlarmWidget
    AppWidgetManager->>Glance: Create AlarmWidget instance
    Glance->>AlarmWidget: AlarmWidgetContent()
    AlarmWidget-->>Glance: Box > Row(clickable) > Image + Text
    Glance->>Glance: Generate layoutId_Alarm based on tree

    Glance->>AppWidgetManager: Provide distinct layouts for both widgets
    AppWidgetManager->>Launcher: Render WeatherWidget and AlarmWidget with correct content
Loading

Updated class diagram for AlarmWidgetReceiver and widget content composables

classDiagram
    class GlanceAppWidgetReceiver

    class AlarmWidgetReceiver {
        +onReceive(context: Context, intent: Intent): void
        -isUserFacingApp(context: Context, packageName: String): Boolean
    }

    AlarmWidgetReceiver --|> GlanceAppWidgetReceiver

    class AlarmWidgetContent {
        +AlarmWidgetContent(tapAction: Action, alarmText: String, fontSize: Int, textColorProvider: ColorProvider): void
    }

    class WeatherWidgetContent {
        +WeatherWidgetContent(tapAction: Action, displayTemp: String, fontSize: Int, textColorProvider: ColorProvider): void
    }
Loading

File-Level Changes

Change Details Files
Attach click behavior directly to widget content elements instead of an intermediate Box to make the Glance layout trees structurally distinct and avoid ID collisions.
  • In AlarmWidget, remove the clickable Box wrapping the Row and instead apply GlanceModifier.clickable(tapAction) directly to the Row
  • In WeatherWidget, remove the clickable Box wrapper and instead apply GlanceModifier.clickable(tapAction) directly to the Text
  • Preserve existing layout: Alarm widget still uses a centered Row with icon, spacer, and text; Weather widget still shows a centered Text with temperature
app/src/main/java/com/wassupluke/widgets/widget/AlarmWidget.kt
app/src/main/java/com/wassupluke/widgets/widget/WeatherWidget.kt
Harden alarm text source so the widget only reflects alarms coming from user-facing clock apps.
  • Derive the creator package of the nextAlarm showIntent and determine if it belongs to a user-launchable (clock) app
  • If the next alarm is not from a user-facing app, fall back to the "no alarm" string instead of showing its time
  • Introduce a helper isUserFacingApp that resolves ACTION_MAIN/CATEGORY_LAUNCHER activities for a given package via PackageManager
app/src/main/java/com/wassupluke/widgets/widget/AlarmWidgetReceiver.kt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="app/src/main/java/com/wassupluke/widgets/widget/AlarmWidgetReceiver.kt" line_range="46-44" />
<code_context>
                     context.getString(R.string.widget_alarm_none)
                 } else {
-                    DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(nextAlarm.triggerTime))
+                    val creator = nextAlarm.showIntent?.creatorPackage
+                    val fromClockApp = creator != null && isUserFacingApp(context, creator)
+                    if (fromClockApp) {
+                        DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(nextAlarm.triggerTime))
+                    } else {
+                        context.getString(R.string.widget_alarm_none)
+                    }
                 }
</code_context>
<issue_to_address>
**question:** Filtering to only alarms from launcher-visible apps may hide legitimate alarms from non-launcher apps.

Because `fromClockApp` relies on `isUserFacingApp` (i.e., having a launcher activity), any alarm from a package without a launcher will be treated as “no next alarm”. That affects valid alarms from automation tools, companion apps, or OEM/system components that don’t expose launcher activities. If the intent is to exclude specific system/internal sources (e.g., System UI or framework packages), it would be safer to explicitly whitelist known clock apps or blacklist known internal packages instead of using `CATEGORY_LAUNCHER` as a proxy, to avoid the widget incorrectly showing "none" when an alarm is actually set.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wassupluke wassupluke merged commit 74a8e96 into main Apr 2, 2026
3 checks passed
@wassupluke wassupluke deleted the feature/alarm-widget-font-size branch April 2, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant