InstantSearch Android - Clear All Filters and go back to previous fragment


I am trying to add “Close” button functionality to Filters i.e. whenever a user clicks the close button on filters screen, all applied filters should be cleared and user can go back to previous fragment.
But I was only able to:

  1. Either clear all filters using:
    onClearAllThenClearFilters(filterState, btnClearAll, connection)
  2. Go back to previous fragment

I want to do both on button click.

Instead of


You can write something like this:

myButton.setOnClickListener {

I am not using clearViewModel. I am using this method to clear the filters

fun onClearAllThenClearFilters(
filterState: FilterState,
filtersClearAll: View,
connection: ConnectionHandler
) {
val connector = FilterClearConnector(filterState)

    connection += connector
    connection += connector.connectView(FilterClearViewImpl(filtersClearAll))

Can you please help me understand how the clearAll and closeFragment work with this?

myButton.setOnClickListener {