diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-01-12 16:15:29 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-01-12 23:21:55 +0100 |
| commit | 7fe17b6b441e145e7e4c46f0aed83b86a00d4e57 (patch) | |
| tree | 29136ac2e174221f8ab65bb4e7874e6a2de6f1f2 /main/src/cgeo/geocaching/ui | |
| parent | df177f0e15f4a8fa3dd378648477200596306be9 (diff) | |
| download | cgeo-7fe17b6b441e145e7e4c46f0aed83b86a00d4e57.zip cgeo-7fe17b6b441e145e7e4c46f0aed83b86a00d4e57.tar.gz cgeo-7fe17b6b441e145e7e4c46f0aed83b86a00d4e57.tar.bz2 | |
When storing a cache, download images concurrently
Up to 5 downloads can happen simultaneously. Also, those downloads are
executed concurrently to static map requests if any.
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
| -rw-r--r-- | main/src/cgeo/geocaching/ui/ImagesList.java | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index fb2ac15..f564583 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -9,16 +9,8 @@ import cgeo.geocaching.utils.Log; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; - -import rx.Observable; -import rx.Observable.OnSubscribeFunc; -import rx.Observer; -import rx.Scheduler; -import rx.Subscription; import rx.android.concurrency.AndroidSchedulers; -import rx.concurrency.Schedulers; import rx.subscriptions.CompositeSubscription; -import rx.subscriptions.Subscriptions; import rx.util.functions.Action1; import android.app.Activity; @@ -46,9 +38,6 @@ import java.io.FileOutputStream; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; public class ImagesList { @@ -82,9 +71,6 @@ public class ImagesList { private final String geocode; private LinearLayout imagesView; - private Scheduler downloadScheduler = Schedulers.executor(new ThreadPoolExecutor(5, 5, 5, TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>())); - public ImagesList(final Activity activity, final String geocode) { this.activity = activity; this.geocode = geocode; @@ -92,9 +78,10 @@ public class ImagesList { } public void loadImages(final View parentView, final List<Image> images, final boolean offline) { - imagesView = (LinearLayout) parentView.findViewById(R.id.spoiler_list); + final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false); + for (final Image img : images) { final LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); assert(rowView != null); @@ -110,8 +97,7 @@ public class ImagesList { descView.setVisibility(View.VISIBLE); } - subscriptions.add(loadImage(img, offline) - .subscribeOn(downloadScheduler) + subscriptions.add(imgGetter.fetchDrawable(img.getUrl()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<BitmapDrawable>() { @Override public void call(final BitmapDrawable image) { @@ -123,18 +109,6 @@ public class ImagesList { } } - private Observable<BitmapDrawable> loadImage(final Image img, final boolean offline) { - return Observable.create(new OnSubscribeFunc<BitmapDrawable>() { - @Override - public Subscription onSubscribe(final Observer<? super BitmapDrawable> observer) { - final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? StoredList.STANDARD_LIST_ID : StoredList.TEMPORARY_LIST_ID, false); - observer.onNext(imgGetter.getDrawable(img.getUrl())); - observer.onCompleted(); - return Subscriptions.empty(); - } - }); - } - private void display(final BitmapDrawable image, final Image img, final LinearLayout view) { if (image != null) { bitmaps.add(image.getBitmap()); |
