Lilly
08/23/2023, 2:04 PMLazyColumn
composable which gets its items from a flow. As terminal operator I'm using toList(myStateList)
and store new items in a SnapshotStateList
. The producer of the flow might be a BroadcastReceiver
or anything else that keeps the flow alive. Further, the UI provides a sheet for filtering the list. When I apply a filter that reduces the items of the list, should I remove the affected items from the current list (which are currently visible) or should I clear the list and restart the collection? What is the better practice here?why
08/23/2023, 2:36 PMLilly
08/23/2023, 3:24 PMwhy
08/23/2023, 4:35 PMLilly
08/23/2023, 4:39 PMBroadcastReceiver
, that says, this
a new list of items will be producedis not possible since all items have to be discovered every time again
Lilly
08/23/2023, 4:45 PMwhy
08/23/2023, 4:51 PMLilly
08/23/2023, 4:52 PMLilly
08/23/2023, 4:54 PMwhy
08/23/2023, 4:56 PMLilly
08/23/2023, 5:00 PMoverride fun execute(
requestBuilder: () -> ObserveDiscoveredDevicesRequest,
): Flow<DiscoveredDeviceResponse> =
with(requestBuilder()) {
filterService.subscribeToState().flatMapLatest { filter ->
discoveryService.subscribeToState()
.filter { device ->
if (filter.name.isNotBlank()) {
device.name.startsWith(filter.name, ignoreCase = true)
} else {
true
}
}
.map { DiscoveredDeviceResponse.from(it) }
.flowOn(dispatcher)
}
}
Wait. Even when I
have another flow that receives filtering input and combine both flows and generate your final flowthe device discovery flow wouldn't emit anything as long as I'm not scanning. 🤔
Lilly
08/23/2023, 5:04 PMwhy
08/23/2023, 5:35 PMFlows
, StateFlows
and MutableStateFlows
to learn more about their usability since they can be very tricky especially if one is not familiar with reactive programming. Hope this helped.Lilly
08/23/2023, 8:06 PM