Compare commits

...

5 Commits

Author SHA1 Message Date
Dimitry Ivanov
30294782cb Update travis configuration 2019-06-19 10:37:54 +03:00
Dimitry Ivanov
e6b283e243 Better fix for latex plugin 2019-06-19 10:37:09 +03:00
Dimitry Ivanov
c20f1520ab Fix recursive factory call in OkHttpImagesPlugin 2019-06-19 00:40:09 +03:00
Zac Sweers
b30a1e10a8 Switch OkHttpImagesPlugin to be Call.Factory-based
This is a binary-compatible change that changes the underlying semantics to use a Call.Factory rather than OkHttpClient directly. This allows for a few benefits:

- Not tightly coupled to OkHttpClient
- Allows for lazy/delegating/deferred initialization
- Matches other OkHttpClient-dependent libraries' APIs, namely Retrofit and Apollo GraphQL
2019-06-19 00:39:22 +03:00
Dimitry Ivanov
08507c8a92 Fix latex plugin 2019-06-19 00:39:17 +03:00
5 changed files with 24 additions and 21 deletions

View File

@ -1,5 +1,6 @@
# https://docs.travis-ci.com/user/languages/android/ # https://docs.travis-ci.com/user/languages/android/
language: android language: android
dist: trusty
jdk: openjdk8 jdk: openjdk8
sudo: false sudo: false

View File

@ -6,7 +6,7 @@ org.gradle.configureondemand=true
android.enableBuildCache=true android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache android.buildCacheDir=build/pre-dex-cache
VERSION_NAME=3.0.1 VERSION_NAME=3.0.2
GROUP=ru.noties.markwon GROUP=ru.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android POM_DESCRIPTION=Markwon markdown for Android

View File

@ -80,12 +80,8 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
} }
} }
@NonNull
public static String makeDestination(@NonNull String latex) {
return SCHEME + "://" + latex;
}
private static final String SCHEME = "jlatexmath"; private static final String SCHEME = "jlatexmath";
private static final String SCHEME_START = SCHEME + "://";
private static final String CONTENT_TYPE = "text/jlatexmath"; private static final String CONTENT_TYPE = "text/jlatexmath";
private final Config config; private final Config config;
@ -112,9 +108,11 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
final RenderProps renderProps = visitor.renderProps(); final RenderProps renderProps = visitor.renderProps();
ImageProps.DESTINATION.set(renderProps, makeDestination(latex)); ImageProps.DESTINATION.set(renderProps, SCHEME_START + latex);
ImageProps.REPLACEMENT_TEXT_IS_LINK.set(renderProps, false); ImageProps.REPLACEMENT_TEXT_IS_LINK.set(renderProps, false);
ImageProps.IMAGE_SIZE.set(renderProps, new ImageSize(new ImageSize.Dimension(100, "%"), null)); ImageProps.IMAGE_SIZE.set(
renderProps,
new ImageSize(new ImageSize.Dimension(100, "%"), null));
visitor.setSpansForNode(Image.class, length); visitor.setSpansForNode(Image.class, length);
} }
@ -132,7 +130,7 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
ImageItem item = null; ImageItem item = null;
try { try {
final byte[] bytes = raw.substring(SCHEME.length()).getBytes("UTF-8"); final byte[] bytes = raw.substring(SCHEME_START.length()).getBytes("UTF-8");
item = new ImageItem( item = new ImageItem(
CONTENT_TYPE, CONTENT_TYPE,
new ByteArrayInputStream(bytes)); new ByteArrayInputStream(bytes));

View File

@ -4,6 +4,7 @@ import android.support.annotation.NonNull;
import java.util.Arrays; import java.util.Arrays;
import okhttp3.Call;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import ru.noties.markwon.AbstractMarkwonPlugin; import ru.noties.markwon.AbstractMarkwonPlugin;
import ru.noties.markwon.image.AsyncDrawableLoader; import ru.noties.markwon.image.AsyncDrawableLoader;
@ -28,20 +29,25 @@ public class OkHttpImagesPlugin extends AbstractMarkwonPlugin {
@NonNull @NonNull
public static OkHttpImagesPlugin create(@NonNull OkHttpClient okHttpClient) { public static OkHttpImagesPlugin create(@NonNull OkHttpClient okHttpClient) {
return new OkHttpImagesPlugin(okHttpClient); return create((Call.Factory) okHttpClient);
} }
private final OkHttpClient client; @NonNull
public static OkHttpImagesPlugin create(@NonNull Call.Factory callFactory) {
return new OkHttpImagesPlugin(callFactory);
}
OkHttpImagesPlugin(@NonNull OkHttpClient client) { private final Call.Factory callFactory;
this.client = client;
OkHttpImagesPlugin(@NonNull Call.Factory callFactory) {
this.callFactory = callFactory;
} }
@Override @Override
public void configureImages(@NonNull AsyncDrawableLoader.Builder builder) { public void configureImages(@NonNull AsyncDrawableLoader.Builder builder) {
builder.addSchemeHandler( builder.addSchemeHandler(
Arrays.asList(NetworkSchemeHandler.SCHEME_HTTP, NetworkSchemeHandler.SCHEME_HTTPS), Arrays.asList(NetworkSchemeHandler.SCHEME_HTTP, NetworkSchemeHandler.SCHEME_HTTPS),
new OkHttpSchemeHandler(client) new OkHttpSchemeHandler(callFactory)
); );
} }

View File

@ -3,11 +3,9 @@ package ru.noties.markwon.image.okhttp;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
@ -18,10 +16,10 @@ class OkHttpSchemeHandler extends SchemeHandler {
private static final String HEADER_CONTENT_TYPE = "Content-Type"; private static final String HEADER_CONTENT_TYPE = "Content-Type";
private final OkHttpClient client; private final Call.Factory callFactory;
OkHttpSchemeHandler(@NonNull OkHttpClient client) { OkHttpSchemeHandler(@NonNull Call.Factory callFactory) {
this.client = client; this.callFactory = callFactory;
} }
@Nullable @Nullable
@ -36,7 +34,7 @@ class OkHttpSchemeHandler extends SchemeHandler {
Response response = null; Response response = null;
try { try {
response = client.newCall(request).execute(); response = callFactory.newCall(request).execute();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }