6

I have been developing android apps for few years. Recently i have used MVP architecture in my app and after reading through a lot and making use of this Android10 github repo.

But there are few questions i have around this MVP architecture which i am looking for. Please help me to understand these better.

1) So i have three module app, domain, data. Which module presenters will go. In some app they have it in domain but i saw some other libraries have it in presentation or app module like this https://github.com/android10/Android-CleanArchitecture.

2 ) Can presenters have android related stuffs like Intents, Contexts, SharedPrefs ets? I don't think this should happen.

3) Can data module talk with app module and vice versa Or app module should talk to domain module which in term executes the things on data module

4 ) How can i do social login like Facebook with MVP architecture... any idea or link to explain? I have done that in a below way:

Activity: onFBButtonClick() --> presenter.onButtonClick() --> FacebookLoginManager.registerCallback

After this i directly get a callback on my activity on onActivityResult(int requestcode, int resultcode, Intent intent). Now according to fb sdk tutorial i have to call FbCallbackManager.onActivityResult(with all the params). But I can't pass these information in presenter as presenter should not know about intent(Platform Specific) thing. How can i now call FbcallbackManager.onActivity()?

PrzemekTom
  • 1,328
  • 1
  • 13
  • 34
anshul
  • 982
  • 1
  • 11
  • 33
  • 1
    2) Intent is really Android framework thing - must be in V part of MVP. Context - should be achievable by Dependency Injection whenever you need it, I avoid it in Presenter. SharedPrefs the same - they're strictly related to particular UseCase (or Interactor, whatever you name it). UseCase uses Repositories for data, and SharedPrefs could be such injectable Repository. Check donnfelker's response: https://www.reddit.com/r/androiddev/comments/35vgw7/in_an_mvp_architecture_where_would_accessing_the/?sort=top Personally, I wouldn't use UseCase for simple Presenter. Use Repository straight. – PrzemekTom Jan 13 '17 at 11:49
  • @Przemo What i understand from v part is View ...Activity , fragments . I don't think a way we can implement Intents as View .Any way thanks for replying. – anshul Jan 13 '17 at 12:31
  • Yep, V is Android framework part (Activities, Views, Fragments. I meant that intent related stuff, like starting new Activity, IntentFilters, BroadcastReceivers, Services etc. should be managed in View part. It actually is not a View, it is Controller. But in MVP View is actually View + simple Controller with stuff I just told, click listeners etc. – PrzemekTom Jan 13 '17 at 12:37
  • 1
    1) don't mix MVP concept with Clean Architecture concept. All MVP should go in app module. Domain, data, network, and so on are other different layers. – adalpari Jan 13 '17 at 13:05
  • 1
    @Przemo and adalPari : Yeah I agree but what about 3) and 4) question – anshul Jan 13 '17 at 13:21

1 Answers1

2

There are many approaches to implementation of MVP in Android.

Most of the approaches I've seen designate Activity/Fragment as MVP view. This seems natural initially, but too many issues and questions raises when you try to apply this scheme to a non-trivial applications.

After I investigated many MVP approaches (incl. the ones you linked), I came to a conclusion that neither Activity no Fragment should be MVC views.

The detailed reasoning behind this claim is summarized here: Why Activities are not UI Elements.

Following this line of sight, I proposed another implementation of MVP for android applications: MVP and MVC Architectures in Android.

As for your questions:

  1. Presenter is part of the "screen"
  2. Depends on which MVP approach you choose. I personally think that presenters are Activities and Fragments, therefore they can have dependencies on Android's components.
  3. I think that only the author of that git repo can answer this question.
  4. If you adopt the mindset of Activity/Fragment being presenters, you will immediately understand how to do it without polluting MVP views.

Also, as for FB integration, please see my answer here.

Community
  • 1
  • 1
Vasiliy
  • 16,221
  • 11
  • 71
  • 127