I have UserConfig that I would like to download during splash screen.
class UserManager {
Single<UserConfig> loadConfig()
}
After downloading of the UserConfig, user is redirected to the next screen. I do something like these:
@Override
public void onResume(boolean isNewView) {
subscriptions.add(
userManager.loadConfig().subscribe(config -> {
applyConfig(config);
launchActivity(HomeActivity.class);
}, error -> {
//some error handling
})
);
}
However, I would like to show the splash screen for at least 1 second. (If loading took less than 1s add extra delay)
I think .delay(), .delaySubscription() will not work for my case, since they will delay every request (no matter was it shorter that 1s or not).
Try Zip operator
Returns a Single that emits the results of a specified combiner function > applied to two items emitted by two other Singles.
You can do something like
Single
.zip(
Single.timer(1, TimeUnit.SECONDS),
userManager.loadConfig(),
(time, config) -> config
)
.subscribe(
config -> {
applyConfig(config);
launchActivity(HomeActivity.class);
}, error -> {
//some error handling
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With