Another fix...

This commit is contained in:
Martin Fietz 2015-04-12 01:40:09 +02:00
parent 9bd6bcf9d3
commit e5c03079b6
3 changed files with 33 additions and 25 deletions

View File

@ -40,9 +40,9 @@ dependencies {
compile 'commons-io:commons-io:2.4'
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
compile 'com.squareup.okio:okio:1.2.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'de.greenrobot:eventbus:2.4.0'

View File

@ -66,7 +66,7 @@ public class PicassoProvider {
return;
}
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new BasicAuthenticationInterceptor(appContext));
client.interceptors().add(new BasicAuthenticationInterceptor(appContext));
Picasso picasso = new Picasso.Builder(appContext)
.indicatorsEnabled(DEBUG)
.loggingEnabled(DEBUG)
@ -98,29 +98,32 @@ public class PicassoProvider {
public Response intercept(Chain chain) throws IOException {
com.squareup.okhttp.Request request = chain.request();
String url = request.urlString();
// add authentication
String authentication = DBReader.getImageAuthentication(context, url);
if(TextUtils.isEmpty(authentication) == false) {
String[] auth = authentication.split(":");
String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1");
com.squareup.okhttp.Request newRequest = request
if(TextUtils.isEmpty(authentication)) {
Log.d(TAG, "no credentials for '" + url + "'");
return chain.proceed(request);
}
// add authentication
String[] auth = authentication.split(":");
String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1");
com.squareup.okhttp.Request newRequest = request
.newBuilder()
.addHeader("Authorization", credentials)
.build();
Log.d(TAG, "Basic authentication with ISO-8859-1 encoding");
Response response = chain.proceed(newRequest);
if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8");
newRequest = request
.newBuilder()
.addHeader("Authorization", credentials)
.build();
Response response = chain.proceed(newRequest);
if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8");
newRequest = request
.newBuilder()
.addHeader("Authorization", credentials)
.build();
return chain.proceed(newRequest);
} else {
return response;
}
}
else { // no authentication required
return chain.proceed(request);
Log.d(TAG, "Basic authentication with UTF-8 encoding");
return chain.proceed(newRequest);
} else {
return response;
}
}
}
@ -140,7 +143,7 @@ public class PicassoProvider {
}
@Override
public Result load(Request data) throws IOException {
public Result load(Request data, int networkPolicy) throws IOException {
Bitmap bitmap = null;
MediaMetadataRetriever mmr = null;
try {

View File

@ -726,7 +726,12 @@ public class GpodnetService {
Validate.notNull(body);
ByteArrayOutputStream outputStream;
int contentLength = (int) body.contentLength();
int contentLength = 0;
try {
contentLength = (int) body.contentLength();
} catch (IOException ignore) {
// ignore
}
if (contentLength > 0) {
outputStream = new ByteArrayOutputStream(contentLength);
} else {