Ensure explicit dependencies for SVG and GIF
This commit is contained in:
parent
0b0d3c4753
commit
2e35ef53bb
@ -19,7 +19,6 @@ import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.gif.GifAwarePlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.DefaultImageMediaDecoder;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.data.DataUriSchemeHandler;
|
||||
import ru.noties.markwon.image.file.FileSchemeHandler;
|
||||
@ -105,8 +104,7 @@ public class MarkdownRenderer {
|
||||
.addSchemeHandler(OkHttpNetworkSchemeHandler.create())
|
||||
.addSchemeHandler(FileSchemeHandler.createWithAssets(context.getAssets()))
|
||||
.addMediaDecoder(GifMediaDecoder.create(false))
|
||||
.addMediaDecoder(SvgMediaDecoder.create())
|
||||
.defaultMediaDecoder(DefaultImageMediaDecoder.create());
|
||||
.addMediaDecoder(SvgMediaDecoder.create());
|
||||
}
|
||||
}))
|
||||
.usePlugin(SyntaxHighlightPlugin.create(prism4j, prism4jTheme))
|
||||
|
@ -101,7 +101,7 @@ public class TaskListPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
private static int resolve(@NonNull Context context, @AttrRes int attr) {
|
||||
final TypedValue typedValue = new TypedValue();
|
||||
final int attrs[] = new int[]{attr};
|
||||
final int[] attrs = new int[]{attr};
|
||||
final TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, attrs);
|
||||
try {
|
||||
return typedArray.getColor(0, 0);
|
||||
|
@ -3,7 +3,6 @@ package ru.noties.markwon.image;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -31,14 +30,8 @@ class AsyncDrawableLoaderBuilder {
|
||||
}
|
||||
|
||||
void addMediaDecoder(@NonNull MediaDecoder mediaDecoder) {
|
||||
final Collection<String> supportedTypes = mediaDecoder.supportedTypes();
|
||||
if (supportedTypes.isEmpty()) {
|
||||
// todo: we should think about this little _side-effect_... does it worth it?
|
||||
defaultMediaDecoder = mediaDecoder;
|
||||
} else {
|
||||
for (String type : supportedTypes) {
|
||||
mediaDecoders.put(type, mediaDecoder);
|
||||
}
|
||||
for (String type : mediaDecoder.supportedTypes()) {
|
||||
mediaDecoders.put(type, mediaDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,11 @@ public class ImagesPlugin extends AbstractMarkwonPlugin {
|
||||
* Factory method to create an empty {@link ImagesPlugin} instance with no {@link SchemeHandler}s
|
||||
* nor {@link MediaDecoder}s registered. Can be used to further configure via instance methods or
|
||||
* via {@link ru.noties.markwon.MarkwonPlugin#configure(Registry)}
|
||||
*
|
||||
* @see #create(ImagesConfigure)
|
||||
*/
|
||||
@NonNull
|
||||
public static ImagesPlugin createEmpty() {
|
||||
public static ImagesPlugin create() {
|
||||
return new ImagesPlugin();
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,9 @@ public class GifMediaDecoder extends MediaDecoder {
|
||||
|
||||
protected GifMediaDecoder(boolean autoPlayGif) {
|
||||
this.autoPlayGif = autoPlayGif;
|
||||
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
Holder.validate();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -82,4 +85,28 @@ public class GifMediaDecoder extends MediaDecoder {
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
private static class Holder {
|
||||
|
||||
private static final boolean HAS_GIF;
|
||||
|
||||
static {
|
||||
boolean result = true;
|
||||
try {
|
||||
GifDrawable.class.getName();
|
||||
} catch (Throwable t) {
|
||||
result = false;
|
||||
t.printStackTrace();
|
||||
}
|
||||
HAS_GIF = result;
|
||||
}
|
||||
|
||||
static void validate() {
|
||||
if (!HAS_GIF) {
|
||||
throw new IllegalStateException("`pl.droidsonroids.gif:android-gif-drawable:*` " +
|
||||
"dependency is missing, please add to your project explicitly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,11 @@ public class NetworkSchemeHandler extends SchemeHandler {
|
||||
return new NetworkSchemeHandler();
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
NetworkSchemeHandler() {
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
||||
|
@ -36,6 +36,7 @@ public class OkHttpNetworkSchemeHandler extends SchemeHandler {
|
||||
|
||||
private final OkHttpClient client;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
OkHttpNetworkSchemeHandler(@NonNull OkHttpClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ public class SvgMediaDecoder extends MediaDecoder {
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
SvgMediaDecoder(Resources resources) {
|
||||
this.resources = resources;
|
||||
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
Holder.validate();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -79,4 +82,28 @@ public class SvgMediaDecoder extends MediaDecoder {
|
||||
public Collection<String> supportedTypes() {
|
||||
return Collections.singleton(CONTENT_TYPE);
|
||||
}
|
||||
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
private static class Holder {
|
||||
|
||||
private static final boolean HAS_SVG;
|
||||
|
||||
static {
|
||||
boolean result = true;
|
||||
try {
|
||||
SVG.class.getName();
|
||||
} catch (Throwable t) {
|
||||
result = false;
|
||||
t.printStackTrace();
|
||||
}
|
||||
HAS_SVG = result;
|
||||
}
|
||||
|
||||
static void validate() {
|
||||
if (!HAS_SVG) {
|
||||
throw new IllegalStateException("`com.caverock:androidsvg:*` dependency is missing, " +
|
||||
"please add to your project explicitly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user