Skip to content
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
24 changes: 24 additions & 0 deletions app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import org.wordpress.aztec.plugins.wpcomments.toolbar.PageToolbarButton
import org.wordpress.aztec.source.SourceViewEditText
import org.wordpress.aztec.toolbar.AztecToolbar
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
import org.wordpress.aztec.toolbar.ToolbarAction
import org.wordpress.aztec.toolbar.ToolbarItems
import org.wordpress.aztec.util.AztecLog
import org.xml.sax.Attributes
import java.io.File
Expand Down Expand Up @@ -459,6 +461,28 @@ open class MainActivity : AppCompatActivity(),
}
})

toolbar.enableTaskList()

toolbar.setToolbarItems(
ToolbarItems.BasicLayout(
ToolbarAction.HEADING,
ToolbarAction.LIST,
ToolbarAction.INDENT,
ToolbarAction.OUTDENT,
ToolbarAction.QUOTE,
ToolbarAction.BOLD,
ToolbarAction.ITALIC,
ToolbarAction.LINK,
ToolbarAction.UNDERLINE,
ToolbarAction.STRIKETHROUGH,
ToolbarAction.ALIGN_LEFT,
ToolbarAction.ALIGN_CENTER,
ToolbarAction.ALIGN_RIGHT,
ToolbarAction.HORIZONTAL_RULE,
ToolbarItems.PLUGINS,
ToolbarAction.HTML
))

aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
.setImageGetter(GlideImageLoader(this))
.setVideoThumbnailGetter(GlideVideoThumbnailLoader(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.wordpress.aztec.spans.AztecListItemSpan
import org.wordpress.aztec.spans.AztecListSpan
import org.wordpress.aztec.spans.AztecOrderedListSpan
import org.wordpress.aztec.spans.AztecOrderedListSpanAligned
import org.wordpress.aztec.spans.AztecTaskListSpan
import org.wordpress.aztec.spans.AztecTaskListSpanAligned
import org.wordpress.aztec.spans.AztecUnorderedListSpan
import org.wordpress.aztec.spans.AztecUnorderedListSpanAligned
import org.wordpress.aztec.spans.IAztecBlockSpan
Expand Down Expand Up @@ -96,6 +98,14 @@ class ListFormatter(editor: AztecText) : AztecFormatter(editor) {
is AztecOrderedListSpan -> AztecOrderedListSpan(updatedNestingLevel, attributes, listStyle)
is AztecUnorderedListSpanAligned -> AztecUnorderedListSpanAligned(updatedNestingLevel, attributes, listStyle, alignment)
is AztecUnorderedListSpan -> AztecUnorderedListSpan(updatedNestingLevel, attributes, listStyle)
is AztecTaskListSpanAligned -> {
val context = getContext() ?: return null
AztecTaskListSpanAligned(updatedNestingLevel, attributes, context, listStyle, alignment)
}
is AztecTaskListSpan -> {
val context = getContext() ?: return null
AztecTaskListSpan(updatedNestingLevel, attributes, context, listStyle)
}
else -> null
}
}
Expand Down
20 changes: 17 additions & 3 deletions aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ abstract class AztecListSpan(override var nestingLevel: Int,
val listText = text.subSequence(spanStart, spanEnd) as Spanned

if (end - spanStart - 1 >= 0 && end - spanStart <= listText.length) {
val hasSublist = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
.any { it.nestingLevel > nestingLevel }
if (hasSublist) {
// When outdenting an empty list item, a nested list span may begin at the
// exact start of this line due to span boundary updates. That should not
// suppress the indicator for the current line. Ignore sublists whose start
// coincides with the current line start.
val potentialSublists = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
val hasBlockingSublist = potentialSublists.any { sub ->
if (sub.nestingLevel <= nestingLevel) return@any false
val subStart = listText.getSpanStart(sub)
val lineStart = (listText.subSequence(0, end - spanStart) as Spanned)
.lastIndexOf('\n') + 1
// Only treat as blocking if the nested list actually starts after the line start
// (i.e., the next line belongs to a deeper list). If it starts exactly at the
// line start, we are at the first character of that nested block, which should
// still show the current line indicator.
subStart > lineStart
}
if (hasBlockingSublist) {
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ open class AztecTaskListSpan(
) : AztecListSpan(nestingLevel, listStyle.verticalPadding) {
private var toggled: Boolean = false
private var contextRef: WeakReference<Context> = WeakReference(context)

internal fun getContext(): Context? = contextRef.get()
override val TAG = "ul"

override val startTag: String
Expand Down
25 changes: 24 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ allprojects {
}
tasks.withType(KotlinCompile).all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
allWarningsAsErrors = true
}
}
Expand All @@ -43,6 +42,30 @@ task clean(type: Delete) {
}

subprojects {
plugins.withId("com.android.application") {
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
plugins.withId("com.android.library") {
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
plugins.withId("org.jetbrains.kotlin.android") {
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}
}

configurations {
ktlint
}
Expand Down