[android] #3461 - upgrade to okhttp3 for faster tile loading! 🚀

This commit is contained in:
Tobrun
2016-01-14 13:49:06 +01:00
parent 1f31de288f
commit 35855889df
2 changed files with 26 additions and 25 deletions

View File

@@ -4,12 +4,6 @@ import android.text.TextUtils;
import android.util.Log;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;
import java.io.InterruptedIOException;
@@ -19,6 +13,13 @@ import java.net.UnknownHostException;
import javax.net.ssl.SSLException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
class HTTPContext {
private static final int CONNECTION_ERROR = 0;
@@ -80,23 +81,7 @@ class HTTPContext {
}
@Override
public void onFailure(Request request, IOException e) {
Log.w(LOG_TAG, String.format("[HTTP] Request could not be executed: %s", e.getMessage()));
int type = PERMANENT_ERROR;
if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) {
type = CONNECTION_ERROR;
} else if ((e instanceof InterruptedIOException)) {
type = TEMPORARY_ERROR;
} else if (mCall.isCanceled()) {
type = CANCELED_ERROR;
}
nativeOnFailure(mNativePtr, type, e.getMessage());
}
@Override
public void onResponse(Response response) throws IOException {
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
Log.d(LOG_TAG, String.format("[HTTP] Request was successful (code = %d).", response.code()));
} else {
@@ -117,9 +102,25 @@ class HTTPContext {
} finally {
response.body().close();
}
nativeOnResponse(mNativePtr, response.code(), response.message(), response.header("ETag"), response.header("Last-Modified"), response.header("Cache-Control"), response.header("Expires"), body);
}
@Override
public void onFailure(Call call, IOException e) {
Log.w(LOG_TAG, String.format("[HTTP] Request could not be executed: %s", e.getMessage()));
int type = PERMANENT_ERROR;
if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) {
type = CONNECTION_ERROR;
} else if ((e instanceof InterruptedIOException)) {
type = TEMPORARY_ERROR;
} else if (mCall.isCanceled()) {
type = CANCELED_ERROR;
}
nativeOnFailure(mNativePtr, type, e.getMessage());
}
}
/*