Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1800700 - Add default search suggest header
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger authored and mergify[bot] committed Nov 21, 2022
1 parent 4b67f97 commit f472a99
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ internal fun Suggestions(
modifier = Modifier.testTag("mozac.awesomebar.suggestions"),
) {
suggestions.forEach { (group, suggestions) ->
if (suggestions.isNotEmpty()) {
group.title?.let { title ->
item(group.id) {
SuggestionGroup(title, colors)
}
val title = group.title
if (suggestions.isNotEmpty() && !title.isNullOrEmpty()) {
item(group.id) {
SuggestionGroup(title, colors)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ class SearchActionProvider(
private val icon: Bitmap? = null,
private val showDescription: Boolean = true,
private val searchEngine: SearchEngine? = null,
private val suggestionsHeader: String? = null,
) : AwesomeBar.SuggestionProvider {
override val id: String = java.util.UUID.randomUUID().toString()

override fun groupTitle(): String? {
return suggestionsHeader
}

override suspend fun onInputChanged(text: String): List<AwesomeBar.Suggestion> {
if (text.isBlank()) {
return emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SearchSuggestionProvider private constructor(
private val icon: Bitmap? = null,
private val showDescription: Boolean = true,
private val filterExactMatch: Boolean = false,
private val suggestionsHeader: String? = null,
) : AwesomeBar.SuggestionProvider {
override val id: String = UUID.randomUUID().toString()

Expand Down Expand Up @@ -99,6 +100,7 @@ class SearchSuggestionProvider private constructor(
* @param filterExactMatch If true filters out suggestions that exactly match the entered text.
* @param private When set to `true` then all requests to search engines will be made in private
* mode.
* @param suggestionsHeader Optional suggestions header to display.
*/
constructor(
context: Context,
Expand All @@ -112,6 +114,7 @@ class SearchSuggestionProvider private constructor(
showDescription: Boolean = true,
filterExactMatch: Boolean = false,
private: Boolean = false,
suggestionsHeader: String? = null,
) : this (
SearchSuggestionClient(context, store) { url -> fetch(fetchClient, url, private) },
searchUseCase,
Expand All @@ -121,8 +124,13 @@ class SearchSuggestionProvider private constructor(
icon,
showDescription,
filterExactMatch,
suggestionsHeader,
)

override fun groupTitle(): String? {
return suggestionsHeader
}

@Suppress("ReturnCount")
override suspend fun onInputChanged(text: String): List<AwesomeBar.Suggestion> {
if (text.isEmpty()) {
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ permalink: /changelog/
* **browser-tabstray**:
* `TabViewHolder` no longer checks if a thumbnail is in memory before retrieving a thumbnail from the `ImageLoader`.

* **feature-awesomebar**
* `SearchSuggestionProvider` and `SearchActionProvider` now have a new parameter `suggestionsHeader`, to add title to suggestions.

# 107.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v106.0.0..v107.0.0)
* [Milestone](https://github.com/mozilla-mobile/android-components/milestone/154?closed=1)
Expand Down

0 comments on commit f472a99

Please sign in to comment.