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(