diff --git a/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt b/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt index 4a5769fbb..101dbf76d 100644 --- a/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt +++ b/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt @@ -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 @@ -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)) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/ListFormatter.kt b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/ListFormatter.kt index 100e55d52..c2517f852 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/ListFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/ListFormatter.kt @@ -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 @@ -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 } } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt index 925a3ad6d..c05dba508 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt @@ -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 } } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecTaskListSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecTaskListSpan.kt index b359fba5c..3cbae340a 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecTaskListSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecTaskListSpan.kt @@ -68,6 +68,8 @@ open class AztecTaskListSpan( ) : AztecListSpan(nestingLevel, listStyle.verticalPadding) { private var toggled: Boolean = false private var contextRef: WeakReference = WeakReference(context) + + internal fun getContext(): Context? = contextRef.get() override val TAG = "ul" override val startTag: String diff --git a/build.gradle b/build.gradle index 79057a732..878b2e1c2 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,6 @@ allprojects { } tasks.withType(KotlinCompile).all { kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 allWarningsAsErrors = true } } @@ -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 }