package com.kishorebabu.popularmovies;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.kishorebabu.popularmovies.model.Movie;
import com.squareup.picasso.Picasso;

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

/**
 * Created by Kishore on 2/28/2016.
 */
public class MoviesGridAdapter extends RecyclerView.Adapter<MoviesGridAdapter.MovieViewHolder> {

    Context context;
    List<Movie> movies;

    public MoviesGridAdapter(Context context) {
        this.context = context;
    }

    public void addMovies(List<Movie> movies) {
        if (this.movies == null)
            this.movies = new ArrayList<>();
        this.movies.addAll(movies);
        notifyDataSetChanged();
    }

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

    @Override
    public void onBindViewHolder(MovieViewHolder holder, int position) {
        if (position < movies.size()) {
            final Movie movie = movies.get(position);
            Picasso.with(context)
                    .load(String.format("http://image.tmdb.org/t/p/w185/%s", movie.getPosterPath()))
                    .into(holder.moviePoster);

            holder.moviePoster.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MovieDetails.class);
                    intent.putExtra(Constants.KEY_MOVIE, movie);
                    context.startActivity(intent);
                }
            });
        }


    }

    @Override
    public int getItemCount() {
        if (movies != null)
            return movies.size();
        return 0;
    }

    public class MovieViewHolder extends RecyclerView.ViewHolder {
        private ImageView moviePoster;

        public MovieViewHolder(View itemView) {
            super(itemView);
            moviePoster = (ImageView) itemView.findViewById(R.id.movie_poster);
        }
    }
}

@@ -920,32 +920,175 @@
 anged();%0D    %7D%0D%0D
+    public void clearMovies() %7B%0D        if (movies != null) %7B%0D            movies.clear();%0D            notifyDataSetChanged();%0D        %7D%0D    %7D%0D%0D
     @Override%0D  

Add method to clear the adapter list