I use LiveData + MVP architecture.
My View in onCreate say to Presenter:
presenter = MyApplication.me().getAppComponent().getBasketPresenter();
presenter.attachView(this);
presenter.viewIsReady();
And My Presenter get LiveData
from Room DB:
LiveData<List<BasketItem>> listLiveData = MyApplication.me().getDatabase().basketDao().getAll();
After that I need observe this LiveData:
listLiveData.observe(getView(), basketItems -> {
callView(view -> {
view.setData(basketItems);
});
});
In observe callback I can check view
in callView method:
void callView(ViewAction<T> action) {
if (getView() == null) return;
action.call(view);
}
but What about listLiveData.observe(getView()
? How can I check it? I need write:
if (getView() == null) return;?
Whether correctly in general I do or make? I get the LiveData in the presenter and I observe on the view?