Comments added to explain why we should check if the url is valid.

This commit is contained in:
onurays 2020-04-27 13:44:16 +03:00
parent 6c4e71d7d4
commit 626eb4d06b

View file

@ -60,6 +60,7 @@ fun CharSequence.linkify(callback: TimelineEventController.UrlClickCallback?): C
fun createLinkMovementMethod(urlClickCallback: TimelineEventController.UrlClickCallback?): EvenBetterLinkMovementMethod {
return EvenBetterLinkMovementMethod(object : EvenBetterLinkMovementMethod.OnLinkClickListener {
override fun onLinkClicked(textView: TextView, span: ClickableSpan, url: String, actualText: String): Boolean {
// Always return false if the url is not valid, so the EvenBetterLinkMovementMethod can fallback to default click listener.
return url.isValidUrl() && urlClickCallback?.onUrlClicked(url, actualText) == true
}
})
@ -67,6 +68,7 @@ fun createLinkMovementMethod(urlClickCallback: TimelineEventController.UrlClickC
// We need also to fix the case when long click on link will trigger long click on cell
setOnLinkLongClickListener { tv, url ->
// Long clicks are handled by parent, return true to block android to do something with url
// Always return false if the url is not valid, so the EvenBetterLinkMovementMethod can fallback to default click listener.
if (url.isValidUrl() && urlClickCallback?.onUrlLongClicked(url) == true) {
tv.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0))
true