0

At cloud DB (firebase or Retrofit doesn't matter.),I have multiple objects like Restaurant, menu, food, user etc. With the first initiation of App,one by one, I need the fetch them all and populate Database. I can fetch any of them alone. I saw Mediatorlivedata,List>> with two object but it doesn't seem practical. There will be many data to insert and many task that bind to. What is the best practice to fit here? What is your suggestion?

Example Objects

public class Restaurant{public String id; public String name;}
public class User{public String id; public String name;}
public class Food{public String id; public String name;}

Remote Repository

LiveData<List<Restaurant>> getRestaurant();
LiveData<List<User>> getUser();
LiveData<List<Food>> getRestaurant();

insert methods to Local are void.

yardımcı Etis
  • 140
  • 2
  • 12
  • You shouldn't use LiveData at the repository level, the observer is executed in the main thread. – m0skit0 Dec 08 '19 at 15:14
  • It doesn't. It passes values to MainFragment like local implementation of Room. – yardımcı Etis Dec 08 '19 at 15:21
  • Fragment should never access repository, view model does. That's why you shouldn't use LiveData at repository level. View model then exposes only the necessary LiveData for drawing the view. – m0skit0 Dec 08 '19 at 16:18
  • Thank you for response. I understand your concern, but I implement MVVM. I wrote [this](https://stackoverflow.com/q/59236758/6517449) as quick reference. I execute LiveData at Fragment as you said.It is similar implementataion at [Codelabs LiveData](https://codelabs.developers.google.com/codelabs/android-training-livedata-viewmodel/#6).But Example shows livedata with object. Differences are not only Local,but also Remote uses LiveData to Observe and I have many objects. If I had two I can handle but too many multiple objects leads me confision. – yardımcı Etis Dec 08 '19 at 16:46

0 Answers0