diff options
author | Sam Judd <sam@bu.mp> | 2013-07-12 20:02:55 -0700 |
---|---|---|
committer | Sam Judd <sam@bu.mp> | 2013-07-15 11:41:33 -0700 |
commit | 64b6d88e922b1818976a45ed30754b18e9b9e6e7 (patch) | |
tree | 28a3a27c3bdd95bdd2e3ec305a5b74ad3caa7fa1 /samples | |
parent | 806522ed49bab96c11780a7986bd16767d1a0226 (diff) | |
download | glide-64b6d88e922b1818976a45ed30754b18e9b9e6e7.tar.gz |
Fix flickr api return url for incorrect image size
HashMap.keySet is not ordered :(
Diffstat (limited to 'samples')
-rw-r--r-- | samples/flickr/src/com/bumptech/flickr/api/Api.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/samples/flickr/src/com/bumptech/flickr/api/Api.java b/samples/flickr/src/com/bumptech/flickr/api/Api.java index 8c98f19f..1755d44f 100644 --- a/samples/flickr/src/com/bumptech/flickr/api/Api.java +++ b/samples/flickr/src/com/bumptech/flickr/api/Api.java @@ -10,6 +10,7 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -37,20 +38,25 @@ public class Api { put(150, "q"); put(240, "m"); put(320, "n"); - put(500, "-"); put(640, "z"); put(1024, "b"); - put(Integer.MAX_VALUE, "o"); }}; + + private static final List<Integer> SORTED_SIZE_KEYS = new ArrayList<Integer>(EDGE_TO_SIZE_KEY.size()); + static { + SORTED_SIZE_KEYS.addAll(EDGE_TO_SIZE_KEY.keySet()); + Collections.sort(SORTED_SIZE_KEYS); + } private final String sizeKey; private static String getSizeKey(int width, int height) { - final int largestEdge = width > height ? width : height; + final int largestEdge = Math.max(width, height); - final String result = EDGE_TO_SIZE_KEY.get(Integer.MAX_VALUE); - for (int edge : EDGE_TO_SIZE_KEY.keySet()) { + String result = EDGE_TO_SIZE_KEY.get(SORTED_SIZE_KEYS.get(SORTED_SIZE_KEYS.size() - 1)); + for (int edge : SORTED_SIZE_KEYS) { if (largestEdge <= edge) { - return EDGE_TO_SIZE_KEY.get(edge); + result = EDGE_TO_SIZE_KEY.get(edge); + break; } } return result; |