oday
11/15/2022, 12:18 PMprivate val categoryFilter = BrowseEventsFilter.CategoryFilter(category = MutableStateFlow(Category.All))
private val locationFilter = BrowseEventsFilter.LocationFilter(location = MutableStateFlow(null))
private val periodFilter = BrowseEventsFilter.PeriodFilter(
period = MutableStateFlow(Period.Any),
dateRange = MutableStateFlow(null)
)
and then you change them
var filtersState = MutableStateFlow(listOf(locationFilter, periodFilter, categoryFilter)) // collectAsState in the activity
// how they change
filterState?.enabled?.value = ChipStatus.ENABLED
filterState?.period?.value = period
filterState?.dateRange?.value = null
and then observe them
flowOf(periodFilter.period?.value,
periodFilter.dateRange?.value,
categoryFilter.category.value,
locationFilter.location.value
).collect {
// do something everytime their values change
}
Filip Wiesner
11/15/2022, 12:24 PMflowOf
implementation:
public fun <T> flowOf(vararg elements: T): Flow<T> = flow {
for (element in elements) {
emit(element)
}
}
Also not really #compose relatedoday
11/15/2022, 12:24 PMChris Fillmore
11/16/2022, 3:07 AMcombine
oday
11/16/2022, 7:40 AMmerge