diff options
author | blafoo <github@blafoo.de> | 2012-01-08 19:41:12 +0100 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2012-01-08 19:43:53 +0100 |
commit | 1036767c353a6c80306f119e76efa8dcd86f2cfe (patch) | |
tree | 61fa5f98764438f416ff857476f84c7f01dbf4ae /main | |
parent | 533a9f2caaaa6cd6ac2bbbabf612c083a9c41cc6 (diff) | |
download | cgeo-1036767c353a6c80306f119e76efa8dcd86f2cfe.zip cgeo-1036767c353a6c80306f119e76efa8dcd86f2cfe.tar.gz cgeo-1036767c353a6c80306f119e76efa8dcd86f2cfe.tar.bz2 |
Cache for ratings. Avoids double requests. Fixes #939
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/cgeopopup.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/gcvote/GCVote.java | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index 75dffb1..d207ab7 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -528,6 +528,7 @@ public class cgeopopup extends AbstractActivity { private void cachesAround() { if (cache == null || cache.getCoords() == null) { showToast(res.getString(R.string.err_location_unknown)); + return; } cgeocaches.startActivityCachesAround(this, cache.getCoords()); @@ -628,7 +629,6 @@ public class cgeopopup extends AbstractActivity { public void goCompass(View view) { if (cache == null || cache.getCoords() == null) { showToast(res.getString(R.string.cache_coordinates_no)); - return; } diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java index dfd077d..fede9df 100644 --- a/main/src/cgeo/geocaching/gcvote/GCVote.java +++ b/main/src/cgeo/geocaching/gcvote/GCVote.java @@ -26,11 +26,26 @@ public final class GCVote { private static final Pattern patternVote = Pattern.compile("voteUser='([0-9.]+)'", Pattern.CASE_INSENSITIVE); private static final Pattern patternVoteElement = Pattern.compile("<vote ([^>]+)>", Pattern.CASE_INSENSITIVE); + private static Map<String, GCVoteRating> ratingsCache = new HashMap<String, GCVoteRating>(); // key = guid + + /** + * Get user rating for a given guid or geocode. For a guid first the ratings cache is checked + * before a request to gcvote.com is made. + * + * @param guid + * @param geocode + * @return + */ public static GCVoteRating getRating(String guid, String geocode) { List<String> guids = null; List<String> geocodes = null; if (StringUtils.isNotBlank(guid)) { + + GCVoteRating rating = ratingsCache.get(guid); + if (rating != null) { + return rating; + } guids = new ArrayList<String>(); guids.add(guid); } else if (StringUtils.isNotBlank(geocode)) { @@ -50,6 +65,13 @@ public final class GCVote { return null; } + /** + * Get user ratings from gcvote.com + * + * @param guids + * @param geocodes + * @return + */ public static Map<String, GCVoteRating> getRating(List<String> guids, List<String> geocodes) { if (guids == null && geocodes == null) { return null; @@ -154,6 +176,7 @@ public final class GCVote { if (StringUtils.isNotBlank(guid)) { GCVoteRating gcvoteRating = new GCVoteRating(rating, votes, myVote); ratings.put(guid, gcvoteRating); + ratingsCache.put(guid, gcvoteRating); } } } catch (Exception e) { @@ -163,6 +186,13 @@ public final class GCVote { return ratings; } + /** + * Transmit user vote to gcvote.com + * + * @param cache + * @param vote + * @return + */ public static boolean setRating(cgCache cache, double vote) { if (!cache.supportsGCVote()) { return false; |