Skip to content

Commit

Permalink
updated content text view
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed May 22, 2017
1 parent b89d3c1 commit a383fb5
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}

}
Expand Down

0 comments on commit a383fb5

Please sign in to comment.