P
P
powato2016-10-16 22:32:50
Java
powato, 2016-10-16 22:32:50

How to check that all files are uploaded (using Picasso)?

I want to check that all files are loaded before rendering the MainActivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    getBitmapsByURLs(urls);
    // здесь бы знать, что да, всё уже загружено, вот список Bitmap'ов. 
}

public void getBitmapsByURLs(List<String> urls) {
    final List<Target> targets = new ArrayList<>();

    for (int i = 0; i < urls.size(); i++) {
        final int k = i;
        Target target = new Target() {

            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.i("TEMP", "Loaded: " + k);
                targets.remove(this);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                targets.remove(this);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
                Log.i("TEMP", "Preparing: " + k);
            }
        };
        targets.add(target);
        Picasso.with(this)
                .load(urls.get(i))
                .memoryPolicy(NO_CACHE, NO_STORE)
                .into(target);
    }
}

How can I check? If I add to onCreate (after getBitmapsByURLs) whilethen it will be infinite because it will run before all the images have loaded. Please tell me how to do it right? I'm still learning.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question