LinkifyPlugin is thread-safe
This commit is contained in:
		
							parent
							
								
									681a7f68d7
								
							
						
					
					
						commit
						a6201b1b35
					
				| @ -7,6 +7,7 @@ | ||||
| * Add `SvgPictureMediaDecoder` in `image` module to deal with SVG without dimensions ([#165]) | ||||
| * `LinkSpan#getLink` method | ||||
| * `LinkifyPlugin` applies link span that is configured by `Markwon` (obtain via span factory) | ||||
| * `LinkifyPlugin` is thread-safe | ||||
| 
 | ||||
| [#165]: https://github.com/noties/Markwon/issues/165 | ||||
| 
 | ||||
|  | ||||
| @ -58,15 +58,12 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     // todo: thread safety (builder is reused) | ||||
|     private static class LinkifyTextAddedListener implements CorePlugin.OnTextAddedListener { | ||||
| 
 | ||||
|         private final int mask; | ||||
|         private final SpannableStringBuilder builder; | ||||
| 
 | ||||
|         LinkifyTextAddedListener(int mask) { | ||||
|             this.mask = mask; | ||||
|             this.builder = new SpannableStringBuilder(); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
| @ -79,12 +76,9 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             // clear previous state | ||||
|             builder.clear(); | ||||
|             builder.clearSpans(); | ||||
| 
 | ||||
|             // append text to process | ||||
|             builder.append(text); | ||||
|             // @since 4.2.0-SNAPSHOT we no longer re-use builder (thread safety achieved for | ||||
|             //  render calls from different threads and ... better performance) | ||||
|             final SpannableStringBuilder builder = new SpannableStringBuilder(text); | ||||
| 
 | ||||
|             if (Linkify.addLinks(builder, mask)) { | ||||
|                 // target URL span specifically | ||||
|  | ||||
| @ -35,6 +35,7 @@ import io.noties.markwon.editor.MarkwonEditor; | ||||
| import io.noties.markwon.editor.MarkwonEditorTextWatcher; | ||||
| import io.noties.markwon.editor.MarkwonEditorUtils; | ||||
| import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; | ||||
| import io.noties.markwon.linkify.LinkifyPlugin; | ||||
| import io.noties.markwon.sample.R; | ||||
| 
 | ||||
| public class EditorActivity extends Activity { | ||||
| @ -154,7 +155,7 @@ public class EditorActivity extends Activity { | ||||
| 
 | ||||
|         final Markwon markwon = Markwon.builder(this) | ||||
|                 .usePlugin(StrikethroughPlugin.create()) | ||||
| //                .usePlugin(LinkifyPlugin.create()) | ||||
|                 .usePlugin(LinkifyPlugin.create()) | ||||
|                 .build(); | ||||
| 
 | ||||
|         final MarkwonTheme theme = markwon.configuration().theme(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov