0

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));
alexpfx
  • 6,412
  • 12
  • 52
  • 88
  • http://stackoverflow.com/questions/33885561/does-picasso-library-for-android-handle-image-loading-while-network-connectivity – Anurag Aggarwal Jan 16 '17 at 23:14
  • @AnuragAggarwal I have seen this post, but I don't want to use image cache, alias, I want to, but when there is no image in cache I want to hide the progress bar and shows error image. – alexpfx Jan 16 '17 at 23:17
  • Does your `R.drawable.ic_error` load into the ImageView? – Eric Cochran Jan 17 '17 at 20:42
  • I Never see it when implementing this way. I only see it when I don't make use of Callback. – alexpfx Jan 17 '17 at 23:30

1 Answers1

0

Does Picasso library for Android handle image loading while network connectivity is off?

Please take a look at the above link regarding the same issue .

Community
  • 1
  • 1
Anurag Aggarwal
  • 247
  • 1
  • 5
  • It not works... onError method is never called. I have tried it before. – alexpfx Jan 16 '17 at 23:19
  • private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } You can use it to check if device is online or offline . If its offlne then no need to initiate picasso call – Anurag Aggarwal Jan 16 '17 at 23:29