Filter Toggle
About this widget
Filter Toggle is a filtering view that displays any kind of filter, and lets the user refine the search results by toggling it on or off.
To add a filter toggle to your search experience, use these components:
Searcher
: TheSearcher
that handles your searches.FilterState
: The current state of the filters.FilterToggleViewModel
: The logic applied to the filter.FilterToggleView
: The view that will render the filter toggle.FilterPresenter
: Optional. The presenter to customize the display of the filters.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class MyActivity : AppCompatActivity() {
val client = ClientSearch(
ApplicationID("YourApplicationID"),
APIKey("YourAPIKey")
)
val index = client.initIndex(IndexName("YourIndexName"))
val searcher = SearcherSingleIndex(index)
val filterState = FilterState()
val attribute = Attribute("facetName")
val filter = Filter.Facet(attribute, "facetValue")
val viewModel = FilterToggleViewModel(filter)
val connection = ConnectionHandler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val checkBox = CheckBox(this)
val view: FilterToggleView = FilterToggleViewCompoundButton(checkBox)
connection += searcher.connectFilterState(filterState)
connection += viewModel.connectFilterState(filterState)
connection += viewModel.connectView(view)
searcher.searchAsync()
}
override fun onDestroy() {
super.onDestroy()
connection.disconnect()
searcher.cancel()
}
}
Parameters
searcher
|
type: Searcher
Required
The |
||
Copy
|
|||
filterState
|
type: FilterState
Required
The |
||
Copy
|
|||
filterToggleView
|
type: FilterToggleView
Required
The view that will render the filter toggle. |
||
Copy
|
|||
filter
|
type: Filter
Required
The filter to apply. |
||
Copy
|
|||
groupId
|
type: FilterGroupID?
default: FilterGroupID(filter.value.attribute, FilterOperator.And)
Optional
When specified, the filter will be grouped under this ID and will be composed with this operator.
Defaults to the attribute used, applying |
||
Copy
|
|||
isSelected
|
type: Boolean?
default: false
Optional
If |
||
Copy
|
Presenter
presenter
|
type: FilterPresenter
default: FilterPresenterImpl()
Optional
A presenter describing how to display a filter. |
||
Copy
|