简体   繁体   English

适配器,服务,内容提供商和其他基本元素在android应用的MVP架构中扮演什么角色?

[英]What role of adapter, service, content provider and other basic elements in MVP architecture of android app?

I figure out that it's very useful to use MVP pattern in my apps, but it's too complicated for me, how find out of role elements in apps, which is model, view, presenter? 我发现在我的应用程序中使用MVP模式非常有用,但是对我来说太复杂了,如何找出应用程序中的角色元素,即模型,视图,演示者?

  1. What is adapter of recyclerview? 什么是recyclerview适配器? I guess it should be a view, but it manage loading data to recyclerview, so it can be also presenter or model 我想它应该是一个视图,但是它可以管理将数据加载到recyclerview,因此它也可以是演示者或模型
  2. How many presenters can have view? 多少位主持人可以查看? What is basic? 基本是什么? For one view should be one present and one model? 一种观点应该是一种存在,一种模型? But if I have some view and can they use one presenter? 但是,如果我有一些看法,他们可以使用一位主持人吗?
  3. I have an app with recyclerview which is loading images from rest api. 我有一个带有recyclerview的应用程序,该应用程序从rest api加载图像。 I wanna figure out elements for MVP. 我想找出MVP的要素。 Activity with recycler view is View? 具有“回收者”视图的活动是“视图”? Adapter is Presenter? 适配器是演示者? Picasso is Model? 毕加索是模特吗? Retrofit is Model? 改装是模型吗? Notification Service for download in external storage is Model? 在外部存储中下载的Notification Service是Model吗? Image class is Model? 图像类是模型?
  4. Can you please give a link for big complex apps with MVP architecture, please? 能否请您提供具有MVP架构的大型复杂应用程序的链接?

There's no agreed definition on exactly the best way of MVP-ing in Android. 关于Android中MVP ing的最佳方式,尚无一致的定义。

My answers to your questions. 我对您问题的回答。

  1. I'd say the Adapter is a View, that is passed data from a Presenter . 我说适配器是一个视图,它是从Presenter传递的数据。
  2. I usually have 1 Presenter 1 View. 我通常有1个主持人1个视图。
  3. View : RecyclerView, Actvity, Fragment + Adpater all are views for me. 视图 :RecyclerView,Actvity,Fragment + Adpater都是我的视图。 Presenter: Is a normal java class that retrieves the data from Model (Retrofit, Sqlite, ContentProvider) and gives it the View to populate the RecyclerView. Presenter:是一个普通的Java类,它从Model (Retrofit,Sqlite,ContentProvider)检索数据,并为其提供View以填充RecyclerView。

See this article on MVP MVP上查看此文章

Note : 注意事项

  • Try to ensure the Presenter does not have any Android logic or Android stuff. 尝试确保Presenter没有任何Android逻辑或Android内容。

  • Model doesn't just mean the POJO's it can mean include storing in DB, ContentProvider etc. including network retrieval. 模型不仅意味着POJO,还意味着包括存储在DB,ContentProvider等中,包括网络检索。

  • The View should not interact with the model directly ie data retrieval, storage etc. Only via the Presenter. 视图不应直接与模型进行交互,即数据检索,存储等。 只能通过演示者进行。

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

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