Search code examples
androidpicasso

Synchronise two Targets[Picasso]


I need two images loaded for custom view, so I use two targets:

private void loadImage(String[] url) {
    Picasso.with(getActivity()).load(url[0]).into(mLeftImageTarget);
    if(url.length>1) {
        Picasso.with(getActivity()).load(url[1]).into(mRightImageTarget);
    }
}

private Target mLeftImageTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            mView.setBitmaps(bitmap, null);
        }
};

private Target mRightImageTarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            mView.setBitmaps(null, bitmap);
        }
};

The problem is that I don't want to load call mView.setBitmaps() for each bitmap separately, I'd rather wait for both images to download and only then set bitmaps for view. But I can't find a way to synchronise two targets. Can this be accomplished with Picasso?


Solution

  • I ended up using synchronous download, wrapped into AsyncTask using RequestCreator.get()