LiveDataReactiveStreams.fromPublisher() not working with Single

317 Views Asked by At

I am getting User from Room Database by returning Single<UserMinimal>. Once I get the data I want to show it through LiveData observing, and I am using LiveDataReactiveStreams.fromPublisher() method, but looks like when .setValue() is called, all attributes of the received user are null. Don't know if needs .subscribe() or whatever.

LiveData<UserMinimal> userLiveData = LiveDataReactiveStreams
                .fromPublisher(mRepository.getUser().toFlowable());
        user = new MediatorLiveData<>();
        user.addSource(userLiveData, minimalUser -> {
            user.postValue(minimalUser);
            user.removeSource(userLiveData);
        });


public Single<MenuRepository.UserMinimal> getUser(){
    return dataSource.getUser()
            .onErrorReturnItem(new MenuRepository.UserMinimal())
            .doOnError(t -> Timber.e(t))
            .subscribeOn(Schedulers.io());
}

Looks like the access to database is successfully working because if I use MutableLiveData instead of MeadiatorLiveData, it does work:

user = new MutableLiveData<>();
        disposable.add(mRepository.getUser().subscribe(new Consumer<UserMinimal>() {
            @Override
            public void accept(UserMinimal userMinimal) throws Throwable {
                user.postValue(userMinimal);
            }
        }));
0

There are 0 best solutions below