Hi,
thanks for the great android architecture examples.
Please create a sample that uses mvp.
thx
It's not trivial to set up MVP when dealing with multiple fragments in a single activity, as we will show with the tablet layout #3 . However, since viewpager-tab is not an architecture pattern or architectural tool, I'm going to close the issue as it will not be part of the official set of variants.
Thanks!
@JoseAlcerreca Because viewpager are often used in apps, I'm looking forward to the tablet layout.
I had an issue to use the mvp clean architecture with a viewpager where the fragments of the tabs needed to communicate with the parent view. I solved it by using a single presenter for the main view and the child fragments (that are still separated views in the view layer) treating them as if they were a single view from the perspective of the presentation layer. It was a bit more complicated to implement some startup logic like loading but after all it's much more simple than using an event bus or something else suggested in some of the discussions I've read.
Would you like to show your sample? Maybe add it here as external one? I'm very interested.
I've used it in one of my projects (here). Basically a new fragment inside the viewpager calls a listener method on its parent as soon as it's created which notifies the presenter about a newly created view (in addView()). In that method the the loading task is triggered if (in my case) both fragments are initialized.
I recently found that it might be better to define a more abstract relation between parent and child controller (the child controller is currently unused) since in the future or in another way of using this technique it might be necessary to store more details of the child view. And since it seems to be best practice to avoid having data about the model inside the view (e.g. fragment) I'm currently experimenting to accomplish that using interfaces for parent and client controllers defining setParent(presenter) and setChild(presenter, index).
It's difficult to explain that approach without having explicitly written any code for it yet (I've only solved the issue theoretically for now). I'll report back when I'm finished with it and got it working.
Hi,
Had the same problem. Found out this:
http://duzi077.tistory.com/131
A tutorial on how to implement the todo app samples with MVP with TabLayout and ViewPager.
Same question.
Tab layout is recomended in material guidelines for navigation when you have more than five destinations.
https://material.io/design/components/bottom-navigation.html
I am trying to create a dagger mvp app with tab layout.
Thanks to @Kavi-Ramsamy, I will check that example.
I remember way back in time that android 1.5 had TabActivity.
Now with fragment based tabs is more difficult to follow this architectural approach (mvp-dagger-todoapp) of spliting your components/views by Activity.
Most helpful comment
I've used it in one of my projects (here). Basically a new fragment inside the viewpager calls a listener method on its parent as soon as it's created which notifies the presenter about a newly created view (in
addView()). In that method the the loading task is triggered if (in my case) both fragments are initialized.I recently found that it might be better to define a more abstract relation between parent and child controller (the child controller is currently unused) since in the future or in another way of using this technique it might be necessary to store more details of the child view. And since it seems to be best practice to avoid having data about the model inside the view (e.g. fragment) I'm currently experimenting to accomplish that using interfaces for parent and client controllers defining
setParent(presenter)andsetChild(presenter, index).It's difficult to explain that approach without having explicitly written any code for it yet (I've only solved the issue theoretically for now). I'll report back when I'm finished with it and got it working.