-
-
Notifications
You must be signed in to change notification settings - Fork 513
Search Functionality
SuperDragonXD edited this page Jun 24, 2025
·
1 revision
The search functionality in Lawnicons allows users to quickly find specific icons within the app. This feature involves several UI components and interacts with the ViewModel and Repository layers to filter and display results.
- The user taps the search icon (on compact screens) or interacts with the search bar (on expanded screens or when search is active).
- A search interface appears, allowing the user to type a query.
- Filter chips allow the user to specify whether to search by icon Name (label), Component name, or Drawable resource name.
- As the user types, the list of displayed icons updates in real-time to show matching results.
- If only one icon matches precisely, it might be displayed in a more prominent list item format. If no icons match, a "no items found" message appears.
-
UI Layer (
ui/package):-
HomeTopBar.kt:- Contains the primary search input field (
SearchBarInputField) and manages the overall search bar state (SearchBarStatefrom Material 3). - On expanded screens, it directly hosts the search bar.
- On compact screens, it's less visible initially but becomes active when search is triggered (often via
HomeBottomToolbar).
- Contains the primary search input field (
-
search/SearchBar.kt:-
SearchBarInputField: The Composable for the actual text input, placeholder, leading/trailing icons (back arrow, clear button). -
ResponsiveSearchBarContents: Adapts the search bar display (ExpandedDockedSearchBarvs.ExpandedFullScreenSearchBar) based on screen size (isExpandedScreen).
-
-
search/SearchContents.kt:- Displays the filter chips for selecting search mode (Name, Component, Drawable).
- Renders the
LazyVerticalGridofIconPreviewComposables based on the filterediconInfolist received from the ViewModel. - Handles the display for "no results" or a single result in a list item format.
-
home/Home.kt:- Integrates
HomeTopBarinto the main screen Scaffold. - Manages the
expandSearchstate which controls the visibility/expansion of the search bar.
- Integrates
-
-
ViewModel Layer (
viewmodel/package):-
LawniconsViewModelImpl.kt:- Holds the current search query in
searchTermTextState(aandroidx.compose.foundation.text.input.TextFieldState). - Manages the current
searchMode(SearchMode.LABEL,SearchMode.COMPONENT,SearchMode.DRAWABLE). - Exposes the filtered search results as
searchedIconInfoModel(StateFlow<IconInfoModel>). - The
searchIcons(query: String)function is called whenever the search term or mode changes. It delegates the actual search operation to theIconRepository. -
changeMode(mode: SearchMode)updates the search mode and triggers a new search.
- Holds the current search query in
-
-
Data Layer (
repository/package):-
IconRepositoryImpl.kt:- The
search(mode: SearchMode, query: String)function performs the filtering logic. - It iterates over the full list of
IconInfo(cached iniconInfoModel). - Based on the
searchMode, it checks the query against the icon's label(s), component name(s), or drawable name. - It prioritizes matches at the start of words and then by the index of the match.
- The filtered and sorted list is then emitted to
_searchedIconInfoModel. -
clearSearch()resets thesearchedIconInfoModelto the full icon list.
- The
-
-
Model Layer (
model/package):-
IconInfo.kt: The data class for individual icons. -
IconInfoModel.kt: Holds the list of icons and their count. -
SearchInfo.kt: A temporary data class used withinIconRepositoryto hold an icon and its match relevance during sorting. -
SearchMode.kt: Anenumdefining the different search criteria.
-
- User types into
SearchBarInputField(UI). - The
TextFieldState(inLawniconsViewModel) is updated. - A
LaunchedEffectobservingsearchTermTextState.textinHome.kt(or a similar mechanism inSearchBarInputField'sonSearchcallback) callslawniconsViewModel.searchIcons(newQuery). -
LawniconsViewModel.searchIcons()callsiconRepository.search(currentSearchMode, newQuery). -
IconRepositoryfilters its master list of icons based on the query and mode, then updates its_searchedIconInfoModelStateFlow. -
SearchContents.kt(UI), observinglawniconsViewModel.searchedIconInfoModel, recomposes and displays the new list of filtered icons.
This setup ensures that the search is responsive and that concerns are well-separated across the different architectural layers.
Found an issue or have a suggestion for this wiki? Please let us know!
- Home
- Getting Started
- Architecture
- Key Feature Explanations
- Troubleshooting for Developers
- Project Glossary