I have this implementation of image loading with Picasso. I want it shows a progress bar while loading the image from URL. When it is loading, the progress bar is hidden. If it can't, I want it shows the error image instead and even then hide the ProgressBar.
But if there isn't network connection it never calls onError and the ProgressBar is always visible.
public class PicassoShowImageHideProgressBarCallback extends Callback.EmptyCallback {
private ImageView mImageView;
private ProgressBar mProgressBar;
private static final String TAG = "PicassoShowImageHidePro";
public PicassoShowImageHideProgressBarCallback(ImageView imageView,
ProgressBar progressBar) {
mImageView = imageView;
mProgressBar = progressBar;
}
@Override
public void onSuccess() {
mImageView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
mProgressBar.setVisibility(View.GONE);
}
}
@BindView(R.id.poster_image)
ImageView mImageView;
@BindView(R.id.pb_progress_loading)
ProgressBar mProgressBar;
Picasso.with(mContext).load(path).error(R.drawable.ic_error).into(mImageView,
new PicassoShowImageHideProgressBarCallback(mImageView, mProgressBar));