I'm currently writing an app that displays cooking recipes when clicked.
My data is stored in a custom content provider and the information for my recipes is stored in 3-4 tables.
DetailActivity contains a Fragment(Let's call is MasterFragment).
MasterFragment contains a ViewPager which holds 3 fragments that display the main parts of my model: general info, ingredients and directions. Let's call them GeneralFragment, IngredientFragment and DirectionFragment.
How it stands now, the 3 fragments of the ViewPager all receive the appropriate Uri and each has a loader that loads the data from the content provider and displays it in my UI.
My problem is that having the data loaded into the 3 fragments adds a lot of complexity to my code when it comes to updating the data in the content provider. On top of that, I feel like that doing in this manner may not be the most efficient way of fetching and displaying my data.
One alternative that I thought of was to query all the data in my MasterFragment and to pass it to each individual fragment of the ViewPager through the its adapter. Once again, this is a hassle that requires a lot of overhead and may not be optimal.
I'm thinking that the best way of doing it may be to centralize the model data into the MasterFragment and have the fragments access that data. I'm just not sure how to implement this. I'm leaning towards using a singleton recipe class but I'd rather here your opinion before implementing it.
I'd appreciate any input and I thank you in advance for your time.
tl;dr: Model needs to be accessed by 3 fragments in a viewpager, what is the best way of doing this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire