MVP-7: Make Presenters dependent on Views, and not Activities.


Description

Not only does this abstract away from the Android framework. But also improves the testability of the Presenters. Make the Activities implement a view interface. This also prevents the Presenter to access methods which should not be accessible from the Activity.

Example

We created a simple MVP login Application.

As described above the presenter is dependent on views and not the activity.

The GreetPresenter has only a reference to a GreetView. The GreetActivity implements the GreetView.

The GreetPresenter makes changes to the Activity via the view. To show the message, mGreetView.showMessage(mCredentials.getPersonalizedGreeting()); is being called.

Which in the mainActivity is described as:

The message has been added to the TextView personalGreetingTextView.

Check out the Github page to view the complete repository.