fix(community): 전체 아이템 말줄임과 폰트를 정렬한다
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.TextUtils
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.text.style.ClickableSpan
|
||||
import android.view.LayoutInflater
|
||||
@@ -46,6 +47,10 @@ class CreatorCommunityAllAdapter(
|
||||
(Long, Int, onSuccess: (GetCommunityPostListResponse) -> Unit) -> Unit
|
||||
) : RecyclerView.Adapter<CreatorCommunityAllAdapter.ViewHolder>() {
|
||||
|
||||
companion object {
|
||||
private const val CONTENT_PREVIEW_MAX_LENGTH = 120
|
||||
}
|
||||
|
||||
val items = mutableListOf<GetCommunityPostListResponse>()
|
||||
|
||||
inner class ViewHolder(
|
||||
@@ -257,26 +262,42 @@ class CreatorCommunityAllAdapter(
|
||||
index: Int
|
||||
) {
|
||||
textView.visibility = View.VISIBLE
|
||||
textView.text = text
|
||||
|
||||
val spannable = SpannableString(text)
|
||||
val pattern = Pattern.compile("https?://\\S+")
|
||||
val matcher = pattern.matcher(spannable)
|
||||
if (isExpand) {
|
||||
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)))
|
||||
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)
|
||||
}
|
||||
spannable.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
|
||||
textView.text = spannable
|
||||
textView.movementMethod = LinkMovementMethod.getInstance()
|
||||
textView.maxLines = Int.MAX_VALUE
|
||||
textView.ellipsize = null
|
||||
textView.linksClickable = true
|
||||
textView.movementMethod = LinkMovementMethod.getInstance()
|
||||
textView.text = spannable
|
||||
} else {
|
||||
val collapsedText = if (text.length > CONTENT_PREVIEW_MAX_LENGTH) {
|
||||
"${text.take(CONTENT_PREVIEW_MAX_LENGTH)}..."
|
||||
} else {
|
||||
text
|
||||
}
|
||||
|
||||
textView.maxLines = 3
|
||||
textView.ellipsize = TextUtils.TruncateAt.END
|
||||
textView.linksClickable = false
|
||||
textView.movementMethod = null
|
||||
textView.text = collapsedText
|
||||
}
|
||||
|
||||
textView.setOnClickListener {
|
||||
items[index] = items[index].copy(
|
||||
@@ -284,12 +305,6 @@ class CreatorCommunityAllAdapter(
|
||||
)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
textView.maxLines = if (isExpand) {
|
||||
Int.MAX_VALUE
|
||||
} else {
|
||||
3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user