konmik / nucleus

Nucleus is an Android library, which utilizes the Model-View-Presenter pattern to properly connect background tasks with visual parts of an application.
MIT License
1.98k stars 253 forks source link

Still neen view in presenter. #127

Closed lectricas closed 7 years ago

lectricas commented 7 years ago

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.

ml-bright commented 7 years ago

this may be help you #87

lectricas commented 7 years ago

@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.

konmik commented 7 years ago

just save/restore progressIsShowing flag into the activity bundle