NohaSamir / PopularMovies

We will take the Movies Application in journey to Android Architecture component.
28 stars 8 forks source link

Use observation instead of listener interfaces since you are using `ViewModel` #4

Closed fadi-botros closed 5 years ago

fadi-botros commented 5 years ago

Good work, keep up 👍 👍 But

https://github.com/NohaSamir/PopularMovies/blob/421590e7a4234fb40a6e4f87d775b5501d131c6f/app/src/main/java/com/example/android/popularmovies/view_model/MainViewModel.java#L41

Using MVVM architecture and using ViewModel, means using observation instead of listener interfaces. An automatic observation mechanism is already provided by Google on Android called LiveData, you can use it, or you can use RxJava.

     public MutableLiveData<List<Movie>> movies = new MutableLiveData<>();

Then use setValue on the main thread, instead of invoking the listener, this would make the observation more automatic.

I think there is also something maybe more automatic, is to use MutableLiveData<List<MutableLiveData<Movie>>>, so that you can observe on a single Movie when you are binding a RecyclerView's view holder

NohaSamir commented 5 years ago

Thanks Fadi for you comment, really I need someone review what I do and evaluate it

I know that I should use live data, but I wanted to talk about LiveData in the next branch.

I promise that I will use it in the next branch.

NohaSamir commented 5 years ago

Check it now on LiveData branch