package com.jonasgerdes.schauburgr.usecase.home.movies.movie_list;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jonasgerdes.schauburgr.R;
import com.jonasgerdes.schauburgr.model.Movie;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jonas on 05.03.2017.
 */

public class MovieListAdapter extends RecyclerView.Adapter<MovieHolder> {

    private List<Movie> mMovies = new ArrayList<>();

    @Override
    public MovieHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_movies_item_movie, parent, false);
        return new MovieHolder(view);
    }

    @Override
    public void onBindViewHolder(MovieHolder holder, int position) {
        Movie movie = mMovies.get(position);
        holder.onBind(movie);
    }

    @Override
    public int getItemCount() {
        return mMovies.size();
    }

    public void setMovies(List<Movie> movies) {
        mMovies = movies;
        notifyDataSetChanged();
    }
}

@@ -339,16 +339,84 @@
 .List;%0A%0A
+import io.realm.RealmChangeListener;%0Aimport io.realm.RealmResults;%0A%0A
 /**%0A * C
@@ -1125,20 +1125,28 @@
 tMovies(
-List
+RealmResults
 %3CMovie%3E 
@@ -1209,20 +1209,254 @@
 tChanged();%0A
+        movies.addChangeListener(new RealmChangeListener%3CRealmResults%3CMovie%3E%3E() %7B%0A            @Override%0A            public void onChange(RealmResults%3CMovie%3E element) %7B%0A                notifyDataSetChanged();%0A            %7D%0A        %7D);%0A
     %7D%0A%7D%0A

Add automatic refresh of movies when new data is available