Mojtaba
Mojtaba

Reputation: 392

Android MVP for complex activity

I want to implement MVP pattern in my android project . So , for Login-activity I did not have any problem . But in Activity-Main I get confused a little and now i`m not sure how should I implement its Presenter !!!

In Activity-Main there are 3 sections as Navigation-Drawer , Toolbar and a fragment .

How can I make Presenter(s) now ? I doubt to create one presenter that implements 3 others implements or

directly create 3 presenter that have access to Activity-Main ?

Thanks

Upvotes: 2

Views: 1097

Answers (3)

Code_Life
Code_Life

Reputation: 5902

From my understanding about MVP and its implementation is "P" is logic part which does all the logic/action handling. For this case i have personally created two presenters : Navigation Drawer/Home Presenter & Fragment Presenter.

Navigation/Home P : Only responsible to action related to Navigation and related to Main-Activity.

Fragement P : Having 1-1 relationship ie each fragment will have its own presenter.

For toolbar Presenter : I don't see much of a case where you should create separate presenter for toolbar, as all the action delegated via fragment and each fragment will have different items in toolbar and different handling as well.So collating them in one would just add complexity.

Upvotes: 0

milosmns
milosmns

Reputation: 3793

What we did for a complex activity (30+ screens) was to divide each screen into View and Presenter components, where View battles with Android Views, and Presenter works out the logic (pulling and preparing data from controllers, network or local storage). But yeah, Google samples contain information about pretty much everything you'll need to start. Either way you should spend more time designing and thinking about the structure rather than actually implementing it. Good luck :)

Upvotes: 1

shalini
shalini

Reputation: 365

You can create refer to google's android-architecture .According to me you should create three different presenter for your each view and then bind them.you should check this part of sample,which has very basic design

Upvotes: 3

Related Questions