package com.github.skittlesdev.kubrick.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.github.skittlesdev.kubrick.R;
import com.parse.ParseObject;
import com.squareup.picasso.Picasso;

import java.util.List;

public class FavoritesOverviewAdapter extends RecyclerView.Adapter<FavoritesOverviewAdapter.ViewHolder> {
    private List<ParseObject> favorites;
    private Context context;

    public FavoritesOverviewAdapter(List<ParseObject> favorites) {
        this.favorites = favorites;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.movies_layout, parent, false);
        return new ViewHolder(layout);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.setPoster(this.context, this.favorites.get(position).getString("poster_path"));
    }

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

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView poster;
        public ViewHolder(View itemView) {
            super(itemView);
            this.poster = (ImageView) itemView.findViewById(R.id.moviePoster);
        }
        public void setPoster(Context context, String posterPath) {
            Picasso.with(context)
                .load("http://image.tmdb.org/t/p/w500" + posterPath)
                .placeholder(R.drawable.poster_default_placeholder)
                .error(R.drawable.poster_default_error)
                .into(this.poster);
        }
    }
}

@@ -75,16 +75,47 @@
 ontext;%0A
+import android.content.Intent;%0A
 import a
@@ -275,24 +275,77 @@
 .ImageView;%0A
+import com.github.skittlesdev.kubrick.MediaActivity;%0A
 import com.g
@@ -439,16 +439,116 @@
 Picasso;
+%0Aimport info.movito.themoviedbapi.model.MovieDb;%0Aimport info.movito.themoviedbapi.model.tv.TvSeries;
 %0A%0Aimport
@@ -1246,29 +1246,13 @@
 .set
-Poster(this.context, 
+Item(
 this
@@ -1279,33 +1279,48 @@
 ion)
-.getString(%22poster_path%22)
+);%0A        holder.setPoster(this.context
 );%0A 
@@ -1478,16 +1478,48 @@
 wHolder 
+implements View.OnClickListener 
 %7B%0A      
@@ -1546,16 +1546,51 @@
 poster;%0A
+        private ParseObject item;%0A%0A
         
@@ -1724,32 +1724,82 @@
 d.moviePoster);%0A
+            this.poster.setOnClickListener(this);%0A
         %7D%0A      
@@ -1841,27 +1841,8 @@
 text
-, String posterPath
 ) %7B%0A
@@ -1936,18 +1936,37 @@
 %22 + 
+item.getString(%22
 poster
-P
+_p
 ath
+%22)
 )%0A  
@@ -2128,21 +2128,741 @@
 );%0A        %7D
+%0A%0A        @Override%0A        public void onClick(View view) %7B%0A            Context context = view.getContext();%0A%0A            Intent intent = new Intent(context, MediaActivity.class);%0A%0A            if(this.item.has(%22tmdb_movie_id%22))%7B%0A                intent.putExtra(%22MEDIA_TYPE%22, %22movie%22);%0A                intent.putExtra(%22MEDIA_ID%22, this.item.getInt(%22tmdb_movie_id%22));%0A            %7D%0A%0A            if(this.item.has(%22tmdb_series_id%22))%7B%0A                intent.putExtra(%22MEDIA_TYPE%22, %22tv%22);%0A                intent.putExtra(%22MEDIA_ID%22, this.item.getInt(%22tmdb_series_id%22));%0A            %7D%0A%0A            context.startActivity(intent);%0A        %7D%0A%0A        public void setItem(ParseObject item) %7B%0A            this.item = item;%0A        %7D
 %0A    %7D%0A%7D%0A

Implement FavoritesOverviewAdapter onClick