From a383fb5e47edbeecc9aef1650319556da4c2fb8a Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 22 May 2017 20:09:53 +0800 Subject: [PATCH] updated content text view --- .../twidere/view/TimelineContentTextView.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt index 01cb6384d..bee87f44f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt @@ -29,6 +29,7 @@ import android.view.MotionEvent import android.widget.TextView import org.mariotaku.chameleon.view.ChameleonTextView import org.mariotaku.twidere.extension.setupEmojiFactory +import java.lang.ref.WeakReference /** * Returns true when not clicking links @@ -85,11 +86,9 @@ class TimelineContentTextView( } internal class InternalMovementMethod : BaseMovementMethod() { - private var targetSpan: ClickableSpan? = null + private var targetSpan: WeakReference? = null - override fun initialize(widget: TextView, text: Spannable) { - - } + override fun canSelectArbitrarily() = true override fun onTouchEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean { when (event.actionMasked) { @@ -100,22 +99,22 @@ class TimelineContentTextView( val line = layout.getLineForVertical(Math.round(y)) val offset = layout.getOffsetForHorizontal(line, x) if (x <= layout.getLineWidth(line)) { - targetSpan = text.getSpans(offset, offset, ClickableSpan::class.java).firstOrNull() + targetSpan = WeakReference(text.getSpans(offset, offset, ClickableSpan::class.java).firstOrNull()) } else { targetSpan = null } } MotionEvent.ACTION_UP -> { - targetSpan?.onClick(widget) - val handled = targetSpan != null + val span = targetSpan?.get() ?: return false + span.onClick(widget) targetSpan = null - return handled + return true } MotionEvent.ACTION_CANCEL -> { targetSpan = null } } - return targetSpan != null + return targetSpan?.get() != null } }