2

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

Mojtaba
  • 382
  • 1
  • 3
  • 19

3 Answers3

3

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

shalini
  • 355
  • 4
  • 17
1

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 :)

milosmns
  • 3,595
  • 4
  • 36
  • 48
  • Thank for your replay.I saw Google’s samples and I learned MVP pattern.But my problem is : how many presenter should I create ? 3 or one? What's conversion? – Mojtaba Sep 13 '16 at 19:48
  • Ok more info - maybe you should look into this question before implementing: http://stackoverflow.com/questions/19444431/what-is-difference-between-mvc-mvp-mvvm-design-pattern-in-terms-of-coding-c-s – milosmns Sep 13 '16 at 19:51
  • You may be looking for MVVM pattern instead. If you find it attractive enough, it really depends on what you are doing inside your app - I cannot give you any advice without actually knowing the business logic (which you should not post here on SO). When you are sure you have grouped your use cases together, it should be easy to extract a good data model from that and work on separating business logic. From what I can read now, it seems that you will need one presenter for the navigation drawer + one presenter for the main container. But again, it depends on your use cases and requirements :) – milosmns Sep 13 '16 at 19:54
0

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.

Code_Life
  • 5,742
  • 4
  • 29
  • 49