From 0c9f01ba2957a17c6152c2bab03cea518343baad Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 1 Oct 2024 12:56:43 +0200 Subject: [PATCH] handle link clicks properly Signed-off-by: sowjanyakch --- .../IncomingLinkPreviewMessageViewHolder.kt | 15 +++++++++++++++ .../OutcomingLinkPreviewMessageViewHolder.kt | 15 ++++++++++++++- app/src/main/res/layout/activity_chat.xml | 1 - 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt index 0657113f70..829d40f397 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt @@ -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) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt index e557a98cba..b93c77ba39 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt @@ -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 diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index b73e404d93..0c130f8e8f 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -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" />