Skip to content

fix(android): widget multi-target click listeners for reliable deep linking#572

Draft
drehelis wants to merge 4 commits intobetter-rail:mainfrom
drehelis:fix_2x2_widget_listener
Draft

fix(android): widget multi-target click listeners for reliable deep linking#572
drehelis wants to merge 4 commits intobetter-rail:mainfrom
drehelis:fix_2x2_widget_listener

Conversation

@drehelis
Copy link
Member

Fixes an issue where widget clicks were often ignored on the 2x2 layout due to touch events being consumed by the background overlay or not bubbling up to the root container.

@gemini-code-assist
Copy link

Summary of Changes

Hello @drehelis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the reliability of deep linking from Android widgets by implementing a multi-target click handling mechanism. By allowing multiple views within a widget to register for click events, it resolves previous issues where clicks were frequently missed, especially on the 2x2 widget layout. This change ensures a more consistent and user-friendly experience when interacting with widgets.

Highlights

  • Multi-target click handling for widgets: Introduced the ability to define multiple click target IDs for Android widgets, allowing for more robust deep linking by setting PendingIntent on several views within a widget layout.
  • Improved widget click reliability: Addressed an issue where widget clicks, particularly on the 2x2 layout, were often ignored due to touch events being consumed by background overlays or not bubbling up correctly.
  • Centralized click target configuration: Refactored widget click target definitions into the WidgetSize enum, providing a centralized and configurable way to specify which views within a widget should respond to clicks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • android/app/src/main/java/com/betterrail/widget/ModernBaseWidgetProvider.kt
    • Added a new getClickTargetIds() method to return an array of view IDs that should respond to clicks.
    • Modified the setupWidgetClickIntent function to accept an IntArray of clickTargetIds instead of a single Int.
    • Updated setupWidgetClickIntent and setupRefreshClickIntent to iterate over the provided clickTargetIds and set setOnClickPendingIntent for each target.
    • Adjusted calls to setupWidgetClickIntent to pass an intArrayOf for specific click targets.
  • android/app/src/main/java/com/betterrail/widget/UnifiedWidgetProvider.kt
    • Overrode the getClickTargetIds() method to retrieve click targets from the defaultWidgetSize.clickTargets property.
  • android/app/src/main/java/com/betterrail/widget/WidgetSize.kt
    • Added a new clickTargets: IntArray property to the WidgetSize enum constructor.
    • Updated the COMPACT_2X2, COMPACT_4X2, and COMPACT_5X2 enum entries to define their respective clickTargets arrays and adjusted their containerId values.
  • android/app/src/main/res/layout/widget_compact_2x2.xml
    • Added the android:id="@id/widget_content_container_2x2" attribute to the main content LinearLayout.
  • android/app/src/main/res/layout/widget_compact_4x2.xml
    • Added the android:id="@id/widget_content_container_4x2" attribute to the main content LinearLayout.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of unreliable widget clicks by implementing multi-target click listeners. The changes are well-structured, introducing a new getClickTargetIds() function and correctly propagating its use throughout the widget providers. My review includes a couple of suggestions for improvement: one to refactor a section for better conciseness and efficiency, and another to align with Kotlin best practices by preferring List over Array to enhance code safety.

val actionRefresh: String,
val actionWidgetUpdate: String,
val actionRouteReversal: String,
val clickTargets: IntArray

Choose a reason for hiding this comment

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

medium

For better safety and adherence to Kotlin best practices, consider using List<Int> instead of IntArray. IntArray uses reference equality for equals() and hashCode(), which can lead to subtle bugs. List<Int> uses structural equality, which is usually what's intended.

This change would require updating getClickTargetIds() to return List<Int>, setupClickIntentsBase() to accept a List<Int>, and using listOf() instead of intArrayOf().

Suggested change
val clickTargets: IntArray
val clickTargets: List<Int>

Copy link
Member

@guytepper guytepper left a comment

Choose a reason for hiding this comment

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

Note

This review was generated by Claude Code.

Overall

Good, focused fix. The multi-target click approach is the right solution — registering the same PendingIntent on multiple view layers (root container, content overlay, station background) ensures touch events are captured regardless of which layer intercepts them. The refactoring from single clickTargetId to clickTargetIds: IntArray is clean and backward-compatible.

Potential Issue

setupConfigurationClickIntent (line 712) was not updated. It still calls views.setOnClickPendingIntent(getWidgetContainerId(), pendingIntent) with a single target. Since containerId now points to the content overlay (widget_content_container_2x2/widget_content_container_4x2) instead of the root, the "Tap to configure" state may suffer from the same click-not-registering issue on the background/root layers — the very bug this PR is fixing for the schedule state.

Suggest updating setupConfigurationClickIntent to iterate over getClickTargetIds() as well, for consistency.

Comment on lines +22 to +26
clickTargets = intArrayOf(
R.id.widget_container_compact,
R.id.widget_content_container_2x2,
R.id.widget_station_background
),
Copy link
Member

Choose a reason for hiding this comment

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

[Claude Review]

Good coverage — targeting the root container, content overlay, and station background should handle all the touch interception layers.

Minor Kotlin note: IntArray uses reference equality, not structural equality. This won't matter for enum constants (always the same instance), but if clickTargets is ever compared in tests or other contexts, == won't behave like contentEquals(). Not actionable now, just a heads-up.

@drehelis drehelis marked this pull request as draft February 13, 2026 10:14
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.

2 participants