Skip to content

Commit

Permalink
Merge pull request #191 from noties/v4.2.1
Browse files Browse the repository at this point in the history
V4.2.1
  • Loading branch information
noties authored Feb 2, 2020
2 parents b844f4d + 34f71f1 commit c939c0f
Show file tree
Hide file tree
Showing 22 changed files with 596 additions and 45 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# 4.2.1
* Fix SpannableBuilder `subSequence` method
* Introduce Nougat check in `BulletListItemSpan` to position bullet (for bullets to be
positioned correctly when nested inside other `LeadingMarginSpan`s)
* Reduced number of invalidations in AsyncDrawable when result is ready
* AsyncDrawable#hasKnownDimentions -> AsyncDrawable#hasKnownDimensions typo fix

# 4.2.0
* `MarkwonEditor` to highlight markdown input whilst editing (new module: `markwon-editor`)
* `CoilImagesPlugin` image loader based on [Coil] library (new module: `markwon-image-coil`) ([#166], [#174])
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package="io.noties.markwon.app">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_ALL_DOWNLOADS" />

<application
android:name=".App"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.file.FileSchemeHandler;
import io.noties.markwon.image.gif.GifMediaDecoder;
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler;
import io.noties.markwon.syntax.Prism4jTheme;
import io.noties.markwon.syntax.Prism4jThemeDarkula;
Expand Down Expand Up @@ -105,7 +106,8 @@ public void configureImages(@NonNull ImagesPlugin plugin) {
// default-media-decoder is also added automatically
plugin
.addSchemeHandler(OkHttpNetworkSchemeHandler.create())
.addSchemeHandler(FileSchemeHandler.createWithAssets(context.getAssets()));
.addSchemeHandler(FileSchemeHandler.createWithAssets(context.getAssets()))
.addMediaDecoder(GifMediaDecoder.create(false));
}
}))
.usePlugin(SyntaxHighlightPlugin.create(prism4j, prism4jTheme))
Expand Down
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.27.0'
}
}

Expand Down Expand Up @@ -55,6 +55,11 @@ ext {
final def commonMarkVersion = '0.13.0'
final def daggerVersion = '2.10'

// please note that `pl.droidsonroids.gif:android-gif-drawable:1.2.15` is used due to the minimum
// api level mismatch that Markwon supports (16) and later versions of AndroidGifDrawable (17).
// It should not be a problem as this dependency is used as `compileOnly` and users
// must specify version explicitly (until library's API changes...)

deps = [
'x-annotations' : 'androidx.annotation:annotation:1.1.0',
'x-recycler-view' : 'androidx.recyclerview:recyclerview:1.0.0',
Expand All @@ -63,7 +68,7 @@ ext {
'commonmark-strikethrough': "com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:$commonMarkVersion",
'commonmark-table' : "com.atlassian.commonmark:commonmark-ext-gfm-tables:$commonMarkVersion",
'android-svg' : 'com.caverock:androidsvg:1.4',
'android-gif' : 'pl.droidsonroids.gif:android-gif-drawable:1.2.14',
'android-gif' : 'pl.droidsonroids.gif:android-gif-drawable:1.2.15',
'jlatexmath-android' : 'ru.noties:jlatexmath-android:0.1.0',
'okhttp' : 'com.squareup.okhttp3:okhttp:3.9.0',
'prism4j' : 'io.noties:prism4j:2.0.0',
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/components/AwesomeGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
margin: 0.25em;
border-radius: 0.25em;
box-shadow: 0 0 0.1em 0.1em #eee;
max-width: 30%;
max-width: 25%;
min-width: 100px;
display: flex;
align-items: center;
Expand Down
Binary file added docs/.vuepress/public/assets/apps/cinopsys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/assets/apps/habitica.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/assets/apps/nextcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 25 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: 'Introduction'

<br><br>
[![markwon](https://img.shields.io/maven-central/v/io.noties.markwon/core.svg?label=markwon)](http://search.maven.org/#search|ga|1|g%3A%22io.noties.markwon%22%20)
[![Build Status](https://travis-ci.org/noties/Markwon.svg?branch=master)](https://travis-ci.org/noties/Markwon)
[![Build](https://github.com/noties/Markwon/workflows/Build/badge.svg)](https://github.com/noties/Markwon/actions)

**Markwon** is a markdown library for Android. It parses markdown following
<Link name="commonmark-spec" /> with the help of amazing <Link name="commonmark-java" /> library
Expand Down Expand Up @@ -79,7 +79,26 @@ and 2 themes included: Light &amp; Dark. It can be downloaded from [releases](ht
:::


## Awesome Markwon
<style>
.awesome-block {
background-color: #4CAF50;
height: 7rem;
display: flex;
justify-content: center;
align-items: center;
}

.awesome-block * {
border: 0
}
</style>


<div class="awesome-block">

## # Awesome Markwon

</div>

<u>Applications using Markwon</u>:

Expand All @@ -88,9 +107,12 @@ and 2 themes included: Light &amp; Dark. It can be downloaded from [releases](ht
* [Boxcryptor](https://www.boxcryptor.com) - A software that adds AES-256 and RSA encryption to Dropbox, Google Drive, OneDrive and many other clouds.

<AwesomeGroup :apps="[
{name: 'Cinopsys: Movies and Shows', image: 'http://drive.google.com/uc?export=view&id=1rD0HLd8tDUCe8QcVEG_iGvsJbFyozRhC', link: 'https://play.google.com/store/apps/details?id=com.cinopsys.movieshows'}
{name: 'Nextcloud', image: $withBase(`/assets/apps/nextcloud.png`), link: 'https://github.com/nextcloud/android', description: 'A safe home for all your data. Access & share your files, calendars, contacts, mail & more from any device, on your terms.'},
{name: 'Habitica', image: $withBase(`/assets/apps/habitica.png`), link: 'https://play.google.com/store/apps/details?id=com.habitrpg.android.habitica', description: 'Treat your life like a game to stay motivated and organized! Habitica makes it simple to have fun while accomplishing goals.'},
{name: 'Cinopsys: Movies and Shows', image: $withBase(`/assets/apps/cinopsys.png`), link: 'https://play.google.com/store/apps/details?id=com.cinopsys.movieshows'}
]" />


<u>Extension/plugins</u>:

* [MarkwonCodeEx](https://github.com/kingideayou/MarkwonCodeEx) - Markwon extension support elegant code background.
Expand Down
9 changes: 5 additions & 4 deletions docs/docs/v4/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ imagesPlugin.addSchemeHandler(new SchemeHandler() {
:::warning
If you wish to add support for **SVG** or **GIF** you must explicitly add these dependencies
to your project:
* for `SVG`: `com.caverock:androidsvg:1.4`
* for `GIF`: `pl.droidsonroids.gif:android-gif-drawable:1.2.14`
* to support `SVG`: [com.caverock:androidsvg](https://github.com/BigBadaboom/androidsvg)
* to support `GIF`: [pl.droidsonroids.gif:android-gif-drawable](https://github.com/koral--/android-gif-drawable)

You can try more recent versions of these libraries, but make sure that they doesn't
introduce any unexpected behavior.
For [security reasons](https://github.com/noties/Markwon/issues/186) it's advisable to use latest
versions of these libraries. If you notice compilation and/or runtime issues when used with Markwon,
please [create an issue](https://github.com/noties/Markwon/issues/new) specifying library and library version used.
:::


Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android.enableJetifier=true
android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache

VERSION_NAME=4.2.0
VERSION_NAME=4.2.1

GROUP=io.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public CharSequence subSequence(int start, int end) {
// if a span was fully including resulting subSequence it's start and
// end must be within 0..length bounds
s = Math.max(0, span.start - start);
e = Math.max(length, s + (span.end - span.start));
e = Math.min(length, s + (span.end - span.start));

builder.setSpan(
span.what,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout;
import android.text.style.LeadingMarginSpan;

Expand All @@ -15,6 +16,13 @@

public class BulletListItemSpan implements LeadingMarginSpan {

private static final boolean IS_NOUGAT;

static {
final int sdk = Build.VERSION.SDK_INT;
IS_NOUGAT = Build.VERSION_CODES.N == sdk || Build.VERSION_CODES.N_MR1 == sdk;
}

private MarkwonTheme theme;

private final Paint paint = ObjectsPool.paint();
Expand Down Expand Up @@ -62,28 +70,41 @@ public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int ba

final int marginLeft = (width - side) / 2;

// @since 2.0.2
// There is a bug in Android Nougat, when this span receives an `x` that
// doesn't correspond to what it should be (text is placed correctly though).
// Let's make this a general rule -> manually calculate difference between expected/actual
// and add this difference to resulting left/right values. If everything goes well
// we do not encounter a bug -> this `diff` value will be 0
final int diff;
if (dir < 0) {
// rtl
diff = x - (layout.getWidth() - (width * level));
} else {
diff = (width * level) - x;
}

// in order to support RTL
final int l;
final int r;
{
final int left = x + (dir * marginLeft);
final int right = left + (dir * side);
l = Math.min(left, right) + (dir * diff);
r = Math.max(left, right) + (dir * diff);
// @since 4.2.1 to correctly position bullet
// when nested inside other LeadingMarginSpans (sorry, Nougat)
if (IS_NOUGAT) {

// @since 2.0.2
// There is a bug in Android Nougat, when this span receives an `x` that
// doesn't correspond to what it should be (text is placed correctly though).
// Let's make this a general rule -> manually calculate difference between expected/actual
// and add this difference to resulting left/right values. If everything goes well
// we do not encounter a bug -> this `diff` value will be 0
final int diff;
if (dir < 0) {
// rtl
diff = x - (layout.getWidth() - (width * level));
} else {
diff = (width * level) - x;
}

final int left = x + (dir * marginLeft);
final int right = left + (dir * side);
l = Math.min(left, right) + (dir * diff);
r = Math.max(left, right) + (dir * diff);

} else {
if (dir > 0) {
l = x + marginLeft;
} else {
l = x - width + marginLeft;
}
r = l + side;
}
}

final int t = baseline + (int) ((paint.descent() + paint.ascent()) / 2.F + .5F) - (side / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getDestination() {
/**
* @since 4.0.0
*/
@SuppressWarnings("WeakerAccess")
@Nullable
public ImageSize getImageSize() {
return imageSize;
Expand All @@ -63,30 +64,44 @@ public ImageSize getImageSize() {
/**
* @since 4.0.0
*/
@SuppressWarnings("unused")
@NonNull
public ImageSizeResolver getImageSizeResolver() {
return imageSizeResolver;
}

/**
* @see #hasKnownDimensions()
* @since 4.0.0
* @deprecated 4.2.1
*/
@SuppressWarnings({"unused", "WeakerAccess"})
@Deprecated
public boolean hasKnownDimentions() {
return canvasWidth > 0;
}

/**
* @see #hasKnownDimentions()
* @since 4.2.1
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public boolean hasKnownDimensions() {
return canvasWidth > 0;
}

/**
* @see #hasKnownDimensions()
* @since 4.0.0
*/
public int getLastKnownCanvasWidth() {
return canvasWidth;
}

/**
* @see #hasKnownDimentions()
* @see #hasKnownDimensions()
* @since 4.0.0
*/
@SuppressWarnings("WeakerAccess")
public float getLastKnowTextSize() {
return textSize;
}
Expand All @@ -95,6 +110,7 @@ public Drawable getResult() {
return result;
}

@SuppressWarnings("WeakerAccess")
public boolean hasResult() {
return result != null;
}
Expand All @@ -104,10 +120,17 @@ public boolean isAttached() {
}

// yeah
public void setCallback2(@Nullable Callback callback) {
@SuppressWarnings("WeakerAccess")
public void setCallback2(@Nullable Callback cb) {

this.callback = callback;
super.setCallback(callback);
// @since 4.2.1
// wrap callback so invalidation happens to this AsyncDrawable instance
// and not for wrapped result/placeholder
this.callback = cb == null
? null
: new WrappedCallback(cb);

super.setCallback(cb);

// if not null -> means we are attached
if (callback != null) {
Expand Down Expand Up @@ -138,6 +161,7 @@ public void setCallback2(@Nullable Callback callback) {
/**
* @since 3.0.1
*/
@SuppressWarnings("WeakerAccess")
protected void setPlaceholderResult(@NonNull Drawable placeholder) {
// okay, if placeholder has bounds -> use it, otherwise use original imageSize

Expand Down Expand Up @@ -175,7 +199,6 @@ public void setResult(@NonNull Drawable result) {
}

this.result = result;
this.result.setCallback(callback);

initBounds();
}
Expand Down Expand Up @@ -210,6 +233,12 @@ private void initBounds() {

final Rect bounds = resolveBounds();
result.setBounds(bounds);
// @since 4.2.1, we set callback after bounds are resolved
// to reduce number of invalidations
result.setCallback(callback);

// so, this method will check if there is previous bounds and call invalidate _BEFORE_
// applying new bounds. This is why it is important to have initial bounds empty.
setBounds(bounds);

invalidateSelf();
Expand Down Expand Up @@ -291,6 +320,7 @@ private Rect resolveBounds() {
return imageSizeResolver.resolveImageSize(this);
}

@NonNull
@Override
public String toString() {
return "AsyncDrawable{" +
Expand All @@ -302,4 +332,30 @@ public String toString() {
", waitingForDimensions=" + waitingForDimensions +
'}';
}

// @since 4.2.1
// Wrapped callback to trigger invalidation for this AsyncDrawable instance (and not result/placeholder)
private class WrappedCallback implements Callback {

private final Callback callback;

WrappedCallback(@NonNull Callback callback) {
this.callback = callback;
}

@Override
public void invalidateDrawable(@NonNull Drawable who) {
callback.invalidateDrawable(AsyncDrawable.this);
}

@Override
public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
callback.scheduleDrawable(AsyncDrawable.this, what, when);
}

@Override
public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
callback.unscheduleDrawable(AsyncDrawable.this, what);
}
}
}
Loading

0 comments on commit c939c0f

Please sign in to comment.