adding image id code
This commit is contained in:
parent
8ea9ba2925
commit
2bde2da819
1 changed files with 50 additions and 25 deletions
|
@ -21,6 +21,7 @@ import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.plus.BuildConfig;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
|
@ -39,13 +40,7 @@ import org.json.JSONObject;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class ImageCard extends AbstractCard {
|
public abstract class ImageCard extends AbstractCard {
|
||||||
|
|
||||||
|
@ -408,6 +403,28 @@ public abstract class ImageCard extends AbstractCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String[] getIdFromResponse(String response) {
|
||||||
|
try {
|
||||||
|
JSONArray obj = new JSONObject(response).getJSONArray("objects");
|
||||||
|
JSONArray images = (JSONArray) ((JSONObject) obj.get(0)).get("id");
|
||||||
|
return toStringArray(images);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] toStringArray(JSONArray array) {
|
||||||
|
if (array == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String[] arr = new String[array.length()];
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
arr[i] = array.optString(i);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
public static class GetImageCardsTask extends AsyncTask<Void, Void, List<ImageCard>> {
|
public static class GetImageCardsTask extends AsyncTask<Void, Void, List<ImageCard>> {
|
||||||
|
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
|
@ -441,7 +458,15 @@ public abstract class ImageCard extends AbstractCard {
|
||||||
if (o instanceof Amenity) {
|
if (o instanceof Amenity) {
|
||||||
Amenity am = (Amenity) o;
|
Amenity am = (Amenity) o;
|
||||||
long amenityId = am.getId() >> 1;
|
long amenityId = am.getId() >> 1;
|
||||||
getPicturesForPlace(result, amenityId);
|
String url = BuildConfig.OPR_BASE_URL + "api/objects-by-index?type=opr.place&index=osmid&key=" + amenityId;
|
||||||
|
String response = AndroidNetworkUtils.sendRequest(app, url, Collections.<String, String>emptyMap(),
|
||||||
|
"Requesting location images...", false, false);
|
||||||
|
if (response != null) {
|
||||||
|
getPicturesForPlace(result, response);
|
||||||
|
String[] id = getIdFromResponse(response);
|
||||||
|
//TODO perform something with image
|
||||||
|
//listener.onOPRPlaceIdAcquired(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Map<String, String> pms = new LinkedHashMap<>();
|
final Map<String, String> pms = new LinkedHashMap<>();
|
||||||
|
@ -503,15 +528,14 @@ public abstract class ImageCard extends AbstractCard {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getPicturesForPlace(List<ImageCard> result, long l) {
|
private void getPicturesForPlace(List<ImageCard> result, String response) {
|
||||||
String url = "https://test.openplacereviews.org/api/objects-by-index?type=opr.place&index=osmid&limit=1&key=" + l;
|
|
||||||
String response = AndroidNetworkUtils.sendRequest(app, url, Collections.<String, String>emptyMap(),
|
|
||||||
"Requesting location images...", false, false);
|
|
||||||
try {
|
try {
|
||||||
if (!Algorithms.isEmpty(response)) {
|
if (!Algorithms.isEmpty(response)) {
|
||||||
//TODO extract place id
|
|
||||||
JSONArray obj = new JSONObject(response).getJSONArray("objects");
|
JSONArray obj = new JSONObject(response).getJSONArray("objects");
|
||||||
JSONArray images = ((JSONObject) ((JSONObject) obj.get(0)).get("images")).getJSONArray("outdoor");
|
JSONObject imagesWrapper = ((JSONObject) ((JSONObject) obj.get(0)).get("images"));
|
||||||
|
Iterator<String> it = imagesWrapper.keys();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
JSONArray images = imagesWrapper.getJSONArray(it.next());
|
||||||
if (images.length() > 0) {
|
if (images.length() > 0) {
|
||||||
for (int i = 0; i < images.length(); i++) {
|
for (int i = 0; i < images.length(); i++) {
|
||||||
try {
|
try {
|
||||||
|
@ -528,6 +552,7 @@ public abstract class ImageCard extends AbstractCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error(e);
|
LOG.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue