aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/gcvote
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/gcvote')
-rw-r--r--main/src/cgeo/geocaching/gcvote/GCVote.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java
index 077add2..663fd20 100644
--- a/main/src/cgeo/geocaching/gcvote/GCVote.java
+++ b/main/src/cgeo/geocaching/gcvote/GCVote.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.cgCache;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.LeastRecentlyUsedCache;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -223,4 +224,37 @@ public final class GCVote {
return result.trim().equalsIgnoreCase("ok");
}
+
+ public static void loadRatings(ArrayList<cgCache> caches) {
+ if (!Settings.isRatingWanted()) {
+ return;
+ }
+
+ final ArrayList<String> guids = new ArrayList<String>(caches.size());
+ for (final cgCache cache : caches) {
+ String guid = cache.getGuid();
+ if (StringUtils.isNotBlank(guid)) {
+ guids.add(guid);
+ }
+ }
+
+ try {
+ final Map<String, GCVoteRating> ratings = GCVote.getRating(guids, null);
+
+ if (MapUtils.isNotEmpty(ratings)) {
+ // save found cache coordinates
+ for (cgCache cache : caches) {
+ if (ratings.containsKey(cache.getGuid())) {
+ GCVoteRating rating = ratings.get(cache.getGuid());
+
+ cache.setRating(rating.getRating());
+ cache.setVotes(rating.getVotes());
+ cache.setMyVote(rating.getMyVote());
+ }
+ }
+ }
+ } catch (Exception e) {
+ Log.e(Settings.tag, "GCvote.loadRatings: " + e.toString());
+ }
+ }
}