Another fix...
This commit is contained in:
parent
9bd6bcf9d3
commit
e5c03079b6
|
@ -40,9 +40,9 @@ dependencies {
|
||||||
compile 'commons-io:commons-io:2.4'
|
compile 'commons-io:commons-io:2.4'
|
||||||
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
|
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
|
||||||
compile 'org.jsoup:jsoup:1.7.3'
|
compile 'org.jsoup:jsoup:1.7.3'
|
||||||
compile 'com.squareup.picasso:picasso:2.4.0'
|
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||||
compile 'com.squareup.okhttp:okhttp:2.2.0'
|
compile 'com.squareup.okhttp:okhttp:2.3.0'
|
||||||
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
|
||||||
compile 'com.squareup.okio:okio:1.2.0'
|
compile 'com.squareup.okio:okio:1.2.0'
|
||||||
compile 'com.nineoldandroids:library:2.4.0'
|
compile 'com.nineoldandroids:library:2.4.0'
|
||||||
compile 'de.greenrobot:eventbus:2.4.0'
|
compile 'de.greenrobot:eventbus:2.4.0'
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class PicassoProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OkHttpClient client = new OkHttpClient();
|
OkHttpClient client = new OkHttpClient();
|
||||||
client.networkInterceptors().add(new BasicAuthenticationInterceptor(appContext));
|
client.interceptors().add(new BasicAuthenticationInterceptor(appContext));
|
||||||
Picasso picasso = new Picasso.Builder(appContext)
|
Picasso picasso = new Picasso.Builder(appContext)
|
||||||
.indicatorsEnabled(DEBUG)
|
.indicatorsEnabled(DEBUG)
|
||||||
.loggingEnabled(DEBUG)
|
.loggingEnabled(DEBUG)
|
||||||
|
@ -98,15 +98,21 @@ public class PicassoProvider {
|
||||||
public Response intercept(Chain chain) throws IOException {
|
public Response intercept(Chain chain) throws IOException {
|
||||||
com.squareup.okhttp.Request request = chain.request();
|
com.squareup.okhttp.Request request = chain.request();
|
||||||
String url = request.urlString();
|
String url = request.urlString();
|
||||||
// add authentication
|
|
||||||
String authentication = DBReader.getImageAuthentication(context, url);
|
String authentication = DBReader.getImageAuthentication(context, url);
|
||||||
if(TextUtils.isEmpty(authentication) == false) {
|
|
||||||
|
if(TextUtils.isEmpty(authentication)) {
|
||||||
|
Log.d(TAG, "no credentials for '" + url + "'");
|
||||||
|
return chain.proceed(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add authentication
|
||||||
String[] auth = authentication.split(":");
|
String[] auth = authentication.split(":");
|
||||||
String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1");
|
String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1");
|
||||||
com.squareup.okhttp.Request newRequest = request
|
com.squareup.okhttp.Request newRequest = request
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.addHeader("Authorization", credentials)
|
.addHeader("Authorization", credentials)
|
||||||
.build();
|
.build();
|
||||||
|
Log.d(TAG, "Basic authentication with ISO-8859-1 encoding");
|
||||||
Response response = chain.proceed(newRequest);
|
Response response = chain.proceed(newRequest);
|
||||||
if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
||||||
credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8");
|
credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8");
|
||||||
|
@ -114,15 +120,12 @@ public class PicassoProvider {
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.addHeader("Authorization", credentials)
|
.addHeader("Authorization", credentials)
|
||||||
.build();
|
.build();
|
||||||
|
Log.d(TAG, "Basic authentication with UTF-8 encoding");
|
||||||
return chain.proceed(newRequest);
|
return chain.proceed(newRequest);
|
||||||
} else {
|
} else {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // no authentication required
|
|
||||||
return chain.proceed(request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MediaRequestHandler extends RequestHandler {
|
private static class MediaRequestHandler extends RequestHandler {
|
||||||
|
@ -140,7 +143,7 @@ public class PicassoProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result load(Request data) throws IOException {
|
public Result load(Request data, int networkPolicy) throws IOException {
|
||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
MediaMetadataRetriever mmr = null;
|
MediaMetadataRetriever mmr = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -726,7 +726,12 @@ public class GpodnetService {
|
||||||
Validate.notNull(body);
|
Validate.notNull(body);
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream;
|
ByteArrayOutputStream outputStream;
|
||||||
int contentLength = (int) body.contentLength();
|
int contentLength = 0;
|
||||||
|
try {
|
||||||
|
contentLength = (int) body.contentLength();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
if (contentLength > 0) {
|
if (contentLength > 0) {
|
||||||
outputStream = new ByteArrayOutputStream(contentLength);
|
outputStream = new ByteArrayOutputStream(contentLength);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue