MVP with fragments

I can't figure out how activiti and fragments should communicate with each other during MVP. For example, there is an activity with a ViewPager, in which there are 3 fragments, one of which calls another fragment. 1) What would an implementation with MVP look like? The activity and all fragments will be separate views, with separate presenters? Or will there be one presenter for them? 2) How should the interaction of fragments and activiti occur? As I understand it, the activity should interact with fragments via a presenter? 3) If a fragment calls another fragment, how should their interaction occur?

Author: a.zhonin, 2018-07-11

1 answers

I would answer like this:

  1. It depends on how much code and functionality there is. If we assume that each fragment has 1-2 functions to call in-from the fragment - and the total of does not exceed 10-one is enough.

  2. There should be no logic in the activity itself, it generates fragments, creates or connects to the presenter, and that's it. any interaction is via presenter.

  3. It depends on the difficulty of navigation. For example, if it is only 3 fragments - this logic can be in the Presenter. If more than 5-it is better to select a separate layer Navigotor / Locator.

A good example of navigation with MVP c Cicerone https://github.com/terrakok/Cicerone/tree/develop/sample/src/main/java/ru/terrakok/cicerone/sample/mvp

This video also reveals some MVP structuring issues https://events.yandex.ru/lib/talks/5076/

 3
Author: Serge Markov, 2018-07-12 02:36:49