aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java11
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java18
-rw-r--r--main/src/cgeo/geocaching/ui/DirectionImage.java10
3 files changed, 21 insertions, 18 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 5c03dd7..f20df8d 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -28,7 +28,6 @@ import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.settings.Settings;
-import cgeo.geocaching.ui.DirectionImage;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.HtmlUtils;
import cgeo.geocaching.utils.JsonUtils;
@@ -343,16 +342,6 @@ public abstract class GCParser {
}
}
- // get direction images
- if (Settings.getLoadDirImg()) {
- final Set<Geocache> cachesReloaded = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
- for (final Geocache cache : cachesReloaded) {
- if (cache.getCoords() == null && StringUtils.isNotEmpty(cache.getDirectionImg())) {
- DirectionImage.getDrawable(cache.getDirectionImg());
- }
- }
- }
-
return searchResult;
}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 34cac01..ebbe23f 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -27,9 +27,13 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.eclipse.jdt.annotation.NonNull;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
+
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.text.Spannable;
@@ -111,6 +115,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
@InjectView(R.id.inventory) protected ImageView inventory;
@InjectView(R.id.direction) protected CompassMiniView direction;
@InjectView(R.id.dirimg) protected ImageView dirImg;
+ public Geocache cache = null;
public ViewHolder(final View view) {
super(view);
@@ -378,6 +383,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
} else {
holder = (ViewHolder) v.getTag();
}
+ holder.cache = cache;
final boolean lightSkin = Settings.isLightSkin();
@@ -457,9 +463,17 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
holder.direction.updateAzimuth(azimuth);
holder.direction.updateHeading(cache.getDirection());
} else if (StringUtils.isNotBlank(cache.getDirectionImg())) {
- holder.dirImg.setImageDrawable(DirectionImage.getDrawable(cache.getDirectionImg()));
- holder.dirImg.setVisibility(View.VISIBLE);
+ holder.dirImg.setVisibility(View.INVISIBLE);
holder.direction.setVisibility(View.GONE);
+ DirectionImage.fetchDrawable(cache.getDirectionImg()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<BitmapDrawable>() {
+ @Override
+ public void call(final BitmapDrawable bitmapDrawable) {
+ if (cache == holder.cache) {
+ holder.dirImg.setImageDrawable(bitmapDrawable);
+ holder.dirImg.setVisibility(View.VISIBLE);
+ }
+ }
+ });
} else {
holder.dirImg.setVisibility(View.GONE);
holder.direction.setVisibility(View.GONE);
diff --git a/main/src/cgeo/geocaching/ui/DirectionImage.java b/main/src/cgeo/geocaching/ui/DirectionImage.java
index cd7695e..e08ff51 100644
--- a/main/src/cgeo/geocaching/ui/DirectionImage.java
+++ b/main/src/cgeo/geocaching/ui/DirectionImage.java
@@ -3,22 +3,22 @@ package cgeo.geocaching.ui;
import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.network.HtmlImage;
-import org.apache.commons.lang3.StringUtils;
+import rx.Observable;
import android.graphics.drawable.BitmapDrawable;
public class DirectionImage {
- static private HtmlImage htmlImage = new HtmlImage(HtmlImage.SHARED, false, StoredList.STANDARD_LIST_ID, false);
+ static final private HtmlImage HTML_IMAGE = new HtmlImage(HtmlImage.SHARED, false, StoredList.STANDARD_LIST_ID, false);
/**
* Retrieve the direction image corresponding to the direction code.
*
* @param directionCode one of the eight cardinal points
- * @return a drawable with the arrow pointing into the right direction
+ * @return an observable containing zero or more drawables (the last one being the freshest image)
*/
- public static BitmapDrawable getDrawable(final String directionCode) {
- return StringUtils.isNotBlank(directionCode) ? htmlImage.getDrawable("http://www.geocaching.com/images/icons/compass/" + directionCode + ".gif") : null;
+ public static Observable<BitmapDrawable> fetchDrawable(final String directionCode) {
+ return HTML_IMAGE.fetchDrawable("https://www.geocaching.com/images/icons/compass/" + directionCode + ".gif");
}
}