InstantSearch provides the FilterCurrentState as a state model,
which is an implementation of the FilterCurrentView interface.
You need to connect FilterCurrentState to the FilterCurrentConnector or FilterCurrentViewModel like any other FilterCurrentView implementation.
Kotlin
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val color = "color" val price = "price" val tags = "_tags" val groupColor = FilterGroupID(color) val groupPrice = FilterGroupID(price) val groupTags = FilterGroupID(tags) val filters = filters { group(groupColor) { facet(color, "red") facet(color, "green") } group(groupTags) { tag("mobile") } group(groupPrice) { comparison(price, NumericOperator.NotEquals, 42) range(price, IntRange(0, 100)) } } val filterState = FilterState(filters) val chipGroupColors = FilterCurrentState() val currentFiltersColor = FilterCurrentConnector(filterState, listOf(groupColor)) val chipGroupAll = FilterCurrentState() val currentFiltersAll = FilterCurrentConnector(filterState) val connections = ConnectionHandler(currentFiltersColor, currentFiltersAll) init { connections += searcher.connectFilterState(filterState) connections += currentFiltersAll.connectView(chipGroupAll) connections += currentFiltersColor.connectView(chipGroupColors) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Column { // your own UI composable to display filters chipGroupAll.filters.forEach { (filterGroupAndID, filter) -> Chip(text = filter, onClick = { chipGroupAll.selectFilter(filterGroupAndID) }) } chipGroupColors.filters.forEach { (filterGroupAndID, filter) -> Chip(text = filter, onClick = { chipGroupColors.selectFilter(filterGroupAndID) }) } } } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() searcher.cancel() connections.disconnect() }}
The presenter that defines the way filters are displayed.
Kotlin
val view = FilterCurrentViewImpl(chipGroup, chipLayout) // with your view and layoutval presenter = object : FilterCurrentPresenter { // Implement the interface here}currentFilters.connectView(view, presenter)