How can I follow the MVP architecture with third-party SDKs?

I have seen many projects that show how to implement login in MVP, but cannot find anything related to login to Google / Facebook.

What should we do when the login thread is tied to the life cycle of the Android components? I see the main advantage of MVP is that we build the abstraction above Context , but this abstraction will be too complicated when we need to follow, for example, the Facebook login flow: you need to register FacebookCallback using CallbackManager , call logInWithReadPermissions() (passing Activity to it / Fragment), delegate onActivityResult() to the CallbackManager , and this will call the FacebookCallback methods.

What I mean is to create something like

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

whose implementation will know about Context and initialize GoogleApiClient . It will be introduced in Presenter, but with all these callbacks (especially the Facebook SDK), everything will be too complicated. Isn't it better to skip MVP in such cases?

+6
source share
1 answer

I think you are asking this question because you are trying to combine two "ideas" with one in your head:

  • Activity / fragment are MVP views
  • Third-party SDKs depend on Activity (or, at least, context) to gain access to platform resources available to your application.

I encountered similar problems about two years ago when I was researching MVP implementations in Android, and I came to the conclusion that the only way to solve all problems of this kind is to abandon the idea of โ€‹โ€‹Activity / Fragment representing MVP representations.

I posted a detailed discussion of this issue in this post: Why actions in Android are not user interface elements

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

+2
source

All Articles