I am trying to use RecylerView
which Google introduced recently. I have a set of rows there, 7-8 for now, and each row has a image which I am getting from server. For this I am using Picasso library but this is not working for me. I am not sure if I am missing something or configure something.
The screen is correctly showing the default image on each row but doesn't download image from server and I wait more than 5 minutes if slow response from server but that is not the case.
Code
public DemoRecyclerAdapter(List<DemoRowModel> items, int itemLayout, final Context mContext) {
this.items = items;
this.itemLayout = itemLayout;
this.mContext = mContext;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
DemoRowModel item = items.get(position);
holder.mDemoNameTextView.setText(item.getDemoName());
holder.mDemoDateTextView.setText(item.getDemoDate());
Target mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
holder.mImageView.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable drawable) {
Logger.d(TAG, "Failed! Bitmap could not downloaded.");
}
@Override
public void onPrepareLoad(Drawable drawable) {
}
};
Picasso.Builder builder = new Picasso.Builder(mContext);
Picasso picasso = builder.downloader(new OkHttpDownloader(mContext) {
@Override
protected HttpURLConnection openConnection(Uri uri) throws IOException {
HttpURLConnection connection = super.openConnection(uri);
// fetch the auth value
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext.getApplicationContext());
connection.setRequestProperty(Constant.HEADER_X_API_KEY, mSharedPreferences.getString(SharedPreferenceKeys.JSESSIONID, ""));
return connection;
}
}).build();
picasso.load(item.getImagePath()).into(mTarget);
// here set the value
holder.itemView.setTag(item);
}
Thanks in advance.