From 8f5b6c3fa3c983dc27b295df88a1db6ec1b38e12 Mon Sep 17 00:00:00 2001 From: khaykov Date: Thu, 18 Jul 2024 15:02:11 -0500 Subject: [PATCH] Revert change to task click handler, since it's not leaking. --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 3 +-- .../kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index e8c9eb5da..0693fd306 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -542,7 +542,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown exclusiveBlockStyles = BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false), verticalParagraphPadding), paragraphStyle = BlockFormatter.ParagraphStyle(verticalParagraphMargin) ) - EnhancedMovementMethod.setTaskListClickHandler(TaskListClickHandler(listStyle)) + EnhancedMovementMethod.taskListClickHandler = TaskListClickHandler(listStyle) linkFormatter = LinkFormatter(this, LinkFormatter.LinkStyle(styles.getColor( R.styleable.AztecText_linkColor, 0), @@ -955,7 +955,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown blockEditorDialog!!.dismiss() } EnhancedMovementMethod.setLinkTappedListener(null) - EnhancedMovementMethod.setTaskListClickHandler(null) } // We are exposing this method in order to allow subclasses to set their own alpha value diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt b/aztec/src/main/kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt index dd04a899c..523d8e072 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt @@ -15,13 +15,10 @@ import java.lang.ref.WeakReference * http://stackoverflow.com/a/23566268/569430 */ object EnhancedMovementMethod : ArrowKeyMovementMethod() { - private var taskListClickHandlerRef: WeakReference = WeakReference(null) + var taskListClickHandler: TaskListClickHandler? = null private var linkTappedListenerRef: WeakReference = WeakReference(null) var isLinkTapEnabled = false - fun setTaskListClickHandler(handler: TaskListClickHandler?) { - taskListClickHandlerRef = WeakReference(handler) - } fun setLinkTappedListener(listener: AztecText.OnLinkTappedListener?) { linkTappedListenerRef = WeakReference(listener) @@ -47,7 +44,7 @@ object EnhancedMovementMethod : ArrowKeyMovementMethod() { val off = layout.getOffsetForHorizontal(line, x.toFloat()) // This handles the case when the task list checkbox is clicked - if (taskListClickHandlerRef.get()?.handleTaskListClick(text, off, x, widget.totalPaddingStart) == true) { + if (taskListClickHandler?.handleTaskListClick(text, off, x, widget.totalPaddingStart) == true) { return true }