Addied usage of wiki app objects

master
Tomasz Półgrabia 2016-09-08 21:17:50 +02:00
parent 953e27ea2f
commit d96c4c2212
2 changed files with 45 additions and 16 deletions

View File

@ -9,9 +9,9 @@ public class WikiAppObject implements Serializable {
private String url; private String url;
private String thumbnail; private String thumbnail;
private String title; private String title;
private String latitude; private Double latitude;
private String longitude; private Double longitude;
private String distance; private Double distance;
public String getUrl() { public String getUrl() {
return url; return url;
@ -37,27 +37,27 @@ public class WikiAppObject implements Serializable {
this.title = title; this.title = title;
} }
public String getLatitude() { public Double getLatitude() {
return latitude; return latitude;
} }
public void setLatitude(String latitude) { public void setLatitude(Double latitude) {
this.latitude = latitude; this.latitude = latitude;
} }
public String getLongitude() { public Double getLongitude() {
return longitude; return longitude;
} }
public void setLongitude(String longitude) { public void setLongitude(Double longitude) {
this.longitude = longitude; this.longitude = longitude;
} }
public String getDistance() { public Double getDistance() {
return distance; return distance;
} }
public void setDistance(String distance) { public void setDistance(Double distance) {
this.distance = distance; this.distance = distance;
} }

View File

@ -11,6 +11,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback; import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback;
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus; 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.WikiLocation;
import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiPage; import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiPage;
import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiResponse; 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.WikiGeoResponse;
import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponseCallback; import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponseCallback;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
/** /**
* Created by tpolgrabia on 28.08.16. * Created by tpolgrabia on 28.08.16.
@ -223,21 +222,49 @@ public class WikiUtils {
fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() { fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() {
@Override @Override
public void callback(WikiStatus status, WikiGeoResponse response) { public void callback(WikiStatus status, WikiGeoResponse response) {
List<WikiGeoObject> geoData = response.getQuery(); final List<WikiGeoObject> geoItems = response.getQuery();
if (geoData == null) { if (geoItems == null) {
return; return;
} }
List<Long> pageIds = new ArrayList<Long>(); List<Long> pageIds = new ArrayList<Long>();
for (WikiGeoObject wikiGeoObject : geoData) { for (WikiGeoObject wikiGeoObject : geoItems) {
pageIds.add(wikiGeoObject.getPageId()); pageIds.add(wikiGeoObject.getPageId());
} }
final Map<Long, WikiGeoObject> geoItemsMap = new HashMap<>();
for (WikiGeoObject geoItem : geoItems) {
geoItemsMap.put(geoItem.getPageId(), geoItem);
}
WikiResponseCallback tcallback = callback; WikiResponseCallback tcallback = callback;
fetchPageInfos(ctx, fetchPageInfos(ctx,
pageIds, pageIds,
tcallback); new WikiResponseCallback() {
@Override
public void callback(WikiStatus status, WikiResponse response) {
if (status != WikiStatus.SUCCESS) {
return;
}
List<WikiAppObject> results = new ArrayList<WikiAppObject>();
List<WikiPage> 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 {
} }
}); });
} }
} }