sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

Multiple presenters for view #150

Closed akbarsha03 closed 8 years ago

akbarsha03 commented 8 years ago

How can I implement multiple presenters? Say for example I want to have a separate presenter for search view and a separate presenter for the activity which has the search view.

sockeqwe commented 8 years ago

Hi, in general every View should have exactly one Presenter. Usually when you run in such a situation this is an indicator that you should split your big one view with one big presenter into multiple smaller Views having a Presenter each.

Basically your search view has a SearchPresenter, your Activity has its own Presenter.

i.e. you could create a SearchFragment with his own SearchPresenter that will be inside your Activity, but has nothing in common with the Activity and your Activity's Presenter.

If you want to use the SerachView UI widget, then you can do this too. Mosby provides support for averything that extends from android.view.View like any kind of ViewGroup (like FrameLayout) or also SearchView. So basically you could make a class MySearchView extends SerachView implements MvpView, MvpDelegateCallback{} and then you can create Presenters / ViewState with the same API as you do with any arbitary MvpActivity or MvpFrament. Some ViewGroup implementations are already provided by Mosby like MvpFrameLayout etc.