Created
January 16, 2019 04:01
-
-
Save kgundula/78912a6349344e5de2ef9ad81e41e3e4 to your computer and use it in GitHub Desktop.
Poster Adapter to show errors Picasso doesn't load the images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.popularmovies; | |
import android.content.Context; | |
import android.support.annotation.NonNull; | |
import android.support.v7.widget.RecyclerView; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import com.squareup.picasso.Picasso; | |
import java.util.ArrayList; | |
public class PosterAdapter extends RecyclerView.Adapter<PosterAdapter.PosterViewHolder> { | |
Context context; | |
private ArrayList<Movies> mMoviesList; | |
final private PosterClickListener mPosterClick; | |
public interface PosterClickListener { | |
void onClick (int posterPosition); | |
} | |
public PosterAdapter (ArrayList<Movies> movies,PosterClickListener clickListener){ | |
mMoviesList = movies; | |
mPosterClick = clickListener; | |
} | |
@NonNull | |
@Override | |
public PosterViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { | |
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext()); | |
boolean attachToParentImmediately = false; | |
context = viewGroup.getContext(); | |
View view = inflater.inflate(R.layout.grid_movie_item, viewGroup,attachToParentImmediately); | |
return new PosterViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(@NonNull PosterViewHolder holder, int position) { | |
//holder.bindView(position); | |
/*Picasso.get() | |
.load(mMoviesList.get(position).getImage()) | |
.fit() | |
.error(R.drawable.plachholder) | |
.into(holder.imageViewHolder);*/ | |
Picasso.get().load(mMoviesList.get(position).getImage().trim()) | |
.into(holder.imageViewHolder, new com.squareup.picasso.Callback() { | |
@Override | |
public void onSuccess() { | |
/*if (progressBar != null) { | |
progressBar.setVisibility(View.GONE); | |
}*/ | |
} | |
@Override | |
public void onError(Exception e) { | |
Log.i("Ygritte", e.getLocalizedMessage()); | |
} | |
}); | |
} | |
@Override | |
public int getItemCount() { | |
if (mMoviesList == null) return 0; | |
return mMoviesList.size(); | |
} | |
public class PosterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | |
final ImageView imageViewHolder; | |
PosterViewHolder (View itemView){ | |
super(itemView); | |
imageViewHolder = itemView.findViewById(R.id.iv_movie_poster); | |
imageViewHolder.setOnClickListener(this); | |
} | |
/* void bindView (int index){ | |
Picasso.with(context) | |
.load(mMoviesList.get(index).getImage()) | |
.fit() | |
.into(imageViewHolder); | |
}*/ | |
@Override | |
public void onClick(View poster) { | |
mPosterClick.onClick(getAdapterPosition()); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment