Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I follow MVP architecture with 3rd party SDKs?

Tags:

android

mvp

I've seen a lot of projects that show how to implement login in MVP, but can't find anything related to Google/Facebook login.

What should we do in the case when login flow is strongly bound to Android components life cycle? I see the main benefit of MVP in that we build an abstraction above Context, but this abstraction will appear too complex when we need to follow, for example, Facebook login flow: you need to register FacebookCallback with CallbackManager, call logInWithReadPermissions() (passing Activity/Fragment to it), delegate onActivityResult() to callbackManager and this will trigger FacebookCallback's methods.

What I have on mind is to create something like

interface AuthInteractor {
    void doFacebookLogin();
    void doGoogleLogin();
}

whose implementation will know about Context and initialize GoogleApiClient. It will be injected in Presenter, but what with all this callbacks (especially in Facebook's SDK) things are going to become too complicated. Isn't it better to omit MVP in such cases?

like image 372
Yaroslav Avatar asked Mar 19 '16 14:03

Yaroslav


1 Answers

I guess you're asking this question because you're trying to merge two "ideas" to a single one in your head:

  1. Activity/Fragment are MVP views
  2. Third party SDKs depend on Activity (or, at least, Context) in order to get access to platform resources available to your application

I stumbled upon similar issues about two years ago when I researched MVP implementations in Android, and I came to a conclusion that the only way to settle all issues of this kind is to abandon the idea of Activity/Fragment being MVP views.

I posted a detailed discussion of this issue in this post: Why Activities in Android are not UI Elements

And there is also a tutorial on how to implement a better MVP in Android: MVP and MVC in Android

like image 152
Vasiliy Avatar answered Oct 11 '22 14:10

Vasiliy