Skip to content

Feat: Add search and pinned selected values to MultiSelectListPreference - #46

Closed
Toldry wants to merge 1 commit into
zhanghai:masterfrom
Toldry:feat/multi-select-list-search
Closed

Toldry wants to merge 1 commit into
zhanghai:masterfrom
Toldry:feat/multi-select-list-search

Conversation

@Toldry

@Toldry Toldry commented Sep 26, 2026 •

Copy link
Copy Markdown

Made this PR due to this comment.

Long MultiSelectListPreference lists (for example, 100+ keyboard layouts in Thumb-Key) are hard to navigate by scrolling alone. This PR adds optional parameters, all off by default, to all four overloads:

  • searchable: shows a search field above the list.
  • searchFilter: decides which values match. Default: case-insensitive substring match.
  • searchPlaceholder, searchLeadingIcon, searchEmptyResult: composable slots for the field placeholder, the field icon, and the content shown when nothing matches. They are slots so the library adds no untranslated strings and bundles no icon.
  • pinSelectedValues: repeats the values selected when the dialog opened at the top of the list, above a divider. They stay pinned when unchecked until the dialog is reopened.

With the defaults the dialog is unchanged. The new parameters come before item, so trailing-lambda callers still compile; binaries built against the old signatures need recompiling. preference/api/jvm/preference.api is updated accordingly.

The sample app gets a searchable preference demonstrating all options.

  • Tests pass (the repo has no tests; apiCheck passes, and the library and sample compile. Tested manually in the Android sample on an emulator and in Thumb-Key)
  • Appropriate changes to README are included in PR (none needed, README lists preference types only)

Long lists are hard to navigate by scrolling alone. MultiSelectListPreference
now accepts optional parameters, all off by default:

- searchable shows a search field above the list.
- searchFilter decides which values match the query, given the value and its
  text. The default is a case-insensitive substring match on the text.
- searchPlaceholder, searchLeadingIcon and searchEmptyResult are slots for the
  field placeholder, the field icon, and the content shown when nothing
  matches. They are slots rather than built-in strings and icons so that no
  untranslated resources are added.
- pinSelectedValues duplicates the values selected when the dialog opens at the
  top of the list, above a divider. They stay pinned when unchecked until the
  dialog is reopened.

The sample app gets a searchable preference demonstrating all options.
@Toldry

Toldry commented Sep 26, 2026

Copy link
Copy Markdown
Author

Sample app preview:

Screen_recording_tiny.mp4

@Toldry

Toldry commented Sep 26, 2026

Copy link
Copy Markdown
Author

Related: dessalines/thumb-key#2020

@Toldry
Toldry marked this pull request as ready for review September 26, 2026 20:56
@zhanghai

Copy link
Copy Markdown
Owner

First of all, thank you for sending a PR! However, this isn't how the standard list preference works (as in androidx.preference), and different apps may have slightly different opinions on how it should be done (e.g. should unselected items immediately disappear, and should newly selected item immediately appear on top or not), so I think it should remain in the app that needs it instead of being upstreamed.

@zhanghai zhanghai closed this Sep 26, 2026
Toldry added a commit to Toldry/thumb-key that referenced this pull request Sep 27, 2026
The layouts list has over a hundred entries and could only be scrolled.
  The layouts dialog now uses the search and pinning options added to
  MultiSelectListPreference in zhanghai/ComposePreference#46: a search box
  that filters layouts by title, ignoring case and accents, and the layouts
  selected when the dialog opens pinned at the top.

Temporary: settings.gradle builds ComposePreference from a sibling
  checkout until that PR is merged and released.
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