Some preparation work to replace old android query for panoramio.

master
Tomasz Półgrabia 2016-11-19 23:33:45 +01:00
parent e2f710528e
commit 0258ac81b4
9 changed files with 231 additions and 1 deletions

View File

@ -0,0 +1,73 @@
package pl.tpolgrabia.urbanexplorer.dto;
/**
* Created by tpolgrabia on 19.11.16.
*/
public class PanoramioRequest {
private Long offset;
private Long count;
private Double latitude;
private Double longitude;
private Double radiusX;
private Double radiusY;
public Long getOffset() {
return offset;
}
public void setOffset(Long offset) {
this.offset = offset;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public Double getRadiusX() {
return radiusX;
}
public void setRadiusX(Double radiusX) {
this.radiusX = radiusX;
}
public Double getRadiusY() {
return radiusY;
}
public void setRadiusY(Double radiusY) {
this.radiusY = radiusY;
}
@Override
public String toString() {
return "PanoramioRequest{" +
"offset=" + offset +
", count=" + count +
", latitude=" + latitude +
", longitude=" + longitude +
", radiusX=" + radiusX +
", radiusY=" + radiusY +
'}';
}
}

View File

@ -0,0 +1,61 @@
package pl.tpolgrabia.urbanexplorer.worker;
import android.os.AsyncTask;
import okhttp3.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.panoramiobindings.dto.PanoramioResponse;
import pl.tpolgrabia.panoramiobindings.utils.PanoramioUtils;
import pl.tpolgrabia.urbanexplorer.dto.PanoramioRequest;
import retrofit2.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by tpolgrabia on 19.11.16.
*/
public class PanoramioWorker extends AsyncTask<PanoramioRequest, Integer, List<PanoramioResponse>> {
private static final Logger lg = LoggerFactory.getLogger(PanoramioWorker.class);
@Override
protected List<PanoramioResponse> doInBackground(PanoramioRequest... params) {
List<PanoramioResponse> res = new ArrayList<>();
for (PanoramioRequest param : params) {
try {
Response<PanoramioResponse> single = PanoramioUtils.fetchPanoramioImagesSync(
param.getLatitude(),
param.getLongitude(),
param.getRadiusX(),
param.getRadiusY(),
param.getOffset(),
param.getCount());
if (single.code() != 200) {
final ResponseBody errorBody = single.errorBody();
lg.error("Fetching paranomio images failed with code: {}, message: {}, error: {}",
single.code(),
single.message(),
errorBody != null ? errorBody.toString() : "(null)");
continue;
}
res.add(single.body());
} catch (IOException e) {
lg.error("I/O error", e);
}
}
return res;
}
@Override
protected void onPostExecute(List<PanoramioResponse> panoramioResponses) {
super.onPostExecute(panoramioResponses);
lg.warn("NOT IMPLEMENTED");
// TODO implement this
}
}

View File

@ -36,4 +36,7 @@ dependencies {
exclude group: 'com.google.android', module: 'android' exclude group: 'com.google.android', module: 'android'
} }
compile project(':urbanexplorerutils') compile project(':urbanexplorerutils')
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
} }

View File

@ -0,0 +1,8 @@
package pl.tpolgrabia.panoramiobindings;
/**
* Created by tpolgrabia on 19.11.16.
*/
public class PanoramioConstants {
public static final String PANORAMIO_WS_URL = "http://www.panoramio.com/map/get_panoramas.php";
}

View File

@ -1,5 +1,7 @@
package pl.tpolgrabia.panoramiobindings.dto; package pl.tpolgrabia.panoramiobindings.dto;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -7,17 +9,29 @@ import java.io.Serializable;
*/ */
public class PanoramioImageInfo implements Serializable{ public class PanoramioImageInfo implements Serializable{
private static final long serialVersionUID = -3749926831546160047L; private static final long serialVersionUID = -3749926831546160047L;
@SerializedName("height")
private Double height; private Double height;
@SerializedName("owner_name")
private String ownerName; private String ownerName;
@SerializedName("owner_id")
private Long ownerId; private Long ownerId;
@SerializedName("photo_file_url")
private String photoFileUrl; private String photoFileUrl;
@SerializedName("photo_title")
private String photoTitle; private String photoTitle;
@SerializedName("upload_date")
private String uploadDate; private String uploadDate;
@SerializedName("width")
private Double width; private Double width;
@SerializedName("latitude")
private Double latitude; private Double latitude;
@SerializedName("longitude")
private Double longitude; private Double longitude;
@SerializedName("owner_url")
private String ownerUrl; private String ownerUrl;
@SerializedName("photo_id")
private Long photoId; private Long photoId;
@SerializedName("photo_url")
private String photoUrl; private String photoUrl;
public Double getHeight() { public Double getHeight() {

View File

@ -1,5 +1,7 @@
package pl.tpolgrabia.panoramiobindings.dto; package pl.tpolgrabia.panoramiobindings.dto;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -7,8 +9,11 @@ import java.io.Serializable;
*/ */
public class PanoramioMapLocation implements Serializable{ public class PanoramioMapLocation implements Serializable{
private static final long serialVersionUID = -3048527017887972550L; private static final long serialVersionUID = -3048527017887972550L;
@SerializedName("lat")
private Double latitude; private Double latitude;
@SerializedName("lng")
private Double longitude; private Double longitude;
@SerializedName("panoramio_zoom")
private Long zoom; private Long zoom;
public Double getLatitude() { public Double getLatitude() {

View File

@ -1,5 +1,7 @@
package pl.tpolgrabia.panoramiobindings.dto; package pl.tpolgrabia.panoramiobindings.dto;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -8,9 +10,13 @@ import java.util.List;
*/ */
public class PanoramioResponse implements Serializable{ public class PanoramioResponse implements Serializable{
private static final long serialVersionUID = 8840731825651350777L; private static final long serialVersionUID = 8840731825651350777L;
@SerializedName("photos")
private List<PanoramioImageInfo> photos; private List<PanoramioImageInfo> photos;
@SerializedName("count")
private Long count; private Long count;
@SerializedName("moreAvailable")
private Boolean moreAvailable; private Boolean moreAvailable;
@SerializedName("map_location")
private PanoramioMapLocation mapLocation; private PanoramioMapLocation mapLocation;
public List<PanoramioImageInfo> getPhotos() { public List<PanoramioImageInfo> getPhotos() {

View File

@ -0,0 +1,23 @@
package pl.tpolgrabia.panoramiobindings.utils;
import pl.tpolgrabia.panoramiobindings.dto.PanoramioResponse;
import retrofit2.Call;
import retrofit2.http.Query;
/**
* Created by tpolgrabia on 19.11.16.
*/
public interface PanoramioService {
Call<PanoramioResponse> fetch(
@Query("set") String set,
@Query("from") Long from,
@Query("to") Long to,
@Query("minx") Double minx,
@Query("miny") Double miny,
@Query("maxx") Double maxx,
@Query("maxy") Double maxy,
@Query("size") String size,
@Query("order") String order,
@Query("mapfilter") Boolean mapFilter
);
}

View File

@ -8,11 +8,13 @@ import android.view.Display;
import com.androidquery.AQuery; import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback; import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus; import com.androidquery.callback.AjaxStatus;
import okhttp3.OkHttpClient;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pl.tpolgrabia.panoramiobindings.PanoramioConstants;
import pl.tpolgrabia.panoramiobindings.callback.PanoramioResponseCallback; import pl.tpolgrabia.panoramiobindings.callback.PanoramioResponseCallback;
import pl.tpolgrabia.panoramiobindings.callback.PanoramioResponseStatus; import pl.tpolgrabia.panoramiobindings.callback.PanoramioResponseStatus;
import pl.tpolgrabia.panoramiobindings.dto.PanoramioImageInfo; import pl.tpolgrabia.panoramiobindings.dto.PanoramioImageInfo;
@ -20,7 +22,12 @@ import pl.tpolgrabia.panoramiobindings.dto.PanoramioMapLocation;
import pl.tpolgrabia.panoramiobindings.dto.PanoramioResponse; import pl.tpolgrabia.panoramiobindings.dto.PanoramioResponse;
import pl.tpolgrabia.panoramiobindings.exceptions.PanoramioResponseNotExpected; import pl.tpolgrabia.panoramiobindings.exceptions.PanoramioResponseNotExpected;
import pl.tpolgrabia.urbanexplorerutils.utils.NetUtils; import pl.tpolgrabia.urbanexplorerutils.utils.NetUtils;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,11 +38,41 @@ import java.util.List;
public class PanoramioUtils { public class PanoramioUtils {
private static final Logger lg = LoggerFactory.getLogger(PanoramioUtils.class); private static final Logger lg = LoggerFactory.getLogger(PanoramioUtils.class);
private static final String CLASS_TAG = PanoramioUtils.class.getSimpleName();
private static final String LOCATIONS_LIST_IMAGE_SIZE = "medium"; private static final String LOCATIONS_LIST_IMAGE_SIZE = "medium";
private static final String LOCATIONS_ORDER = "popularity"; private static final String LOCATIONS_ORDER = "popularity";
public static Response<PanoramioResponse> fetchPanoramioImagesSync(
Double lat,
Double lon,
Double radiusX,
Double radiusY,
Long offset,
Long count
) throws IOException {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// TODO httpClient.addInterceptor(new RetrofitDebugInterceptor());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(PanoramioConstants.PANORAMIO_WS_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
PanoramioService panoramioService = retrofit.create(PanoramioService.class);
return panoramioService.fetch(
"public",
offset,
offset + count,
lon - radiusX,
lat - radiusY,
lon + radiusX,
lat + radiusY,
LOCATIONS_LIST_IMAGE_SIZE,
LOCATIONS_ORDER,
true).execute();
}
public static void fetchPanoramioImages( public static void fetchPanoramioImages(
Context ctx, Context ctx,
Double lat, Double lat,