From d96c4c2212c249056296a2f7179af449cf6f6d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Thu, 8 Sep 2016 21:17:50 +0200 Subject: [PATCH] Addied usage of wiki app objects --- .../dto/wiki/app/WikiAppObject.java | 18 ++++---- .../urbanexplorer/utils/WikiUtils.java | 43 ++++++++++++++++--- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java index 8ddffcf..0241b55 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java @@ -9,9 +9,9 @@ public class WikiAppObject implements Serializable { private String url; private String thumbnail; private String title; - private String latitude; - private String longitude; - private String distance; + private Double latitude; + private Double longitude; + private Double distance; public String getUrl() { return url; @@ -37,27 +37,27 @@ public class WikiAppObject implements Serializable { this.title = title; } - public String getLatitude() { + public Double getLatitude() { return latitude; } - public void setLatitude(String latitude) { + public void setLatitude(Double latitude) { this.latitude = latitude; } - public String getLongitude() { + public Double getLongitude() { return longitude; } - public void setLongitude(String longitude) { + public void setLongitude(Double longitude) { this.longitude = longitude; } - public String getDistance() { + public Double getDistance() { return distance; } - public void setDistance(String distance) { + public void setDistance(Double distance) { this.distance = distance; } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java index 9c210a2..efb48b7 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java @@ -11,6 +11,7 @@ import org.json.JSONException; import org.json.JSONObject; import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback; import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus; +import pl.tpolgrabia.urbanexplorer.dto.wiki.app.WikiAppObject; import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiLocation; import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiPage; import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiResponse; @@ -19,9 +20,7 @@ import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoObject; import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponse; import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponseCallback; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * Created by tpolgrabia on 28.08.16. @@ -223,21 +222,49 @@ public class WikiUtils { fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() { @Override public void callback(WikiStatus status, WikiGeoResponse response) { - List geoData = response.getQuery(); - if (geoData == null) { + final List geoItems = response.getQuery(); + if (geoItems == null) { return; } List pageIds = new ArrayList(); - for (WikiGeoObject wikiGeoObject : geoData) { + for (WikiGeoObject wikiGeoObject : geoItems) { pageIds.add(wikiGeoObject.getPageId()); } + final Map geoItemsMap = new HashMap<>(); + for (WikiGeoObject geoItem : geoItems) { + geoItemsMap.put(geoItem.getPageId(), geoItem); + } + WikiResponseCallback tcallback = callback; fetchPageInfos(ctx, pageIds, - tcallback); + new WikiResponseCallback() { + @Override + public void callback(WikiStatus status, WikiResponse response) { + if (status != WikiStatus.SUCCESS) { + return; + } + + List results = new ArrayList(); + List pages = response.getPages(); + for (WikiPage page : pages) { + WikiAppObject appObject = new WikiAppObject(); + appObject.setTitle(page.getTitle()); + appObject.setDistance(geoItemsMap.get(page.getPageId()).getDistance()); + appObject.setLatitude(page.getCoordinates().get(0).getLatitude()); + appObject.setLongitude(page.getCoordinates().get(0).getLongitude()); + appObject.setThumbnail(page.getThumbnail().getSource()); + appObject.setUrl(page.getThumbnail().getSource()); + results.add(appObject); + } + + // TODO here add callback invocation with result + + } + }); } }); @@ -269,4 +296,6 @@ public class WikiUtils { } }); } + + }