크리에이터 커뮤니티

- 링크 적용
This commit is contained in:
klaus 2024-01-15 23:36:02 +09:00
parent 82cf1658cb
commit 2dac54b3ec
1 changed files with 32 additions and 1 deletions

View File

@ -2,9 +2,16 @@ package kr.co.vividnext.sodalive.explorer.profile.creator_community.all
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context 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.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import coil.load 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.databinding.ItemCreatorCommunityAllBinding
import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse
import kr.co.vividnext.sodalive.extensions.loadUrl import kr.co.vividnext.sodalive.extensions.loadUrl
import java.util.regex.Pattern
class CreatorCommunityAllAdapter( class CreatorCommunityAllAdapter(
private val onClickLike: (Long) -> Unit, private val onClickLike: (Long) -> Unit,
@ -40,7 +48,7 @@ class CreatorCommunityAllAdapter(
transformations(CircleCropTransformation()) transformations(CircleCropTransformation())
} }
binding.tvContent.text = item.content setNoticeAndClickableUrl(binding.tvContent, item.content)
binding.tvContent.setOnClickListener { binding.tvContent.setOnClickListener {
items[index] = items[index].copy( items[index] = items[index].copy(
isExpand = !item.isExpand, isExpand = !item.isExpand,
@ -129,6 +137,29 @@ class CreatorCommunityAllAdapter(
binding.llComment.setOnClickListener {} 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( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(