简体   繁体   English

有关Android应用的MVP模式的问题

[英]Questions on MVP Pattern for Android apps

I have been developing android apps for few years. 我已经开发了android应用几年了。 Recently i have used MVP architecture in my app and after reading through a lot and making use of this Android10 github repo. 最近,我在应用中使用了MVP架构,并通读了很多内容并利用了Android10 github存储库。

But there are few questions i have around this MVP architecture which i am looking for. 但是我对这种MVP架构几乎没有疑问。 Please help me to understand these better. 请帮助我更好地理解这些。

1) So i have three module app, domain, data. 1)所以我有三个模块的应用程序,域,数据。 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 . 在某些应用程序中,它们在域中具有它,但是我看到其他一些库在演示文稿或应用程序模块中具有此https://github.com/android10/Android-CleanArchitecture

2 ) Can presenters have android related stuffs like Intents, Contexts, SharedPrefs ets? 2)演示者可以拥有与Android有关的东西,例如Intent,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 3)数据模块可以与应用程序模块通信,反之亦然?或者应用程序模块应该与域模块通信,该域模块将在数据模块上执行事务

4 ) How can i do social login like Facebook with MVP architecture... any idea or link to explain? 4)我该如何使用MVP架构进行类似于Facebook的社交登录?有什么想法或链接可以解释吗? I have done that in a below way: 我以下面的方式做到了:

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

After this i directly get a callback on my activity on onActivityResult(int requestcode, int resultcode, Intent intent) . 之后,我直接在onActivityResult(int requestcode, int resultcode, Intent intent)上获得我的活动的回调。 Now according to fb sdk tutorial i have to call FbCallbackManager.onActivityResult(with all the params) . 现在根据fb sdk教程,我必须调用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() ? 我现在如何调用FbcallbackManager.onActivity()

There are many approaches to implementation of MVP in Android. 在Android中有多种实现MVP的方法。

Most of the approaches I've seen designate Activity/Fragment as MVP view. 我见过的大多数方法都将“活动/片段”指定为MVP视图。 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. 在研究了许多MVP方法(包括您链接的方法)之后,我得出一个结论,即“活动无片段”都不应该是MVC视图。

The detailed reasoning behind this claim is summarized here: Why Activities are not UI Elements . 此处总结了此主张背后的详细原因: 为什么活动不是UI元素

Following this line of sight, I proposed another implementation of MVP for android applications: MVP and MVC Architectures in Android . 根据这一观点,我提出了针对Android应用程序的MVP的另一种实现:Android中的MVP和MVC体系结构

As for your questions: 至于您的问题:

  1. Presenter is part of the "screen" 主持人是“屏幕”的一部分
  2. Depends on which MVP approach you choose. 取决于您选择哪种MVP方法。 I personally think that presenters are Activities and Fragments, therefore they can have dependencies on Android's components. 我个人认为演示者是活动和片段,因此他们可以依赖于Android的组件。
  3. I think that only the author of that git repo can answer this question. 我认为只有git repo的作者才能回答这个问题。
  4. If you adopt the mindset of Activity/Fragment being presenters, you will immediately understand how to do it without polluting MVP views. 如果您采用“活动/片段作为演示者”的思维方式,您将立即了解如何做到这一点而不会污染MVP视图。

Also, as for FB integration, please see my answer here . 另外,关于FB集成,请在此处查看我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM