Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import com.mapbox.geojson.BoundingBox;

import java.util.Locale;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;

/**
Expand All @@ -39,14 +43,27 @@ protected Call<ResponseBody> initializeCall() {
);
}

private String formatBoundingBox(BoundingBox boundingBox) {
return String.format(Locale.US,
"%f,%f;%f,%f",
boundingBox.west(),
boundingBox.south(),
boundingBox.east(),
boundingBox.north()
);
@Override
protected synchronized OkHttpClient getOkHttpClient() {
if (okHttpClient == null) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
if (isEnableDebug()) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
httpClient.addInterceptor(logging);
}
Interceptor interceptor = interceptor();
if (interceptor != null) {
httpClient.addInterceptor(interceptor);
}
Interceptor networkInterceptor = networkInterceptor();
if (networkInterceptor != null) {
httpClient.addNetworkInterceptor(networkInterceptor);
}

okHttpClient = httpClient.build();
}
return okHttpClient;
}

@Nullable
Expand All @@ -61,6 +78,12 @@ private String formatBoundingBox(BoundingBox boundingBox) {
@NonNull
abstract String accessToken();

@Nullable
abstract Interceptor interceptor();

@Nullable
abstract Interceptor networkInterceptor();

@Override
protected abstract String baseUrl();

Expand Down Expand Up @@ -142,6 +165,22 @@ public abstract static class Builder {
*/
public abstract Builder clientAppName(@NonNull String clientAppName);

/**
* Adds an optional interceptor to set in the OkHttp client.
*
* @param interceptor to set for OkHttp
* @return this builder for chaining options together
*/
public abstract Builder interceptor(Interceptor interceptor);

/**
* Adds an optional network interceptor to set in the OkHttp client.
*
* @param interceptor to set for OkHttp
* @return this builder for chaining options together
*/
public abstract Builder networkInterceptor(Interceptor interceptor);

abstract MapboxRouteTiles autoBuild();

/**
Expand All @@ -162,4 +201,14 @@ public MapboxRouteTiles build() {
return mapboxRouteTiles;
}
}

private String formatBoundingBox(BoundingBox boundingBox) {
return String.format(Locale.US,
"%f,%f;%f,%f",
boundingBox.west(),
boundingBox.south(),
boundingBox.east(),
boundingBox.north()
);
}
}