Skip to content

Commit

Permalink
Merge branch 'develop' into issue/218-uploading-images
Browse files Browse the repository at this point in the history
  • Loading branch information
hypest committed Feb 7, 2017
2 parents 5f4e56b + cde2466 commit cec412f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,30 @@ class LineBlockFormatter(editor: AztecText, val headerStyle: LineBlockFormatter.
val span = AztecMediaSpan(editor.context, drawable, attributes, onMediaTappedListener)
val html = span.getHtml();

val mediaStartIndex = selectionStart
val mediaEndIndex = selectionStart + html.length
val isAddingMediaToEndOfBlockElement = editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java)
.any {
selectionStart == editableText.getSpanEnd(it)
}

val spanAtStartOfWhichMediaIsAdded = editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java)
.firstOrNull {
selectionStart == editableText.getSpanStart(it)
}

val modifier = if (isAddingMediaToEndOfBlockElement) 1 else 0

val mediaStartIndex = selectionStart - modifier
val mediaEndIndex = selectionStart + html.length - modifier

if (!isAddingMediaToEndOfBlockElement)
editor.disableTextChangedListener()

editor.disableTextChangedListener()
editableText.replace(selectionStart, selectionEnd, html)

editor.removeBlockStylesFromRange(mediaStartIndex, mediaEndIndex, true)
editor.removeHeadingStylesFromRange(mediaStartIndex, mediaEndIndex)
if (spanAtStartOfWhichMediaIsAdded != null) {
editableText.setSpan(spanAtStartOfWhichMediaIsAdded, mediaStartIndex, editableText.getSpanEnd(spanAtStartOfWhichMediaIsAdded), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}

editor.removeInlineStylesFromRange(mediaStartIndex, mediaEndIndex)

editableText.setSpan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class AztecListSpan(val verticalPadding: Int) : LeadingMarginSpan.Stand
val currentLineNumber = getIndexOfProcessedLine(text, end)

if (totalNumberOfLinesInList > 1 && currentLineNumber == 1) {
adjustment = if (this is AztecOrderedListSpan) 0 else verticalPadding
adjustment = 0
} else if ((totalNumberOfLinesInList > 1 && totalNumberOfLinesInList == currentLineNumber) || totalNumberOfLinesInList == 1) {
adjustment = -verticalPadding
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.wordpress.aztec.spans

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.text.Layout
import android.text.Spanned
import android.text.TextUtils
Expand Down Expand Up @@ -64,7 +63,6 @@ class AztecUnorderedListSpan : AztecListSpan {
}



override fun getLeadingMargin(first: Boolean): Int {
return bulletMargin + 2 * bulletWidth + bulletPadding
}
Expand All @@ -86,24 +84,14 @@ class AztecUnorderedListSpan : AztecListSpan {
p.color = bulletColor
p.style = Paint.Style.FILL

if (c.isHardwareAccelerated) {
bulletPath = Path()
bulletPath!!.addCircle(0.0f, 0.0f + getIndicatorAdjustment(text, end) / 2, bulletWidth.toFloat(), Path.Direction.CW)
val textToDraw = "\u2022"

c.save()
c.translate((x + bulletMargin + dir * bulletWidth).toFloat(), ((top + bottom) / 2.0f))
c.drawPath(bulletPath!!, p)
c.restore()
} else {
c.drawCircle((x + bulletMargin + dir * bulletWidth).toFloat(), ((top + bottom) / 2.0f) + getIndicatorAdjustment(text, end) / 2, bulletWidth.toFloat(), p)
}
val width = p.measureText(textToDraw)
c.drawText(textToDraw, (bulletMargin + x + dir - width) * dir, (bottom - p.descent()) - width / 2 + getIndicatorAdjustment(text, end), p)

p.color = oldColor
p.style = style

}

companion object {
private var bulletPath: Path? = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,11 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
}
}

fun enableFormatButtons(isEnabled: Boolean) {
ToolbarAction.values().forEach { action ->
if (action != ToolbarAction.HTML) {
toggleButtonState(findViewById(action.buttonId), isEnabled)
}
}
}
}

0 comments on commit cec412f

Please sign in to comment.