konmik/nucleus

Still neen view in presenter.

lectricas opened this issue · 3 comments

Hi. I'm using your lib very often, and nucleous/mvp is some sort of skeleton where I should adjust to some constraints. For example what I want is to make some sort of a request loop:

You call a network, if you get an error, you are shown a dialog. If you click tryAgain, you will execute the last network requst again.

network(1) - error - dialog - click tryAgain() - (go first)

What I've made so far is this:

public class Activity implements ErrorListener
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        getPresenter().queryNetwork();
        showProgress(); //wrong place to show
    }

    //success callback
    void responeseSuccess(Stuff stuff) {
        hideProgress();
        dealwithData();
    }

    @Override
    void showError(int restartableId){
        newDialog().setPositive(() -> getPresenter().tryAgain(restartableId));
        newDialog().setPositive(() -> finishAffinity());
        newDialog().show;
    }
}

this is the presenter

    @Override
    protected void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        restartableFirst(1,
                () -> networkRequest() //need to my progress here
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()),
                view::responseSuccess,
                this::onError(1)); //here proceed the error and then call  Activity showError() method
    }

    queryNetwork() {
        start(1);
    }

    public void tryAgain(int restartable) {
        start(restartable);
    }

}

it works except one thing. I really need my progressBar to be shown every time I run the network request. This is a view thing and I'm not sure where I can put it.
Or maybe this approach is wrong and you have suggestions.

this may be help you #87

@ml-bright no it don't. That was my aproach before.
I'm restarting the restartable, not the entire method. But to show progress bar, I should restart onCreate with the method inside.

just save/restore progressIsShowing flag into the activity bundle