1

I am currently subscribed to a flowable method using RxJava2 Let's say that i have a method where i subscribe.

public Flowable<UploadStatus> getStatusChanges() 

I will make the first call to load all of the items status from database, so basically will load all of the items on my recyclerview. But once im subscribe i will keep getting events from that flowable. I will get individual changes from a determined item, for instance a determined item changed.

How can i differ individual changes from the initial load?

cri_sys
  • 472
  • 1
  • 5
  • 17
  • any reason you are not using [DiffUtils](https://developer.android.com/reference/android/support/v7/util/DiffUtil.html) ? – LordRaydenMK Feb 24 '18 at 12:11
  • DiffUtils it is for a different use case, for updating the recyclerview itself. What i really want it to differentiate the initial load with the updates afterwards. The idea it is to show a loading bar or something first time when i subscribe to the flowable, then i will update the items changed on the recyclerview, but i want to know when the flowable finished with the first complete load. – cri_sys Feb 26 '18 at 10:27

1 Answers1

1

Assuming you wrap your result into a class like this:

class Wrapper {
    public boolean firstLoad;
    public UploadStatus uploadStatus;

    //constructor omitted for brevity 
}

you could do something like this:

getStatusChanges()
    .map(item -> Wrapper(false, item))
    .startWith(Wrapper(true, null)
    .subscribe(result -> {
        if(result.firstLoad) {
            //show spinner
        } else {
            //handle normaly
        }
    })

Another approach (adapted from my answer here) is using publish.

getStatusChanges().publish(items -> items.first().map(item -> Wrapper(true, item)).concatWith(items.skip(1).map(item -> Wrapper(false, item))))
LordRaydenMK
  • 13,074
  • 5
  • 50
  • 56