Hey, Have a question: I am using MVVM pattern in ...
# kotlin-native
k
Hey, Have a question: I am using MVVM pattern in the app & my approach is: After button click from From Fragment A, navigate to Fragment B, call viewmodel, call APIs from the server (usecase, repo & repo impl part), and the result would we shown to UI (Fragment B) after observing the data. So is there any way that, after button click from Fragment A, call the API and based on the response of the API, show updated UI in the Fragments B. Current Behaviour -> Fragment A -> click button-> navigate to Fragment B and do api calls via MVVM Expected Behaviour -> Fragment A -> click button -> API call -> show Updated UI in Fragment B Does anyone know how to achieve this kind of behaviour in our android application? TIA
c
This is more appropriate for #android
k
I asked this question in android so some of the people used 😶 so I asked here. I don't know now where should I ask. This is the link for the #android channel where I posted my question: https://kotlinlang.slack.com/archives/C0B8M7BUY/p1636145133271300
c
Same when I asked a question. It seems people reserve the channel more for kotlin specific subjects, yours is more architecture based
Anyhows, not to shy away from the issue on hand
You don't seem to quite understand MVVM
Fragment A->B should be entirely in the UI layer
👍 1
But the data update should occur in the lower layers
👍 1
You can use Flows (turn them into LiveData in the viewmodel for the UI) to provide a reactive experience
k
I understand the MVVM but my question is kind of different: The purpose of the question is: when there is api error or where there is no internet we are showing 4 buttons on the screen(fragment B) but when internet is available and we are getting the data from the API, based on response we are showing button according to that. (Fragment B only) Now UI change in between, for an example I am going to click on 1 button but after getting the response, button change so it is difficult for user to understand. So I thought that first on Fragment A while I am calling the Fragment B, before that I call the API and save the response and now based on response, I populate the UI