mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
BraveNewPipe: convert PicassoHelper using the DownloaderImpl#getNewBuilder() to share ConnectionPool etc.
This commit is contained in:
parent
2e330311c4
commit
aac9f2e59c
1 changed files with 19 additions and 4 deletions
|
@ -21,6 +21,7 @@ import com.squareup.picasso.Picasso;
|
|||
import com.squareup.picasso.RequestCreator;
|
||||
import com.squareup.picasso.Transformation;
|
||||
|
||||
import org.schabi.newpipe.DownloaderImpl;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
|
||||
|
@ -49,12 +50,26 @@ public final class PicassoHelper {
|
|||
|
||||
public static void init(final Context context) {
|
||||
picassoCache = new LruCache(10 * 1024 * 1024);
|
||||
picassoDownloaderClient = new OkHttpClient.Builder()
|
||||
.cache(new okhttp3.Cache(new File(context.getExternalCacheDir(), "picasso"),
|
||||
|
||||
final OkHttpClient.Builder builder = DownloaderImpl.getInstance().getNewBuilder();
|
||||
builder.cache(new okhttp3.Cache(new File(context.getExternalCacheDir(), "picasso"),
|
||||
50L * 1024L * 1024L))
|
||||
// this should already be the default timeout in OkHttp3, but just to be sure...
|
||||
.callTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
.callTimeout(15, TimeUnit.SECONDS);
|
||||
|
||||
initInternal(context, builder);
|
||||
}
|
||||
|
||||
public static void reInit(final Context context) {
|
||||
|
||||
final OkHttpClient.Builder builder = picassoDownloaderClient.newBuilder();
|
||||
initInternal(context, builder);
|
||||
}
|
||||
|
||||
private static void initInternal(
|
||||
final Context context,
|
||||
final OkHttpClient.Builder builder) {
|
||||
picassoDownloaderClient = builder.build();
|
||||
|
||||
picassoInstance = new Picasso.Builder(context)
|
||||
.memoryCache(picassoCache) // memory cache
|
||||
|
|
Loading…
Add table
Reference in a new issue