SearchTemplate.Builder


class SearchTemplate.Builder


A builder of SearchTemplate.

Summary

Public constructors

Returns a new instance of a Builder with the input SearchCallback.

Public functions

SearchTemplate

Constructs the SearchTemplate model.

SearchTemplate.Builder

Sets the ActionStrip for this template.

SearchTemplate.Builder
setHeaderAction(headerAction: Action)

Sets the Action that will be displayed in the header of the template.

SearchTemplate.Builder
setInitialSearchText(initialSearchText: String)

Sets the initial search text to display in the search box.

SearchTemplate.Builder
setItemList(itemList: ItemList)

Sets the ItemList to show for search results.

SearchTemplate.Builder
setLoading(isLoading: Boolean)

Sets whether the template is in a loading state.

SearchTemplate.Builder
setSearchHint(searchHint: String)

Sets the text hint to display in the search box when it is empty.

SearchTemplate.Builder
setShowKeyboardByDefault(showKeyboardByDefault: Boolean)

Sets if the keyboard should be displayed by default, instead of waiting until user interacts with the search box.

Public constructors

Builder

Added in 1.0.0
Builder(callback: SearchTemplate.SearchCallback)

Returns a new instance of a Builder with the input SearchCallback.

Note that the callback relates to UI events and will be executed on the main thread using getMainLooper.

Parameters
callback: SearchTemplate.SearchCallback

the callback to be invoked for events such as when the user types new text, or submits a search

Public functions

build

Added in 1.0.0
fun build(): SearchTemplate

Constructs the SearchTemplate model.

Throws
java.lang.IllegalArgumentException

if the template is in a loading state but the list is set

setActionStrip

Added in 1.0.0
fun setActionStrip(actionStrip: ActionStrip): SearchTemplate.Builder

Sets the ActionStrip for this template.

Unless set with this method, the template will not have an action strip.

Requirements This template allows up to 2 Actions in its ActionStrip. Of the 2 allowed Actions, one of them can contain a title as set via setTitle. Otherwise, only Actions with icons are allowed.
Throws
java.lang.IllegalArgumentException

if actionStrip does not meet the requirements

java.lang.NullPointerException

if actionStrip is null

setHeaderAction

Added in 1.0.0
fun setHeaderAction(headerAction: Action): SearchTemplate.Builder

Sets the Action that will be displayed in the header of the template.

Unless set with this method, the template will not have a header action.

Requirements This template only supports either one of APP_ICON and BACK as a header Action.
Throws
java.lang.IllegalArgumentException

if headerAction does not meet the template's requirements

java.lang.NullPointerException

if headerAction is null

setInitialSearchText

Added in 1.0.0
fun setInitialSearchText(initialSearchText: String): SearchTemplate.Builder

Sets the initial search text to display in the search box.

Throws
java.lang.NullPointerException

if initialSearchText is null

setItemList

Added in 1.0.0
fun setItemList(itemList: ItemList): SearchTemplate.Builder

Sets the ItemList to show for search results.

The list will be shown below the search box, allowing users to click on individual search results.

Requirements The number of items in the ItemList should be smaller or equal than the limit provided by CONTENT_LIMIT_TYPE_LIST. The host will ignore any items over that limit. The list itself cannot be selectable as set via setOnSelectedListener. Each Row can add up to 2 lines of texts via addText and cannot contain a Toggle.
Throws
java.lang.IllegalArgumentException

if itemList does not meet the template's requirements

java.lang.NullPointerException

if itemList is null

See also
getContentLimit

setLoading

Added in 1.0.0
fun setLoading(isLoading: Boolean): SearchTemplate.Builder

Sets whether the template is in a loading state.

If set to true, the UI will display a loading indicator where the list content would be otherwise. The caller is expected to call invalidate and send the new template content to the host once the data is ready. If set to false, the UI shows the contents added via setItemList.

setSearchHint

Added in 1.0.0
fun setSearchHint(searchHint: String): SearchTemplate.Builder

Sets the text hint to display in the search box when it is empty.

The host will use a default search hint if not set with this method.

This is not the actual search text, and will disappear if user types any value into the search.

If a non empty text is set via setInitialSearchText, the searchHint will not show, unless the user erases the search text.

Throws
java.lang.NullPointerException

if searchHint is null

setShowKeyboardByDefault

Added in 1.0.0
fun setShowKeyboardByDefault(showKeyboardByDefault: Boolean): SearchTemplate.Builder

Sets if the keyboard should be displayed by default, instead of waiting until user interacts with the search box.

Defaults to true.