StuartDTO
StuartDTO

Reputation: 1041

ShowDialog using MVP

I have a view called ILoginView and on it I have a showDialog(String message) and on my LoginPresenter I have the call to api so if it fails I do view.showDialog(context.getString(R.string.response_server_error)); so my question is, when I implement the interface on my mainActivity and I have to override this method, there is the correct way to place the :

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("Click on Image for tag");
    alertDialogBuilder.setPositiveButton("Ok",
        new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface arg0, int arg1) {
        }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();

Upvotes: 0

Views: 1149

Answers (1)

Shobhit Puri
Shobhit Puri

Reputation: 26017

Correct me if I am wrong but if I understand your question correctly, you are asking about where to place the code to show AlertDialog related code in the MVP pattern. Usually the generic idea is that Presenter shouldn't have any Android specific code. It should be just a POJO class. It makes your business logic inside the Presenter class easier to test using just JUnit testing. So something like below should work:

Inside Presenter:

void onServerCallErrorReturned() {
    view.showErrorDialog();
} 

Inside Activity:

void showErrorDialog() {
    // Here your AlertDialog code can go.
    showDialog(getString(R.string.response_server_error));
}

void showDialog(String message) {
}

Hope this helps.

Upvotes: 1

Related Questions