handle link clicks properly

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-10-01 12:56:43 +02:00
parent 9f6c6b010c
commit 0c9f01ba29
No known key found for this signature in database
GPG key ID: F7AA2A8B65B50220
3 changed files with 29 additions and 2 deletions

View file

@ -9,7 +9,12 @@ package com.nextcloud.talk.adapters.messages
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
import android.text.style.UnderlineSpan
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
@ -92,6 +97,16 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) :
binding.messageText.text = processedMessageText
val link = SpannableString(processedMessageText)
link.setSpan(UnderlineSpan(), 0, link.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
binding.messageText.text = link
binding.messageText.setOnClickListener {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(processedMessageText.toString()))
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(browserIntent)
}
setAvatarAndAuthorOnMessageItem(message)
colorizeMessageBubble(message)

View file

@ -9,6 +9,11 @@ package com.nextcloud.talk.adapters.messages
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.text.SpannableString
import android.text.Spanned
import android.text.style.UnderlineSpan
import android.util.Log
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
@ -84,7 +89,15 @@ class OutcomingLinkPreviewMessageViewHolder(outcomingView: View, payload: Any) :
itemView
)
binding.messageText.text = processedMessageText
val link = SpannableString(processedMessageText)
link.setSpan(UnderlineSpan(), 0, link.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
binding.messageText.text = link
binding.messageText.setOnClickListener {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(processedMessageText.toString()))
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(browserIntent)
}
itemView.isSelected = false

View file

@ -154,7 +154,6 @@
app:outcomingTextLinkColor="@color/high_emphasis_text"
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:textAutoLink="all"
tools:visibility="visible" />
<com.nextcloud.ui.popupbubble.PopupBubble