parent
3fbd6824e2
commit
b874f77551
|
@ -32,4 +32,6 @@ dependencies {
|
||||||
|
|
||||||
compile 'com.googlecode.android-query:android-query:0.25.9'
|
compile 'com.googlecode.android-query:android-query:0.25.9'
|
||||||
compile project(path: ':urbanexplorerutils')
|
compile project(path: ':urbanexplorerutils')
|
||||||
|
compile 'com.squareup.retrofit2:retrofit:2.1.0'
|
||||||
|
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,3 +15,16 @@
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
# public *;
|
# public *;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# Proguard rules for retrofit
|
||||||
|
|
||||||
|
# Platform calls Class.forName on types which do not exist on Android to determine platform.
|
||||||
|
-dontnote retrofit2.Platform
|
||||||
|
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
|
||||||
|
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
|
||||||
|
# Platform used when running on Java 8 VMs. Will not be used at runtime.
|
||||||
|
-dontwarn retrofit2.Platform$Java8
|
||||||
|
# Retain generic type information for use by reflection by converters and adapters.
|
||||||
|
-keepattributes Signature
|
||||||
|
# Retain declared checked exceptions for use by a Proxy instance.
|
||||||
|
-keepattributes Exceptions
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package pl.tpolgrabia.googleutils;
|
||||||
|
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlacePhotoRefResult;
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlaceResult;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.http.GET;
|
||||||
|
import retrofit2.http.Path;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 02.10.16.
|
||||||
|
*/
|
||||||
|
public interface GooglePlacesService {
|
||||||
|
@GET("photo?maxwidth={maxWidth}" +
|
||||||
|
"&photoreference={photoRef}" +
|
||||||
|
"&key={apiKey}")
|
||||||
|
Call<List<GooglePlacePhotoRefResult>> fetchPhotosByRef(
|
||||||
|
@Path("maxWidth") Long maxWidth,
|
||||||
|
@Path("photoRef") String photoRef,
|
||||||
|
@Path("apiKey") String apiKey);
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package pl.tpolgrabia.googleutils.callback;
|
||||||
|
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlacePhotoRefResult;
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlaceResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 02.10.16.
|
||||||
|
*/
|
||||||
|
public interface GooglePlacesPhotosCallback {
|
||||||
|
void onResponse(int code, String message, List<GooglePlacePhotoRefResult> body);
|
||||||
|
void onFailure(Throwable t);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package pl.tpolgrabia.googleutils.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 02.10.16.
|
||||||
|
*/
|
||||||
|
public class GooglePlacesConstants {
|
||||||
|
public static final String GOOGLE_PLACES_BASEURL = "https://maps.googleapis.com/maps/api/place";
|
||||||
|
public static final Long PHOTO_MAX_WIDTH = 512L;
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package pl.tpolgrabia.googleutils.dto;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 02.10.16.
|
||||||
|
*/
|
||||||
|
public class GooglePlacePhotoRefResult {
|
||||||
|
@SerializedName("htmlAttributions")
|
||||||
|
private List<String> htmlAttributions;
|
||||||
|
private Long width;
|
||||||
|
private Long height;
|
||||||
|
@SerializedName("photoReference")
|
||||||
|
private String photoReference;
|
||||||
|
|
||||||
|
public List<String> getHtmlAttributions() {
|
||||||
|
return htmlAttributions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHtmlAttributions(List<String> htmlAttributions) {
|
||||||
|
this.htmlAttributions = htmlAttributions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(Long width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(Long height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhotoReference() {
|
||||||
|
return photoReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhotoReference(String photoReference) {
|
||||||
|
this.photoReference = photoReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GooglePlacePhotoRefResult{" +
|
||||||
|
"htmlAttributions=" + htmlAttributions +
|
||||||
|
", width=" + width +
|
||||||
|
", height=" + height +
|
||||||
|
", photoReference='" + photoReference + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,15 +4,26 @@ import android.content.Context;
|
||||||
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 com.google.gson.JsonObject;
|
import org.apache.http.HttpStatus;
|
||||||
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.googleutils.GooglePlacesService;
|
||||||
|
import pl.tpolgrabia.googleutils.callback.GooglePlacesPhotosCallback;
|
||||||
import pl.tpolgrabia.googleutils.callback.PlacesCallback;
|
import pl.tpolgrabia.googleutils.callback.PlacesCallback;
|
||||||
|
import pl.tpolgrabia.googleutils.constants.GooglePlacesConstants;
|
||||||
import pl.tpolgrabia.googleutils.converter.GooglePlaceConverter;
|
import pl.tpolgrabia.googleutils.converter.GooglePlaceConverter;
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlacePhoto;
|
||||||
|
import pl.tpolgrabia.googleutils.dto.GooglePlacePhotoRefResult;
|
||||||
import pl.tpolgrabia.googleutils.dto.GooglePlaceResult;
|
import pl.tpolgrabia.googleutils.dto.GooglePlaceResult;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
import retrofit2.Retrofit;
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by tpolgrabia on 27.09.16.
|
* Created by tpolgrabia on 27.09.16.
|
||||||
|
@ -97,4 +108,44 @@ public class PlacesUtils {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GooglePlacePhotoRefResult> fetchPhotosByRefSync(String photosRef) throws IOException {
|
||||||
|
Response<List<GooglePlacePhotoRefResult>> results = fetchPhotosByRefInvocation(photosRef).execute();
|
||||||
|
return results.code() == HttpStatus.SC_OK ? results.body() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fetchPhotosByRefAsync(String photosRef, final GooglePlacesPhotosCallback clbk) {
|
||||||
|
fetchPhotosByRefInvocation(photosRef).enqueue(new Callback<List<GooglePlacePhotoRefResult>>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<List<GooglePlacePhotoRefResult>> call, Response<List<GooglePlacePhotoRefResult>> response) {
|
||||||
|
clbk.onResponse(response.code(), response.message(), response.body());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<List<GooglePlacePhotoRefResult>> call, Throwable t) {
|
||||||
|
clbk.onFailure(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Call<List<GooglePlacePhotoRefResult>> fetchPhotosByRefInvocation(String photosRef) {
|
||||||
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
|
.baseUrl(GooglePlacesConstants.GOOGLE_PLACES_BASEURL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build();
|
||||||
|
GooglePlacesService service = retrofit.create(GooglePlacesService.class);
|
||||||
|
return service.fetchPhotosByRef(
|
||||||
|
GooglePlacesConstants.PHOTO_MAX_WIDTH,
|
||||||
|
photosRef,
|
||||||
|
apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<GooglePlacePhotoRefResult>> fetchPhotosSync(Set<String> photoRefs) throws IOException {
|
||||||
|
HashMap<String, List<GooglePlacePhotoRefResult>> result = new HashMap<String, List<GooglePlacePhotoRefResult>>();
|
||||||
|
for (String photoRef : photoRefs) {
|
||||||
|
result.put(photoRef, fetchPhotosByRefSync(photoRef));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue