Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.1.1 #60

Merged
merged 9 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allprojects {
and then in your module `build.gradle`:

```groovy
implementation 'ru.noties:markwon:1.1.0-SNAPSHOT'
implementation 'ru.noties:markwon:1.1.1-SNAPSHOT'
```

Please note that `markwon-image-loader`, `markwon-syntax` and `markwon-view` are also present in `SNAPSHOT` repository and share the same version as main `markwon` artifact.
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ task wrapper(type: Wrapper) {
distributionType 'all'
}

if (hasProperty('local')) {
if (!hasProperty('LOCAL_MAVEN_URL')) {
throw new RuntimeException('Cannot publish to local maven as no such property exists: LOCAL_MAVEN_URL')
}
ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL
ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL
}

ext {

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

VERSION_NAME=1.1.0
VERSION_NAME=1.1.1-SNAPSHOT

GROUP=ru.noties
POM_DESCRIPTION=Markwon
Expand Down
4 changes: 0 additions & 4 deletions library-image-loader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@ afterEvaluate {
}

if (hasProperty('release')) {
if (hasProperty('local')) {
ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL
ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL
}
apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle'
}
4 changes: 0 additions & 4 deletions library-syntax/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ afterEvaluate {
}

if (hasProperty('release')) {
if (hasProperty('local')) {
ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL
ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL
}
apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle'
}
4 changes: 0 additions & 4 deletions library-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ afterEvaluate {
}

if (hasProperty('release')) {
if (hasProperty('local')) {
ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL
ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL
}
apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle'
}
4 changes: 0 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ afterEvaluate {
}

if (hasProperty('release')) {
if (hasProperty('local')) {
ext.RELEASE_REPOSITORY_URL = LOCAL_MAVEN_URL
ext.SNAPSHOT_REPOSITORY_URL = LOCAL_MAVEN_URL
}
apply from: 'https://raw.githubusercontent.com/noties/gradle-mvn-push/master/gradle-mvn-push-aar.gradle'
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static Builder builder(@NonNull Context context) {
private final SpannableHtmlParser htmlParser;
private final ImageSizeResolver imageSizeResolver;
private final SpannableFactory factory; // @since 1.1.0
private final boolean softBreakAddsNewLine; // @since 1.1.1

private SpannableConfiguration(@NonNull Builder builder) {
this.theme = builder.theme;
Expand All @@ -42,6 +43,7 @@ private SpannableConfiguration(@NonNull Builder builder) {
this.htmlParser = builder.htmlParser;
this.imageSizeResolver = builder.imageSizeResolver;
this.factory = builder.factory;
this.softBreakAddsNewLine = builder.softBreakAddsNewLine;
}

@NonNull
Expand Down Expand Up @@ -84,6 +86,15 @@ public SpannableFactory factory() {
return factory;
}

/**
* @return a flag indicating if soft break should be treated as a hard
* break and thus adding a new line instead of adding a white space
* @since 1.1.1
*/
public boolean softBreakAddsNewLine() {
return softBreakAddsNewLine;
}

@SuppressWarnings("unused")
public static class Builder {

Expand All @@ -95,7 +106,8 @@ public static class Builder {
private UrlProcessor urlProcessor;
private SpannableHtmlParser htmlParser;
private ImageSizeResolver imageSizeResolver;
private SpannableFactory factory;
private SpannableFactory factory; // @since 1.1.0
private boolean softBreakAddsNewLine; // @since 1.1.1

Builder(@NonNull Context context) {
this.context = context;
Expand Down Expand Up @@ -155,6 +167,19 @@ public Builder factory(@NonNull SpannableFactory factory) {
return this;
}

/**
* @param softBreakAddsNewLine a flag indicating if soft break should be treated as a hard
* break and thus adding a new line instead of adding a white space
* @return self
* @see <a href="https://spec.commonmark.org/0.28/#soft-line-breaks">spec</a>
* @since 1.1.1
*/
@NonNull
public Builder softBreakAddsNewLine(boolean softBreakAddsNewLine) {
this.softBreakAddsNewLine = softBreakAddsNewLine;
return this;
}

@NonNull
public SpannableConfiguration build() {

Expand Down
6 changes: 6 additions & 0 deletions library/src/main/java/ru/noties/markwon/SpannableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Object tableRow(
boolean isHeader,
boolean isOdd);

/**
* @since 1.1.1
*/
@Nullable
Object paragraph(boolean inTightList);

@Nullable
Object image(
@NonNull SpannableTheme theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public Object tableRow(@NonNull SpannableTheme theme, @NonNull List<TableRowSpan
return new TableRowSpan(theme, cells, isHeader, isOdd);
}

/**
* @since 1.1.1
*/
@Nullable
@Override
public Object paragraph(boolean inTightList) {
return null;
}

@Nullable
@Override
public Object image(@NonNull SpannableTheme theme, @NonNull String destination, @NonNull AsyncDrawable.Loader loader, @NonNull ImageSizeResolver imageSizeResolver, @Nullable ImageSize imageSize, boolean replacementTextIsLink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ public void visit(Heading heading) {

@Override
public void visit(SoftLineBreak softLineBreak) {
// at first here was a new line, but here should be a space char
builder.append(' ');
// @since 1.1.1 there is an option to treat soft break as a hard break (thus adding new line)
if (configuration.softBreakAddsNewLine()) {
newLine();
} else {
builder.append(' ');
}
}

@Override
Expand Down Expand Up @@ -376,15 +380,18 @@ private boolean handleTableNodes(CustomNode node) {

@Override
public void visit(Paragraph paragraph) {

final boolean inTightList = isInTightList(paragraph);

if (!inTightList) {
newLine();
}

final int length = builder.length();
visitChildren(paragraph);

// @since 1.1.1 apply paragraph span
setSpan(length, factory.paragraph(inTightList));

if (!inTightList) {
newLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
abstract class CanvasUtils {

static float textCenterY(int top, int bottom, @NonNull Paint paint) {
return (int) (bottom - ((bottom - top) / 2) - ((paint.descent() + paint.ascent()) / 2.F + .5F));
// @since 1.1.1 it's `top +` and not `bottom -`
return (int) (top + ((bottom - top) / 2) - ((paint.descent() + paint.ascent()) / 2.F + .5F));
}

private CanvasUtils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int ba
left = x + (width * dir) + (width - numberWidth);
}

final float numberY = CanvasUtils.textCenterY(top, bottom, p);

c.drawText(number, left, numberY, p);
// @since 1.1.1 we are using `baseline` argument to position text
c.drawText(number, left, baseline, p);
}
}
47 changes: 47 additions & 0 deletions library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ private static int resolve(Context context, @AttrRes int attr) {
// by default paint.color * TABLE_ODD_ROW_DEF_ALPHA
protected final int tableOddRowBackgroundColor;

// @since 1.1.1
// by default no background
protected final int tableEventRowBackgroundColor;

// @since 1.1.1
// by default no background
protected final int tableHeaderRowBackgroundColor;

// drawable that will be used to render checkbox (should be stateful)
// TaskListDrawable can be used
protected final Drawable taskListDrawable;
Expand Down Expand Up @@ -236,6 +244,8 @@ protected SpannableTheme(@NonNull Builder builder) {
this.tableBorderColor = builder.tableBorderColor;
this.tableBorderWidth = builder.tableBorderWidth;
this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor;
this.tableEventRowBackgroundColor = builder.tableEvenRowBackgroundColor;
this.tableHeaderRowBackgroundColor = builder.tableHeaderRowBackgroundColor;
this.taskListDrawable = builder.taskListDrawable;
}

Expand Down Expand Up @@ -493,6 +503,23 @@ public void applyTableOddRowStyle(@NonNull Paint paint) {
paint.setStyle(Paint.Style.FILL);
}

/**
* @since 1.1.1
*/
public void applyTableEvenRowStyle(@NonNull Paint paint) {
// by default to background to even row
paint.setColor(tableEventRowBackgroundColor);
paint.setStyle(Paint.Style.FILL);
}

/**
* @since 1.1.1
*/
public void applyTableHeaderRowStyle(@NonNull Paint paint) {
paint.setColor(tableHeaderRowBackgroundColor);
paint.setStyle(Paint.Style.FILL);
}

/**
* @return a Drawable to be used as a checkbox indication in task lists
* @since 1.0.1
Expand Down Expand Up @@ -530,6 +557,8 @@ public static class Builder {
private int tableBorderColor;
private int tableBorderWidth = -1;
private int tableOddRowBackgroundColor;
private int tableEvenRowBackgroundColor; // @since 1.1.1
private int tableHeaderRowBackgroundColor; // @since 1.1.1
private Drawable taskListDrawable;

Builder() {
Expand Down Expand Up @@ -733,6 +762,24 @@ public Builder tableOddRowBackgroundColor(@ColorInt int tableOddRowBackgroundCol
return this;
}

/**
* @since 1.1.1
*/
@NonNull
public Builder tableEvenRowBackgroundColor(@ColorInt int tableEvenRowBackgroundColor) {
this.tableEvenRowBackgroundColor = tableEvenRowBackgroundColor;
return this;
}

/**
* @since 1.1.1
*/
@NonNull
public Builder tableHeaderRowBackgroundColor(int tableHeaderRowBackgroundColor) {
this.tableHeaderRowBackgroundColor = tableHeaderRowBackgroundColor;
return this;
}

/**
* Supplied Drawable must be stateful ({@link Drawable#isStateful()} returns true). If a task
* is marked as done, then this drawable will be updated with an {@code int[] { android.R.attr.state_checked }}
Expand Down
33 changes: 25 additions & 8 deletions library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,35 @@ public void draw(
// feels like magic...
final int heightDiff = (bottom - top - height) / 4;

if (odd) {
final int save = canvas.save();
try {
rect.set(0, 0, width, bottom - top);
// @since 1.1.1
// draw backgrounds
{
if (header) {
theme.applyTableHeaderRowStyle(this.paint);
} else if (odd) {
theme.applyTableOddRowStyle(this.paint);
canvas.translate(x, top - heightDiff);
canvas.drawRect(rect, this.paint);
} finally {
canvas.restoreToCount(save);
} else {
// even
theme.applyTableEvenRowStyle(this.paint);
}

// if present (0 is transparent)
if (this.paint.getColor() != 0) {
final int save = canvas.save();
try {
rect.set(0, 0, width, bottom - top);
canvas.translate(x, top - heightDiff);
canvas.drawRect(rect, this.paint);
} finally {
canvas.restoreToCount(save);
}
}
}

// @since 1.1.1 reset after applying background color
// as background changes color attribute and if not specific tableBorderColor
// is specified then after this row all borders will have color of this row (plus alpha)
this.paint.set(paint);
theme.applyTableBorderStyle(this.paint);

final int borderWidth = theme.tableBorderWidth(paint);
Expand Down