DiscoverFeedMainInteractor
@Override
protected void didBecomeActive() {
super.didBecomeActive();
discoverBagelRefreshStream = BehaviorSubject.create();
discoverManager.addGiveTakeItemEventListener(this);
/*
If something goes wrong witht the download of GiveTakes & RisingGiveTakes,
discoverMatchRepository.getGiveTakesDownloaded() will never return
User will be stuck seeing blank or infinite loading screen
That's why timeout is important here
*/
AtomicBoolean downloadCompleted = new AtomicBoolean();
Disposable disposable = discoverMatchRepository.getGiveTakesDownloaded()
.doOnTerminate(() -> downloadCompleted.set(true))
.as(AutoDispose.autoDisposable(this))
.subscribe(unit -> {
Logger.d(TAG, "GiveTakes & RisingTakes downloaded and saved in local cache, now read from local cache and render");
discoverManager.refreshGiveTakes();
});
/*
Is there a simpler way to implement time limit with RxJava?
Probably, need to dig, I don't know of top of my head
This is probably where Coroutines can be simpler
*/
Single.timer(30, TimeUnit.SECONDS)
.as(AutoDispose.autoDisposable(this))
.subscribe(aLong -> {
if (!downloadCompleted.get()) {
final String message = "GiveTakes & RisingGiveTakes download did not completed within reasonable time";
Logger.e(TAG, message, new TimeoutException(message));
disposable.dispose();
getRouter().routeToDiscoverFeedEmpty();
}
});
mainActivity.hideTabLayout();
observeUpsellConditions();
}