feat(feed): 커뮤니티 피드 뷰를 추가한다

This commit is contained in:
2026-05-21 15:53:40 +09:00
parent 77eef9609a
commit 59ea5de00a
2 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
package kr.co.vividnext.sodalive.v2.widget.feed
import android.content.Context
import android.graphics.Outline
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.view.ViewOutlineProvider
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import kr.co.vividnext.sodalive.R
import kotlin.math.roundToInt
class FeedCommunityView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
private var profileImage: ImageView? = null
private var creatorText: TextView? = null
private var createdAtText: TextView? = null
private var bodyText: TextView? = null
private var keywordText: TextView? = null
private var commentCountText: TextView? = null
private var likeCountText: TextView? = null
private var currentItem: FeedItem.Community? = null
private var clickListener: ((FeedItem) -> Unit)? = null
private var hideEmptyTextRows: Boolean = false
override fun onFinishInflate() {
super.onFinishInflate()
profileImage = findViewById(R.id.iv_feed_community_profile)
creatorText = findViewById(R.id.tv_feed_community_creator)
createdAtText = findViewById(R.id.tv_feed_community_created_at)
bodyText = findViewById(R.id.tv_feed_community_body)
keywordText = findViewById(R.id.tv_feed_community_keyword)
commentCountText = findViewById(R.id.tv_feed_community_comment_count)
likeCountText = findViewById(R.id.tv_feed_community_like_count)
profileImageView().clipToOutline = true
profileImageView().outlineProvider = circleOutlineProvider()
}
fun bind(item: FeedItem.Community) {
currentItem = item
requireNotNull(creatorText).text = item.creatorName
requireNotNull(createdAtText).text = item.createdAtText
requireNotNull(bodyText).text = item.bodyText
requireNotNull(keywordText).text = item.keywordText
requireNotNull(bodyText).visibility = visibilityForText(item.bodyText)
requireNotNull(keywordText).visibility = visibilityForText(item.keywordText)
requireNotNull(commentCountText).text = item.commentCount.toString()
requireNotNull(likeCountText).text = item.likeCount.toString()
applyClickState(item)
}
fun profileImageView(): ImageView = requireNotNull(profileImage)
fun setFeedSize(size: FeedSize) {
updateRootWidth(size.rootWidthDp.dpToPx())
}
fun setOnFeedClick(listener: ((FeedItem) -> Unit)?) {
clickListener = listener
currentItem?.let(::applyClickState)
}
fun setHideEmptyTextRows(hide: Boolean) {
hideEmptyTextRows = hide
currentItem?.let(::bind)
}
private fun visibilityForText(text: String): Int =
if (hideEmptyTextRows && text.isEmpty()) View.GONE else View.VISIBLE
private fun applyClickState(item: FeedItem.Community) {
val listener = clickListener
setOnClickListener(if (listener == null) null else View.OnClickListener { listener(item) })
isClickable = listener != null
}
private fun updateRootWidth(width: Int) {
val currentLayoutParams = layoutParams
layoutParams = if (currentLayoutParams == null) {
ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)
} else {
currentLayoutParams.apply { this.width = width }
}
}
private fun circleOutlineProvider() = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setOval(0, 0, view.width, view.height)
}
}
private fun Int.dpToPx(): Int = (this * resources.displayMetrics.density).roundToInt()
}

View File

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<kr.co.vividnext.sodalive.v2.widget.feed.FeedCommunityView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="374dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_feed_card"
android:clipToOutline="true"
android:orientation="vertical"
android:padding="@dimen/spacing_14">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="42dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_feed_community_profile"
android:layout_width="42dp"
android:layout_height="42dp"
android:contentDescription="@string/a11y_feed_profile_image"
android:scaleType="centerCrop"
tools:src="@drawable/ic_launcher_background" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_8"
android:orientation="vertical">
<TextView
android:id="@+id/tv_feed_community_creator"
style="@style/Typography.Body5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/white"
tools:text="크리에이터 이름" />
<TextView
android:id="@+id/tv_feed_community_created_at"
style="@style/Typography.Body6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/gray_500"
tools:text="2분 전" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_feed_community_body"
style="@style/Typography.Body3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_14"
android:includeFontPadding="false"
android:textColor="@color/white"
tools:text="크리에이터가 커뮤니티에 올린 글이 보이는 부분" />
<TextView
android:id="@+id/tv_feed_community_keyword"
style="@style/Typography.Body3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_4"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/soda_400"
tools:text="#키워드 #키워드 #키워드" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginTop="@dimen/spacing_14"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:contentDescription="@null"
android:src="@drawable/ic_feed_community_reply" />
<TextView
android:id="@+id/tv_feed_community_comment_count"
style="@style/Typography.Body3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_4"
android:includeFontPadding="false"
android:textColor="@color/gray_500"
tools:text="5" />
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="15dp"
android:contentDescription="@null"
android:src="@drawable/ic_feed_community_heart" />
<TextView
android:id="@+id/tv_feed_community_like_count"
style="@style/Typography.Body3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_4"
android:includeFontPadding="false"
android:textColor="@color/gray_500"
tools:text="6" />
</LinearLayout>
</kr.co.vividnext.sodalive.v2.widget.feed.FeedCommunityView>