Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OkHttp with UIL #1136

Merged
merged 1 commit into from Feb 23, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private ImageLoaderConfiguration getImageLoaderConfigurations(final int memoryCa
return new ImageLoaderConfiguration.Builder(this)
.memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024))
.diskCacheSize(diskCacheSizeMb * 1024 * 1024)
.imageDownloader(new ImageDownloader(getApplicationContext()))
.build();
}

Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/org/schabi/newpipe/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -98,6 +99,18 @@ public String download(String siteUrl, String language) throws IOException, ReCa
*/
@Override
public String download(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException {
return getBody(siteUrl, customProperties).string();
}

public InputStream stream(String siteUrl) throws IOException {
try {
return getBody(siteUrl, Collections.emptyMap()).byteStream();
} catch (ReCaptchaException e) {
throw new IOException(e.getMessage(), e.getCause());
}
}

private ResponseBody getBody(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException {
final Request.Builder requestBuilder = new Request.Builder()
.method("GET", null).url(siteUrl)
.addHeader("User-Agent", USER_AGENT);
Expand All @@ -123,7 +136,7 @@ public String download(String siteUrl, Map<String, String> customProperties) thr
return null;
}

return body.string();
return body;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/org/schabi/newpipe/ImageDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.schabi.newpipe;

import android.content.Context;

import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import org.schabi.newpipe.extractor.NewPipe;

import java.io.IOException;
import java.io.InputStream;

public class ImageDownloader extends BaseImageDownloader {
public ImageDownloader(Context context) {
super(context);
}

public ImageDownloader(Context context, int connectTimeout, int readTimeout) {
super(context, connectTimeout, readTimeout);
}

protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
Downloader downloader = (Downloader) NewPipe.getDownloader();
return downloader.stream(imageUri);
}
}