Emit from single when flowable emits

134
October 16, 2018, at 6:30 PM

I have an activity where you can see a bunch of places according to a filter and the current viewport of the map.

So I've modeled these two sources as Flowables:

fun boundariesFlowable(): Flowable<Pair<LatLon, LatLon>>
fun filtersFlowable(): Flowable<FilterRequest>

Where boundaries emits the TopLeft and BottomRight corners of the map viewport, and filters just emits any change in the filters applied by the user.

Now I want to observe these two sources so that a call is performed each time either of them changes. This is my request call:

 fun refreshApplyFilter(id: Int, filter: FilterRequest): Single<FilterResponse>

The problem, I cannot figure out how to combine this trigger sources, or how to perform the call on their emission.

I've tried flatmapping just one of the sources but it expects a Publisher, while my request is a Single.

Answer 1

You can use Flowable.combineLatest() operator to observe several sources. If any of them post new value, function will be triggered.

val res: Flowable<FilterResponse> = Flowable.combineLatest(boundariesFlowable(), filtersFlowable(), BiFunction<Pair<LatLon, LatLon>, FilterRequest, FilterRequest> { pair, filter ->
    filter
}).flatMapSingle { filter -> refreshApplyFilter(0, filter) }
Rent Charter Buses Company
READ ALSO
How to play RTSP video url in Android Oreo and Pie

How to play RTSP video url in Android Oreo and Pie

I'm working on a project, and i need to play RTSP videos but the video must be set as background rather than simple imageAnd the only solution i found is using VideoView and MediaPlayer, and it works perfectly fine in Android 7

215
Qt Android - Reading a Directory

Qt Android - Reading a Directory

I'm working on a Qt Android application and would like to read a directory and list all the files inside it of a certain extension

258
&ldquo;onWindowFocusChanged()&rdquo; not excuted when switching fragments

“onWindowFocusChanged()” not excuted when switching fragments

I have an activity, with multiple master-detail fragments in the activityFragment 1 is opened with a button click in Activity, and Fragment 2 is open with a button click in Fragment 1

181
Unable to establish second Raspberry Pi [WIFI Direct] to a device

Unable to establish second Raspberry Pi [WIFI Direct] to a device

I have 2 Raspberry Pi and an Android Tablet and the Tablet is supposed to be controlling the Raspberry Pi via the webserver from the PiThe Android Tablet has a Wifi Direct application and I was able to establish connection with one of the Pi

181