From 2dac54b3ec3efd76f371db73388a78f05fb2477b Mon Sep 17 00:00:00 2001 From: klaus Date: Mon, 15 Jan 2024 23:36:02 +0900 Subject: [PATCH] =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20-=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../all/CreatorCommunityAllAdapter.kt | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt index 3410034..e12172b 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt @@ -2,9 +2,16 @@ package kr.co.vividnext.sodalive.explorer.profile.creator_community.all import android.annotation.SuppressLint import android.content.Context +import android.content.Intent +import android.net.Uri +import android.text.Spannable +import android.text.SpannableString +import android.text.method.LinkMovementMethod +import android.text.style.ClickableSpan import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView import androidx.appcompat.widget.PopupMenu import androidx.recyclerview.widget.RecyclerView import coil.load @@ -14,6 +21,7 @@ import kr.co.vividnext.sodalive.common.SharedPreferenceManager import kr.co.vividnext.sodalive.databinding.ItemCreatorCommunityAllBinding import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse import kr.co.vividnext.sodalive.extensions.loadUrl +import java.util.regex.Pattern class CreatorCommunityAllAdapter( private val onClickLike: (Long) -> Unit, @@ -40,7 +48,7 @@ class CreatorCommunityAllAdapter( transformations(CircleCropTransformation()) } - binding.tvContent.text = item.content + setNoticeAndClickableUrl(binding.tvContent, item.content) binding.tvContent.setOnClickListener { items[index] = items[index].copy( isExpand = !item.isExpand, @@ -129,6 +137,29 @@ class CreatorCommunityAllAdapter( binding.llComment.setOnClickListener {} } } + + private fun setNoticeAndClickableUrl(textView: TextView, text: String) { + textView.text = text + + val spannable = SpannableString(text) + val pattern = Pattern.compile("https?://\\S+") + val matcher = pattern.matcher(spannable) + + while (matcher.find()) { + val start = matcher.start() + val end = matcher.end() + val clickableSpan = object : ClickableSpan() { + override fun onClick(widget: View) { + val url = spannable.subSequence(start, end).toString() + context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + } + } + spannable.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + textView.text = spannable + textView.movementMethod = LinkMovementMethod.getInstance() + } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(