Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MovieListActivity extends AppCompatActivity implements OnMovieListener {
- //RECYCLER VIEW FILM
- private RecyclerView recyclerView;
- private MovieRecyclerView movieRecyclerAdapter;
- //LIVE DATA MovieModel
- private MovieListViewModel movieListViewModel;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
- movieListViewModel = new ViewModelProvider(this).get(MovieListViewModel.class);
- //calling the observers
- //calling the method
- ConfigureRecyclerView();
- ObserveAnyChange();
- searchMovieApi("Avengers", 1);
- //Observing any data changes
- }
- private void ObserveAnyChange(){
- movieListViewModel.getMovies().observe(this, new Observer<List<MovieModel>>() {
- @Override
- public void onChanged(List<MovieModel> movieModels) {
- //Observing any data changes here
- if(movieModels != null){
- for(MovieModel movieModel: movieModels){
- Log.v("Tag", "onChanged: " + movieModel.getTitle());
- movieRecyclerAdapter.setmMovies(movieModels);
- }
- }
- }
- });
- }
- //Calling method in Main Activity
- private void searchMovieApi(String query, int pageNumber){
- movieListViewModel.searchMovieApi(query, pageNumber);
- }
- private void ConfigureRecyclerView(){
- movieRecyclerAdapter = new MovieRecyclerView(this);
- recyclerView.setAdapter(movieRecyclerAdapter);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- }
- @Override
- public void onMovieClick(int position) {
- }
- @Override
- public void onCategoryClick(String category) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement