updated content text view

This commit is contained in:
Mariotaku Lee 2017-05-22 20:09:53 +08:00
parent b89d3c198e
commit a383fb5e47
No known key found for this signature in database
GPG Key ID: 99505AEA531814F1
1 changed files with 8 additions and 9 deletions

View File

@ -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<ClickableSpan?>? = 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
}
}