From 800c7d858cbbc6521071b15dfaf0eb3b2874b72a Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 26 Feb 2012 16:20:15 +0100 Subject: missing part in fix of #695 * handling of icons for unknown cache types --- main/src/cgeo/geocaching/ui/CacheListAdapter.java | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 9ff3eb3..7d32baa 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -103,16 +103,10 @@ public class CacheListAdapter extends ArrayAdapter { Drawable modifiedCoordinatesMarker = activity.getResources().getDrawable(R.drawable.marker_usermodifiedcoords); for (final CacheType cacheType : CacheType.values()) { // unmodified icon - int hashCode = new HashCodeBuilder() - .append(cacheType) - .append(false) - .toHashCode(); + int hashCode = getIconHashCode(cacheType, false); gcIconDrawables.put(hashCode, activity.getResources().getDrawable(cacheType.markerId)); // icon with flag for user modified coordinates - hashCode = new HashCodeBuilder() - .append(cacheType) - .append(true) - .toHashCode(); + hashCode = getIconHashCode(cacheType, true); Drawable[] layers = new Drawable[2]; layers[0] = activity.getResources().getDrawable(cacheType.markerId); layers[1] = modifiedCoordinatesMarker; @@ -135,6 +129,13 @@ public class CacheListAdapter extends ArrayAdapter { } } + private static int getIconHashCode(final CacheType cacheType, final boolean userModifiedOrFinal) { + return new HashCodeBuilder() + .append(cacheType) + .append(userModifiedOrFinal) + .toHashCode(); + } + /** * change the sort order * @@ -480,13 +481,7 @@ public class CacheListAdapter extends ArrayAdapter { } holder.text.setText(cache.getNameSp(), TextView.BufferType.SPANNABLE); - int hashCode = new HashCodeBuilder() - .append(cache.getType()).append(cache.hasUserModifiedCoords() || cache.hasFinalDefined()).toHashCode(); - if (gcIconDrawables.containsKey(hashCode)) { // cache icon - holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(hashCode), null, null, null); - } else { // unknown cache type, "mystery" icon - holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(CacheType.MYSTERY), null, null, null); - } + holder.text.setCompoundDrawablesWithIntrinsicBounds(getCacheIcon(cache), null, null, null); if (holder.inventory.getChildCount() > 0) { holder.inventory.removeAllViews(); @@ -630,6 +625,16 @@ public class CacheListAdapter extends ArrayAdapter { return v; } + private static Drawable getCacheIcon(cgCache cache) { + int hashCode = getIconHashCode(cache.getType(), cache.hasUserModifiedCoords() || cache.hasFinalDefined()); + if (!gcIconDrawables.containsKey(hashCode)) { + // fallback to mystery icon + hashCode = getIconHashCode(CacheType.MYSTERY, cache.hasUserModifiedCoords() || cache.hasFinalDefined()); + } + + return gcIconDrawables.get(hashCode); + } + @Override public void notifyDataSetChanged() { super.notifyDataSetChanged(); -- cgit v1.1