[android] - add resource usage to HttpRequest, add offline query parameter flag to http request (#14837)
This commit is contained in:
@@ -15,17 +15,18 @@ public interface HttpRequest {
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
* @param httpRequest callback to be invoked when we receive a response
|
||||
* @param nativePtr the pointer associated to the request
|
||||
* @param resourceUrl the resource url to download
|
||||
* @param etag http header, identifier for a specific version of a resource
|
||||
* @param modified http header, used to determine if a resource hasn't been modified since
|
||||
* @param httpRequest callback to be invoked when we receive a response
|
||||
* @param nativePtr the pointer associated to the request
|
||||
* @param resourceUrl the resource url to download
|
||||
* @param etag http header, identifier for a specific version of a resource
|
||||
* @param modified http header, used to determine if a resource hasn't been modified since
|
||||
* @param offlineUsage flag to indicate a resource will be used for offline, appends offline=true as a query parameter
|
||||
*/
|
||||
void executeRequest(HttpResponder httpRequest, long nativePtr, String resourceUrl,
|
||||
String etag, String modified);
|
||||
String etag, String modified, boolean offlineUsage);
|
||||
|
||||
/**
|
||||
* Cancels the request.
|
||||
*/
|
||||
*/
|
||||
void cancelRequest();
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@ public class HttpRequestUrl {
|
||||
* @param host the host used as endpoint
|
||||
* @param resourceUrl the resource to download
|
||||
* @param querySize the query size of the resource request
|
||||
* @param offline the type of resource, either offline or online
|
||||
* @return the adapted resource url
|
||||
*/
|
||||
public static String buildResourceUrl(@NonNull String host, String resourceUrl, int querySize) {
|
||||
public static String buildResourceUrl(@NonNull String host, String resourceUrl, int querySize, boolean offline) {
|
||||
if (isValidMapboxEndpoint(host)) {
|
||||
if (querySize == 0) {
|
||||
resourceUrl = resourceUrl + "?";
|
||||
@@ -25,6 +26,10 @@ public class HttpRequestUrl {
|
||||
resourceUrl = resourceUrl + "&";
|
||||
}
|
||||
resourceUrl = resourceUrl + "sku=" + Mapbox.getSkuToken();
|
||||
|
||||
if (offline) {
|
||||
resourceUrl = resourceUrl + "&offline=true";
|
||||
}
|
||||
}
|
||||
return resourceUrl;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class NativeHttpRequest implements HttpResponder {
|
||||
private long nativePtr;
|
||||
|
||||
@Keep
|
||||
private NativeHttpRequest(long nativePtr, String resourceUrl, String etag, String modified) {
|
||||
private NativeHttpRequest(long nativePtr, String resourceUrl, String etag, String modified, boolean offlineUsage) {
|
||||
this.nativePtr = nativePtr;
|
||||
|
||||
if (resourceUrl.startsWith("local://")) {
|
||||
@@ -26,7 +26,7 @@ public class NativeHttpRequest implements HttpResponder {
|
||||
executeLocalRequest(resourceUrl);
|
||||
return;
|
||||
}
|
||||
httpRequest.executeRequest(this, nativePtr, resourceUrl, etag, modified);
|
||||
httpRequest.executeRequest(this, nativePtr, resourceUrl, etag, modified, offlineUsage);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
||||
@@ -53,7 +53,7 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
|
||||
@Override
|
||||
public void executeRequest(HttpResponder httpRequest, long nativePtr, @NonNull String resourceUrl,
|
||||
@NonNull String etag, @NonNull String modified) {
|
||||
@NonNull String etag, @NonNull String modified, boolean offlineUsage) {
|
||||
OkHttpCallback callback = new OkHttpCallback(httpRequest);
|
||||
try {
|
||||
HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
|
||||
@@ -63,7 +63,7 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
}
|
||||
|
||||
final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
|
||||
resourceUrl = HttpRequestUrl.buildResourceUrl(host, resourceUrl, httpUrl.querySize());
|
||||
resourceUrl = HttpRequestUrl.buildResourceUrl(host, resourceUrl, httpUrl.querySize(), offlineUsage);
|
||||
|
||||
final Request.Builder builder = new Request.Builder()
|
||||
.url(resourceUrl)
|
||||
|
||||
Reference in New Issue
Block a user