Skip to content

Commit

Permalink
Merge pull request #129 from ZacSweers/z/callFactoryOkHttp
Browse files Browse the repository at this point in the history
Switch OkHttpImagesPlugin to be Call.Factory-based
  • Loading branch information
noties authored Jun 4, 2019
2 parents 453880b + a03f323 commit a501751
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.Arrays;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import ru.noties.markwon.AbstractMarkwonPlugin;
import ru.noties.markwon.image.AsyncDrawableLoader;
Expand All @@ -28,20 +29,25 @@ public static OkHttpImagesPlugin create() {

@NonNull
public static OkHttpImagesPlugin create(@NonNull OkHttpClient okHttpClient) {
return new OkHttpImagesPlugin(okHttpClient);
return create(okHttpClient);
}

private final OkHttpClient client;
@NonNull
public static OkHttpImagesPlugin create(@NonNull Call.Factory callFactory) {
return new OkHttpImagesPlugin(callFactory);
}

private final Call.Factory callFactory;

OkHttpImagesPlugin(@NonNull OkHttpClient client) {
this.client = client;
OkHttpImagesPlugin(@NonNull Call.Factory callFactory) {
this.callFactory = callFactory;
}

@Override
public void configureImages(@NonNull AsyncDrawableLoader.Builder builder) {
builder.addSchemeHandler(
Arrays.asList(NetworkSchemeHandler.SCHEME_HTTP, NetworkSchemeHandler.SCHEME_HTTPS),
new OkHttpSchemeHandler(client)
new OkHttpSchemeHandler(callFactory)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

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

import okhttp3.OkHttpClient;
import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
Expand All @@ -18,10 +16,10 @@ class OkHttpSchemeHandler extends SchemeHandler {

private static final String HEADER_CONTENT_TYPE = "Content-Type";

private final OkHttpClient client;
private final Call.Factory callFactory;

OkHttpSchemeHandler(@NonNull OkHttpClient client) {
this.client = client;
OkHttpSchemeHandler(@NonNull Call.Factory callFactory) {
this.callFactory = callFactory;
}

@Nullable
Expand All @@ -36,7 +34,7 @@ public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {

Response response = null;
try {
response = client.newCall(request).execute();
response = callFactory.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit a501751

Please sign in to comment.