Skip to content

feat(card-browser): delegate Menu to SearchBar#20213

Merged
lukstbit merged 1 commit intoankidroid:mainfrom
david-allison:browser-delegate-menu
Mar 5, 2026
Merged

feat(card-browser): delegate Menu to SearchBar#20213
lukstbit merged 1 commit intoankidroid:mainfrom
david-allison:browser-delegate-menu

Conversation

@david-allison
Copy link
Copy Markdown
Member

@david-allison david-allison commented Jan 25, 2026

This is a no-op in PROD, and will work in dev once CardBrowser is updated to use MenuProvider

The current implementation was designed to produce the intended effect with minimal modification to the activity and Fragment.

An alternate would be to define activity.menuHost via an interface, but I deemed this to be unintuitive: NoteEditorActivity would need to implement it for no current reason.

Fixes

Approach

  • Enable MenuHost delegation in CardBrowser
  • Use MenuHostHelper to delegate to the Menu of the SearchBar
  • Define an interface with a default implementation so CardBrowserFragment stays lean

How Has This Been Tested?

Right now, this is effectively a no-op, I have a (messy) branch which has converted the Card Browser to use MenuProvider and this works as expected.

Tested briefly on a tablet emulator, in both legacy and SearchView implementations of the Card Browser

Learning (optional, can help others)

super.onCreate on an activity adds MenuProviders, therefore delegation is more complicated than expected

onDestroy invalidates a MenuHost, but a fragment may no longer be attached to a context at this point

Using the incorrect MenuInflater means showIfRoom has no effect

MenuProvider/MenuHost

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:core/core/src/main/java/androidx/core/view/MenuHost.java?q=MenuHost

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:core/core/src/main/java/androidx/core/view/MenuHostHelper.java?q=MenuHost

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison force-pushed the browser-delegate-menu branch 2 times, most recently from 6c9f482 to 4323f72 Compare January 25, 2026 21:32
Copy link
Copy Markdown
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

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

Everything is okay, although it's hard to imagine how the integration is going to look like

@BrayanDSO BrayanDSO added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 25, 2026
Copy link
Copy Markdown
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

LGTM

This is performed in the base class so CardBrowser appears 'lean' and free from low-level concerns

Ok, but do you see other activities using this(now or in the near future)? If not, moving code that is tied to CardBrowser into the super class doesn't feel right(and the implementation could have been simpler).

@lukstbit lukstbit added Needs Author Reply Waiting for a reply from the original author Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Feb 5, 2026
@github-actions

This comment was marked as outdated.

@github-actions github-actions Bot added the Stale label Feb 19, 2026
@lukstbit lukstbit added Keep Open avoids the stale bot and removed Stale labels Feb 20, 2026
@david-allison david-allison force-pushed the browser-delegate-menu branch from ed6f6c7 to 87b306c Compare March 3, 2026 22:21
@david-allison
Copy link
Copy Markdown
Member Author

@lukstbit moved to CardBrowser, strongly open to simplification if anything is proposed

@david-allison david-allison added Needs reviewer reply Waiting for a reply from another reviewer and removed Needs Author Reply Waiting for a reply from the original author Keep Open avoids the stale bot labels Mar 3, 2026
This is a no-op in PROD, and will work in dev
 once CardBrowser is updated to use MenuProvider

The current implementation was designed to produce
 the intended effect with minimal modification to
 the activity and Fragment.

An alternate would be to define `activity.menuHost`
 via an interface, but I deemed this to be unintuitive

Part of issue 18709 - Material 3 CardBrowser SearchView
Copy link
Copy Markdown
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

This is fine. The simplification I was referring to was not using the super class.

@lukstbit lukstbit removed the Needs reviewer reply Waiting for a reply from another reviewer label Mar 5, 2026
@lukstbit lukstbit added this pull request to the merge queue Mar 5, 2026
Merged via the queue into ankidroid:main with commit 0d08afc Mar 5, 2026
15 checks passed
@github-actions github-actions Bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Mar 5, 2026
@github-actions github-actions Bot added this to the 2.24 release milestone Mar 5, 2026
@david-allison david-allison deleted the browser-delegate-menu branch April 17, 2026 18:30
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.

3 participants