Moved image span from factory to image-plugin
This commit is contained in:
		
							parent
							
								
									066b634bee
								
							
						
					
					
						commit
						69f9d0ebb8
					
				| @ -3,14 +3,14 @@ package ru.noties.markwon.gif; | |||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.SpannableFactoryDef; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactoryDef; | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| import ru.noties.markwon.image.ImageSize; | import ru.noties.markwon.image.ImageSize; | ||||||
| import ru.noties.markwon.image.ImageSizeResolver; | import ru.noties.markwon.image.ImageSizeResolver; | ||||||
| import ru.noties.markwon.core.spans.AsyncDrawableSpan; | import ru.noties.markwon.core.spans.AsyncDrawableSpan; | ||||||
| import ru.noties.markwon.core.MarkwonTheme; |  | ||||||
| 
 | 
 | ||||||
| public class GifAwareSpannableFactory extends SpannableFactoryDef { | public class GifAwareSpannableFactory extends MarkwonSpannableFactoryDef { | ||||||
| 
 | 
 | ||||||
|     private final GifPlaceholder gifPlaceholder; |     private final GifPlaceholder gifPlaceholder; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,8 +6,8 @@ import android.widget.TextView; | |||||||
| import org.commonmark.node.Node; | import org.commonmark.node.Node; | ||||||
| import org.commonmark.parser.Parser; | import org.commonmark.parser.Parser; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| 
 | 
 | ||||||
| public abstract class AbstractMarkwonPlugin implements MarkwonPlugin { | public abstract class AbstractMarkwonPlugin implements MarkwonPlugin { | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -10,8 +10,8 @@ import java.util.ArrayList; | |||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| 
 | 
 | ||||||
| class MarkwonBuilderImpl implements Markwon.Builder { | class MarkwonBuilderImpl implements Markwon.Builder { | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,6 +4,8 @@ import android.content.Context; | |||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactoryDef; | ||||||
| import ru.noties.markwon.core.spans.LinkSpan; | import ru.noties.markwon.core.spans.LinkSpan; | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| import ru.noties.markwon.image.ImageSizeResolver; | import ru.noties.markwon.image.ImageSizeResolver; | ||||||
| @ -37,7 +39,7 @@ public class MarkwonConfiguration { | |||||||
|     private final LinkSpan.Resolver linkResolver; |     private final LinkSpan.Resolver linkResolver; | ||||||
|     private final UrlProcessor urlProcessor; |     private final UrlProcessor urlProcessor; | ||||||
|     private final ImageSizeResolver imageSizeResolver; |     private final ImageSizeResolver imageSizeResolver; | ||||||
|     private final SpannableFactory factory; // @since 1.1.0 |     private final MarkwonSpannableFactory factory; // @since 1.1.0 | ||||||
| 
 | 
 | ||||||
|     private MarkwonConfiguration(@NonNull Builder builder) { |     private MarkwonConfiguration(@NonNull Builder builder) { | ||||||
|         this.theme = builder.theme; |         this.theme = builder.theme; | ||||||
| @ -80,7 +82,7 @@ public class MarkwonConfiguration { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     public SpannableFactory factory() { |     public MarkwonSpannableFactory factory() { | ||||||
|         return factory; |         return factory; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -95,7 +97,7 @@ public class MarkwonConfiguration { | |||||||
|         private LinkSpan.Resolver linkResolver; |         private LinkSpan.Resolver linkResolver; | ||||||
|         private UrlProcessor urlProcessor; |         private UrlProcessor urlProcessor; | ||||||
|         private ImageSizeResolver imageSizeResolver; |         private ImageSizeResolver imageSizeResolver; | ||||||
|         private SpannableFactory factory; // @since 1.1.0 |         private MarkwonSpannableFactory factory; // @since 1.1.0 | ||||||
| 
 | 
 | ||||||
|         Builder(@NonNull Context context) { |         Builder(@NonNull Context context) { | ||||||
|             this.context = context; |             this.context = context; | ||||||
| @ -132,7 +134,7 @@ public class MarkwonConfiguration { | |||||||
|          * @since 1.1.0 |          * @since 1.1.0 | ||||||
|          */ |          */ | ||||||
|         @NonNull |         @NonNull | ||||||
|         public Builder factory(@NonNull SpannableFactory factory) { |         public Builder factory(@NonNull MarkwonSpannableFactory factory) { | ||||||
|             this.factory = factory; |             this.factory = factory; | ||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
| @ -161,7 +163,7 @@ public class MarkwonConfiguration { | |||||||
| 
 | 
 | ||||||
|             // @since 1.1.0 |             // @since 1.1.0 | ||||||
|             if (factory == null) { |             if (factory == null) { | ||||||
|                 factory = SpannableFactoryDef.create(); |                 factory = MarkwonSpannableFactoryDef.create(); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return new MarkwonConfiguration(this); |             return new MarkwonConfiguration(this); | ||||||
|  | |||||||
| @ -6,8 +6,8 @@ import android.widget.TextView; | |||||||
| import org.commonmark.node.Node; | import org.commonmark.node.Node; | ||||||
| import org.commonmark.parser.Parser; | import org.commonmark.parser.Parser; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| 
 | 
 | ||||||
| public interface MarkwonPlugin { | public interface MarkwonPlugin { | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import org.commonmark.node.Node; | |||||||
| import org.commonmark.node.Visitor; | import org.commonmark.node.Visitor; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
| 
 | 
 | ||||||
| public interface MarkwonVisitor extends Visitor { | public interface MarkwonVisitor extends Visitor { | ||||||
| 
 | 
 | ||||||
| @ -30,7 +31,7 @@ public interface MarkwonVisitor extends Visitor { | |||||||
|     MarkwonTheme theme(); |     MarkwonTheme theme(); | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     SpannableFactory factory(); |     MarkwonSpannableFactory factory(); | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     SpannableBuilder builder(); |     SpannableBuilder builder(); | ||||||
|  | |||||||
| @ -32,6 +32,7 @@ import java.util.HashMap; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
| 
 | 
 | ||||||
| class MarkwonVisitorImpl implements MarkwonVisitor { | class MarkwonVisitorImpl implements MarkwonVisitor { | ||||||
| 
 | 
 | ||||||
| @ -39,7 +40,7 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | |||||||
| 
 | 
 | ||||||
|     private final MarkwonConfiguration configuration; |     private final MarkwonConfiguration configuration; | ||||||
|     private final MarkwonTheme theme; |     private final MarkwonTheme theme; | ||||||
|     private final SpannableFactory factory; |     private final MarkwonSpannableFactory factory; | ||||||
| 
 | 
 | ||||||
|     private final SpannableBuilder builder = new SpannableBuilder(); |     private final SpannableBuilder builder = new SpannableBuilder(); | ||||||
| 
 | 
 | ||||||
| @ -186,7 +187,7 @@ class MarkwonVisitorImpl implements MarkwonVisitor { | |||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     @Override |     @Override | ||||||
|     public SpannableFactory factory() { |     public MarkwonSpannableFactory factory() { | ||||||
|         return factory; |         return factory; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,20 +1,16 @@ | |||||||
| package ru.noties.markwon; | package ru.noties.markwon.core; | ||||||
| 
 | 
 | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.image.ImageSize; |  | ||||||
| import ru.noties.markwon.image.ImageSizeResolver; |  | ||||||
| import ru.noties.markwon.core.spans.LinkSpan; | import ru.noties.markwon.core.spans.LinkSpan; | ||||||
| import ru.noties.markwon.core.MarkwonTheme; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Each method can return null or a Span object or an array of spans |  * Each method can return null or a Span object or an array of spans | ||||||
|  * |  * | ||||||
|  * @since 1.1.0 |  * @since 1.1.0 | ||||||
|  */ |  */ | ||||||
| public interface SpannableFactory { | public interface MarkwonSpannableFactory { | ||||||
| 
 | 
 | ||||||
|     @Nullable |     @Nullable | ||||||
|     Object strongEmphasis(); |     Object strongEmphasis(); | ||||||
| @ -46,15 +42,6 @@ public interface SpannableFactory { | |||||||
|     @Nullable |     @Nullable | ||||||
|     Object paragraph(boolean inTightList); |     Object paragraph(boolean inTightList); | ||||||
| 
 | 
 | ||||||
|     @Nullable |  | ||||||
|     Object image( |  | ||||||
|             @NonNull MarkwonTheme theme, |  | ||||||
|             @NonNull String destination, |  | ||||||
|             @NonNull AsyncDrawableLoader loader, |  | ||||||
|             @NonNull ImageSizeResolver imageSizeResolver, |  | ||||||
|             @Nullable ImageSize imageSize, |  | ||||||
|             boolean replacementTextIsLink); |  | ||||||
| 
 |  | ||||||
|     @Nullable |     @Nullable | ||||||
|     Object link( |     Object link( | ||||||
|             @NonNull MarkwonTheme theme, |             @NonNull MarkwonTheme theme, | ||||||
| @ -1,20 +1,14 @@ | |||||||
| package ru.noties.markwon; | package ru.noties.markwon.core; | ||||||
| 
 | 
 | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.image.AsyncDrawable; |  | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.image.ImageSize; |  | ||||||
| import ru.noties.markwon.image.ImageSizeResolver; |  | ||||||
| import ru.noties.markwon.core.spans.AsyncDrawableSpan; |  | ||||||
| import ru.noties.markwon.core.spans.BlockQuoteSpan; | import ru.noties.markwon.core.spans.BlockQuoteSpan; | ||||||
| import ru.noties.markwon.core.spans.BulletListItemSpan; | import ru.noties.markwon.core.spans.BulletListItemSpan; | ||||||
| import ru.noties.markwon.core.spans.CodeSpan; | import ru.noties.markwon.core.spans.CodeSpan; | ||||||
| import ru.noties.markwon.core.spans.EmphasisSpan; | import ru.noties.markwon.core.spans.EmphasisSpan; | ||||||
| import ru.noties.markwon.core.spans.HeadingSpan; | import ru.noties.markwon.core.spans.HeadingSpan; | ||||||
| import ru.noties.markwon.core.spans.LinkSpan; | import ru.noties.markwon.core.spans.LinkSpan; | ||||||
| import ru.noties.markwon.core.MarkwonTheme; |  | ||||||
| import ru.noties.markwon.core.spans.OrderedListItemSpan; | import ru.noties.markwon.core.spans.OrderedListItemSpan; | ||||||
| import ru.noties.markwon.core.spans.StrongEmphasisSpan; | import ru.noties.markwon.core.spans.StrongEmphasisSpan; | ||||||
| import ru.noties.markwon.core.spans.ThematicBreakSpan; | import ru.noties.markwon.core.spans.ThematicBreakSpan; | ||||||
| @ -22,11 +16,11 @@ import ru.noties.markwon.core.spans.ThematicBreakSpan; | |||||||
| /** | /** | ||||||
|  * @since 1.1.0 |  * @since 1.1.0 | ||||||
|  */ |  */ | ||||||
| public class SpannableFactoryDef implements SpannableFactory { | public class MarkwonSpannableFactoryDef implements MarkwonSpannableFactory { | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     public static SpannableFactoryDef create() { |     public static MarkwonSpannableFactoryDef create() { | ||||||
|         return new SpannableFactoryDef(); |         return new MarkwonSpannableFactoryDef(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Nullable |     @Nullable | ||||||
| @ -87,22 +81,6 @@ public class SpannableFactoryDef implements SpannableFactory { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Nullable |  | ||||||
|     @Override |  | ||||||
|     public Object image(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull AsyncDrawableLoader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) { |  | ||||||
|         return new AsyncDrawableSpan( |  | ||||||
|                 theme, |  | ||||||
|                 new AsyncDrawable( |  | ||||||
|                         destination, |  | ||||||
|                         loader, |  | ||||||
|                         imageSizeResolver, |  | ||||||
|                         imageSize |  | ||||||
|                 ), |  | ||||||
|                 AsyncDrawableSpan.ALIGN_BOTTOM, |  | ||||||
|                 replacementTextIsLink |  | ||||||
|         ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Nullable |     @Nullable | ||||||
|     @Override |     @Override | ||||||
|     public Object link(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull LinkSpan.Resolver resolver) { |     public Object link(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull LinkSpan.Resolver resolver) { | ||||||
| @ -4,7 +4,6 @@ import android.content.Context; | |||||||
| import android.graphics.Paint; | import android.graphics.Paint; | ||||||
| import android.graphics.Typeface; | import android.graphics.Typeface; | ||||||
| import android.support.annotation.ColorInt; | import android.support.annotation.ColorInt; | ||||||
| import android.support.annotation.FloatRange; |  | ||||||
| import android.support.annotation.IntRange; | import android.support.annotation.IntRange; | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Px; | import android.support.annotation.Px; | ||||||
| @ -96,8 +95,6 @@ public class MarkwonTheme { | |||||||
|             2.F, 1.5F, 1.17F, 1.F, .83F, .67F, |             2.F, 1.5F, 1.17F, 1.F, .83F, .67F, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     protected static final float SCRIPT_DEF_TEXT_SIZE_RATIO = .75F; |  | ||||||
| 
 |  | ||||||
|     protected static final int THEMATIC_BREAK_DEF_ALPHA = 25; |     protected static final int THEMATIC_BREAK_DEF_ALPHA = 25; | ||||||
| 
 | 
 | ||||||
|     protected final int linkColor; |     protected final int linkColor; | ||||||
| @ -158,9 +155,6 @@ public class MarkwonTheme { | |||||||
|     // @since 1.1.0 |     // @since 1.1.0 | ||||||
|     protected final float[] headingTextSizeMultipliers; |     protected final float[] headingTextSizeMultipliers; | ||||||
| 
 | 
 | ||||||
|     // by default `SCRIPT_DEF_TEXT_SIZE_RATIO` |  | ||||||
|     protected final float scriptTextSizeRatio; |  | ||||||
| 
 |  | ||||||
|     // by default textColor with `THEMATIC_BREAK_DEF_ALPHA` applied alpha |     // by default textColor with `THEMATIC_BREAK_DEF_ALPHA` applied alpha | ||||||
|     protected final int thematicBreakColor; |     protected final int thematicBreakColor; | ||||||
| 
 | 
 | ||||||
| @ -186,7 +180,6 @@ public class MarkwonTheme { | |||||||
|         this.headingBreakColor = builder.headingBreakColor; |         this.headingBreakColor = builder.headingBreakColor; | ||||||
|         this.headingTypeface = builder.headingTypeface; |         this.headingTypeface = builder.headingTypeface; | ||||||
|         this.headingTextSizeMultipliers = builder.headingTextSizeMultipliers; |         this.headingTextSizeMultipliers = builder.headingTextSizeMultipliers; | ||||||
|         this.scriptTextSizeRatio = builder.scriptTextSizeRatio; |  | ||||||
|         this.thematicBreakColor = builder.thematicBreakColor; |         this.thematicBreakColor = builder.thematicBreakColor; | ||||||
|         this.thematicBreakHeight = builder.thematicBreakHeight; |         this.thematicBreakHeight = builder.thematicBreakHeight; | ||||||
|     } |     } | ||||||
| @ -369,28 +362,6 @@ public class MarkwonTheme { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void applySuperScriptStyle(@NonNull TextPaint paint) { |  | ||||||
|         final float ratio; |  | ||||||
|         if (Float.compare(scriptTextSizeRatio, .0F) == 0) { |  | ||||||
|             ratio = SCRIPT_DEF_TEXT_SIZE_RATIO; |  | ||||||
|         } else { |  | ||||||
|             ratio = scriptTextSizeRatio; |  | ||||||
|         } |  | ||||||
|         paint.setTextSize(paint.getTextSize() * ratio); |  | ||||||
|         paint.baselineShift += (int) (paint.ascent() / 2); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void applySubScriptStyle(@NonNull TextPaint paint) { |  | ||||||
|         final float ratio; |  | ||||||
|         if (Float.compare(scriptTextSizeRatio, .0F) == 0) { |  | ||||||
|             ratio = SCRIPT_DEF_TEXT_SIZE_RATIO; |  | ||||||
|         } else { |  | ||||||
|             ratio = scriptTextSizeRatio; |  | ||||||
|         } |  | ||||||
|         paint.setTextSize(paint.getTextSize() * ratio); |  | ||||||
|         paint.baselineShift -= (int) (paint.ascent() / 2); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void applyThematicBreakStyle(@NonNull Paint paint) { |     public void applyThematicBreakStyle(@NonNull Paint paint) { | ||||||
|         final int color; |         final int color; | ||||||
|         if (thematicBreakColor != 0) { |         if (thematicBreakColor != 0) { | ||||||
| @ -428,7 +399,6 @@ public class MarkwonTheme { | |||||||
|         private int headingBreakColor; |         private int headingBreakColor; | ||||||
|         private Typeface headingTypeface; |         private Typeface headingTypeface; | ||||||
|         private float[] headingTextSizeMultipliers; |         private float[] headingTextSizeMultipliers; | ||||||
|         private float scriptTextSizeRatio; |  | ||||||
|         private int thematicBreakColor; |         private int thematicBreakColor; | ||||||
|         private int thematicBreakHeight = -1; |         private int thematicBreakHeight = -1; | ||||||
| 
 | 
 | ||||||
| @ -454,7 +424,6 @@ public class MarkwonTheme { | |||||||
|             this.headingBreakColor = theme.headingBreakColor; |             this.headingBreakColor = theme.headingBreakColor; | ||||||
|             this.headingTypeface = theme.headingTypeface; |             this.headingTypeface = theme.headingTypeface; | ||||||
|             this.headingTextSizeMultipliers = theme.headingTextSizeMultipliers; |             this.headingTextSizeMultipliers = theme.headingTextSizeMultipliers; | ||||||
|             this.scriptTextSizeRatio = theme.scriptTextSizeRatio; |  | ||||||
|             this.thematicBreakColor = theme.thematicBreakColor; |             this.thematicBreakColor = theme.thematicBreakColor; | ||||||
|             this.thematicBreakHeight = theme.thematicBreakHeight; |             this.thematicBreakHeight = theme.thematicBreakHeight; | ||||||
|         } |         } | ||||||
| @ -586,12 +555,6 @@ public class MarkwonTheme { | |||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         @NonNull |  | ||||||
|         public Builder scriptTextSizeRatio(@FloatRange(from = .0F, to = Float.MAX_VALUE) float scriptTextSizeRatio) { |  | ||||||
|             this.scriptTextSizeRatio = scriptTextSizeRatio; |  | ||||||
|             return this; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         @NonNull |         @NonNull | ||||||
|         public Builder thematicBreakColor(@ColorInt int thematicBreakColor) { |         public Builder thematicBreakColor(@ColorInt int thematicBreakColor) { | ||||||
|             this.thematicBreakColor = thematicBreakColor; |             this.thematicBreakColor = thematicBreakColor; | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package ru.noties.markwon.image; | |||||||
| 
 | 
 | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
|  | import android.support.annotation.Nullable; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
| 
 | 
 | ||||||
| import org.commonmark.node.Image; | import org.commonmark.node.Image; | ||||||
| @ -13,6 +14,8 @@ import java.util.Arrays; | |||||||
| import ru.noties.markwon.AbstractMarkwonPlugin; | import ru.noties.markwon.AbstractMarkwonPlugin; | ||||||
| import ru.noties.markwon.MarkwonConfiguration; | import ru.noties.markwon.MarkwonConfiguration; | ||||||
| import ru.noties.markwon.MarkwonVisitor; | import ru.noties.markwon.MarkwonVisitor; | ||||||
|  | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.spans.AsyncDrawableSpan; | ||||||
| import ru.noties.markwon.image.data.DataUriSchemeHandler; | import ru.noties.markwon.image.data.DataUriSchemeHandler; | ||||||
| import ru.noties.markwon.image.file.FileSchemeHandler; | import ru.noties.markwon.image.file.FileSchemeHandler; | ||||||
| import ru.noties.markwon.image.network.NetworkSchemeHandler; | import ru.noties.markwon.image.network.NetworkSchemeHandler; | ||||||
| @ -78,12 +81,11 @@ public class ImagesPlugin extends AbstractMarkwonPlugin { | |||||||
|                         .urlProcessor() |                         .urlProcessor() | ||||||
|                         .process(image.getDestination()); |                         .process(image.getDestination()); | ||||||
| 
 | 
 | ||||||
|                 final Object spans = visitor.factory().image( |                 final Object spans = imageSpan( | ||||||
|                         visitor.theme(), |                         visitor.theme(), | ||||||
|                         destination, |                         destination, | ||||||
|                         configuration.asyncDrawableLoader(), |                         configuration.asyncDrawableLoader(), | ||||||
|                         configuration.imageSizeResolver(), |                         configuration.imageSizeResolver(), | ||||||
|                         null, |  | ||||||
|                         link); |                         link); | ||||||
| 
 | 
 | ||||||
|                 visitor.setSpans(length, spans); |                 visitor.setSpans(length, spans); | ||||||
| @ -100,4 +102,24 @@ public class ImagesPlugin extends AbstractMarkwonPlugin { | |||||||
|     public void afterSetText(@NonNull TextView textView) { |     public void afterSetText(@NonNull TextView textView) { | ||||||
|         AsyncDrawableScheduler.schedule(textView); |         AsyncDrawableScheduler.schedule(textView); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     @Nullable | ||||||
|  |     protected Object imageSpan( | ||||||
|  |             @NonNull MarkwonTheme theme, | ||||||
|  |             @NonNull String destination, | ||||||
|  |             @NonNull AsyncDrawableLoader loader, | ||||||
|  |             @NonNull ImageSizeResolver imageSizeResolver, | ||||||
|  |             boolean replacementTextIsLink) { | ||||||
|  |         return new AsyncDrawableSpan( | ||||||
|  |                 theme, | ||||||
|  |                 new AsyncDrawable( | ||||||
|  |                         destination, | ||||||
|  |                         loader, | ||||||
|  |                         imageSizeResolver, | ||||||
|  |                         null | ||||||
|  |                 ), | ||||||
|  |                 AsyncDrawableSpan.ALIGN_BOTTOM, | ||||||
|  |                 replacementTextIsLink | ||||||
|  |         ); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| package ru.noties.markwon.core; | package ru.noties.markwon.core; | ||||||
| 
 | 
 | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Nullable; |  | ||||||
| import android.text.Spanned; | import android.text.Spanned; | ||||||
| 
 | 
 | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| @ -13,7 +12,6 @@ import org.robolectric.annotation.Config; | |||||||
| import ru.noties.markwon.AbstractMarkwonPlugin; | import ru.noties.markwon.AbstractMarkwonPlugin; | ||||||
| import ru.noties.markwon.Markwon; | import ru.noties.markwon.Markwon; | ||||||
| import ru.noties.markwon.MarkwonConfiguration; | import ru.noties.markwon.MarkwonConfiguration; | ||||||
| import ru.noties.markwon.SpannableFactoryDef; |  | ||||||
| import ru.noties.markwon.test.TestSpan; | import ru.noties.markwon.test.TestSpan; | ||||||
| import ru.noties.markwon.test.TestSpanMatcher; | import ru.noties.markwon.test.TestSpanMatcher; | ||||||
| 
 | 
 | ||||||
| @ -38,7 +36,7 @@ public class CoreTest { | |||||||
|                 .use(new AbstractMarkwonPlugin() { |                 .use(new AbstractMarkwonPlugin() { | ||||||
|                     @Override |                     @Override | ||||||
|                     public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { |                     public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { | ||||||
|                         builder.factory(new SpannableFactoryDef() { |                         builder.factory(new MarkwonSpannableFactoryDef() { | ||||||
| 
 | 
 | ||||||
|                             @Override |                             @Override | ||||||
|                             public Object strongEmphasis() { |                             public Object strongEmphasis() { | ||||||
|  | |||||||
| @ -3,17 +3,14 @@ package ru.noties.markwon.core.suite; | |||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.SpannableFactory; | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
| import ru.noties.markwon.core.spans.LinkSpan; | import ru.noties.markwon.core.spans.LinkSpan; | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; |  | ||||||
| import ru.noties.markwon.image.ImageSize; |  | ||||||
| import ru.noties.markwon.image.ImageSizeResolver; |  | ||||||
| 
 | 
 | ||||||
| import static ru.noties.markwon.test.TestSpan.args; | import static ru.noties.markwon.test.TestSpan.args; | ||||||
| import static ru.noties.markwon.test.TestSpan.span; | import static ru.noties.markwon.test.TestSpan.span; | ||||||
| 
 | 
 | ||||||
| class TestFactory implements SpannableFactory { | class TestFactory implements MarkwonSpannableFactory { | ||||||
| 
 | 
 | ||||||
|   static final String BOLD = "bold"; |   static final String BOLD = "bold"; | ||||||
|   static final String ITALIC = "italic"; |   static final String ITALIC = "italic"; | ||||||
| @ -88,12 +85,6 @@ class TestFactory implements SpannableFactory { | |||||||
|       : null; |       : null; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @Nullable |  | ||||||
|   @Override |  | ||||||
|   public Object image(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull AsyncDrawableLoader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) { |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   @Nullable |   @Nullable | ||||||
|   @Override |   @Override | ||||||
|   public Object link(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull LinkSpan.Resolver resolver) { |   public Object link(@NonNull MarkwonTheme theme, @NonNull String destination, @NonNull LinkSpan.Resolver resolver) { | ||||||
|  | |||||||
| @ -7,8 +7,8 @@ import java.util.Collections; | |||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| import ru.noties.markwon.SpannableFactory; |  | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
| import ru.noties.markwon.core.spans.LinkSpan; | import ru.noties.markwon.core.spans.LinkSpan; | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| import ru.noties.markwon.image.ImageSize; | import ru.noties.markwon.image.ImageSize; | ||||||
| @ -27,7 +27,7 @@ import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH; | |||||||
| import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS; | import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS; | ||||||
| import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK; | import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK; | ||||||
| 
 | 
 | ||||||
| class TestFactory implements SpannableFactory { | class TestFactory implements MarkwonSpannableFactory { | ||||||
| 
 | 
 | ||||||
|     private final boolean useParagraphs; |     private final boolean useParagraphs; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -21,8 +21,8 @@ import ru.noties.markwon.AbstractMarkwonVisitorImpl; | |||||||
| import ru.noties.markwon.MarkwonConfiguration; | import ru.noties.markwon.MarkwonConfiguration; | ||||||
| import ru.noties.markwon.MarkwonVisitor; | import ru.noties.markwon.MarkwonVisitor; | ||||||
| import ru.noties.markwon.SpannableBuilder; | import ru.noties.markwon.SpannableBuilder; | ||||||
| import ru.noties.markwon.SpannableFactory; |  | ||||||
| import ru.noties.markwon.core.MarkwonTheme; | import ru.noties.markwon.core.MarkwonTheme; | ||||||
|  | import ru.noties.markwon.core.MarkwonSpannableFactory; | ||||||
| import ru.noties.markwon.core.visitor.CodeBlockNodeVisitor; | import ru.noties.markwon.core.visitor.CodeBlockNodeVisitor; | ||||||
| import ru.noties.markwon.image.AsyncDrawableLoader; | import ru.noties.markwon.image.AsyncDrawableLoader; | ||||||
| 
 | 
 | ||||||
| @ -71,7 +71,7 @@ public class SyntaxHighlightTest { | |||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         final SpannableFactory factory = mock(SpannableFactory.class); |         final MarkwonSpannableFactory factory = mock(MarkwonSpannableFactory.class); | ||||||
|         when(factory.code(any(MarkwonTheme.class), anyBoolean())).thenReturn(codeSpan); |         when(factory.code(any(MarkwonTheme.class), anyBoolean())).thenReturn(codeSpan); | ||||||
| 
 | 
 | ||||||
|         final MarkwonConfiguration configuration = MarkwonConfiguration.builder(mock(Context.class)) |         final MarkwonConfiguration configuration = MarkwonConfiguration.builder(mock(Context.class)) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov