Hi guys n00b question. What would be the best/righ...
# android
a
Hi guys n00b question. What would be the best/right practice to have two viewModels talking each other. I have an object in the viewModelA and I need the ID in the viewModelB to have it on my request Any recommendation?
I'm using koin if it helps
o
Use nav args?
a
What if I have siblings fragments (view page) how could I listen for something or talk to the other view model?
o
I need to know your usecase
a
Let me elaborate something more concrete 🙏
i Have an activity and inside that i have 3 fragments inside of a ViewPage. The viewPage is showing only when i request the userInfo (at the moment that information lives in the AcitivtyViewModel). then i need to request a list of places,tickets, settings (each of them in different fragments) assuming that we are talking about get the list of places. i need in my PlacesViewModel request something like get(api/places/xxxxxxxx where
xxxxxx
is my user id that lives in ActivityViewModel. Question how could i get the data in the ActivityViewMode in the other fragmentViewModels. Do i have to pass all the info in the nav args? could koin help in the injection of properties?
o
So you have a PlacesViewModel (fragment1), TicketsViewModel(f2) and SettingsViewModel(f3). What do you need the activity viewmodel for?
a
yes, those are holding information only about their purpose. In the mainActivity i have few LiveData as a global information. DeviceInfo User info NetworkInfo SessionStatus… in my head i would like to have those properties available in each children view Model (the fragments) by injecting them as they need
o
Put those data in a seperate component, and inject that into all 3 viewmodles
Id like to avoid a parent vm and child vm, it is confusing
a
what do you mean by
seperate component
? something like a shareViewModel?
o
Something like a repository
👌 1
a
Thanks let me try that :)