I am trying to build a presenter that calculates some events within some time period, shows a loading only the first time of loading, and updates the ui when it is done. Because the events can be updated via multiple ways (such as user preferences) I need to be able to tell the presenter that the events were updated and that it has to refresh them again. Here is what I have right now:
subject
.map<List<UpcomingRowViewModel>> {
provider.calculateEventsBetween(TimePeriod.aYearFrom(firstDay))
}
.doOnSubscribe {
view.showLoading()
}
.observeOn(resultScheduler)
.subscribeOn(workScheduler)
.subscribe { upcomingRowViewModels ->
view.display(upcomingRowViewModels)
}
subject.onNext(TRIGGER)
The subject is a PublishSubject
of Int. I do the onNext()
right after the subscription because I want the data to be refreshed as soon as I subscribe to them.
The above code works wonders in my unit tests and also only when I am running it on a device with the debugger attached. If I just run it (without any debugger), it reaches the view.showLoading()
part, but never the provider.calculateEventsBetween(TimePeriod.aYearFrom(firstDay)
so the UI gets 'stuck' with the loading.
Any ideas?