0

I have been pulling my hair out over this bug as it isn't exactly reproducible. I have a custom recycler adapter which loads values from a database. It calls a network helper class to build a URL and load an image using Ion. This bug doesn't appear to be affected by scroll speed, but I think it may be affected by the amount of image calls made to the server at once.

 public ThreadAdapter(Cursor cursor) {
    super(cursor);
}

@Override
public void onBindViewHolderCursor(RecyclerView.ViewHolder holder, Cursor cursor) {
    ThreadViewHolder threadViewHolder = (ThreadViewHolder)holder;

    networkHelper.getImage(threadViewHolder.image,
            cursor.getString(cursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_IMAGE_NAME),
            cursor.getString(cursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_IMAGE_EXTENSION))
    );
}


@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = inflater.from(parent.getContext()).inflate(R.layout.card_thread, parent, false);
    ThreadViewHolder viewHolder = new ThreadViewHolder(view);
    return viewHolder;
}

class ThreadViewHolder extends RecyclerView.ViewHolder{
    public ImageView image;

    public ThreadViewHolder(View itemView) {
        super(itemView);
        image = (ImageView) itemView.findViewById(R.id.thread_image);
    }

}

https://gist.github.com/Shywim/127f207e7248fe48400b

public void getImage(ImageView imageView, String name, String extension){
    if (name != null && extension != null){
        String imageUrl = "example.com/" + name + extension;

        Log.d(LOG_TAG, "Image Url " + imageUrl);
        Ion.with(imageView)
                .fitCenter()
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.error)
                .load(imageUrl);
    }else {
        imageView.setImageBitmap(null);
    }
}

It appears to be building the URL correctly and only calling Ion when something needs to be called. I sometimes will see the placeholder image appear and then disappear. I never have seen the error image appear at all. I think if item A, item B and item C all have images that need to be loaded and all appear at the same time, the odds are greater that it will fail loading them.

fsdhuio
  • 1
  • 4
  • Why not use Picasso instead? – Mike Jun 03 '15 at 21:40
  • No major reason besides having to either implement two libraries adding to my application size which I would like to avoid. I decided to use Ion because it was advertised to unify a lot of my networking calls into a single framework. – fsdhuio Jun 03 '15 at 22:23

0 Answers0