feat(home): 팔로잉 소식 카드를 추가한다

This commit is contained in:
2026-06-25 23:34:11 +09:00
parent ccd2398a7c
commit f009a2edb8
3 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
package kr.co.vividnext.sodalive.v2.main.home.ui
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.extensions.loadUrl
import kr.co.vividnext.sodalive.v2.main.home.model.HomeFollowingNewsUiItem
class HomeFollowingNewsAdapter(
private val onClickItem: (HomeFollowingNewsUiItem) -> Unit = {}
) : RecyclerView.Adapter<HomeFollowingNewsAdapter.NewsViewHolder>() {
private var items: List<HomeFollowingNewsUiItem> = emptyList()
fun submitItems(items: List<HomeFollowingNewsUiItem>) {
this.items = items
notifyDataSetChanged()
}
override fun getItemViewType(position: Int): Int = when (items[position]) {
is HomeFollowingNewsUiItem.Ranking -> VIEW_TYPE_RANKING
is HomeFollowingNewsUiItem.Content -> VIEW_TYPE_CONTENT
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewsViewHolder {
val layoutResId = if (viewType == VIEW_TYPE_RANKING) {
R.layout.item_home_following_news_rank
} else {
R.layout.item_home_following_news_content
}
val view = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false)
view.layoutParams = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
).apply { bottomMargin = parent.resources.getDimensionPixelSize(R.dimen.spacing_8) }
return if (viewType == VIEW_TYPE_RANKING) {
RankingViewHolder(view, onClickItem)
} else {
ContentViewHolder(view, onClickItem)
}
}
override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
holder.bind(items[position])
}
override fun getItemCount(): Int = items.size
sealed class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(item: HomeFollowingNewsUiItem)
}
class RankingViewHolder(
itemView: View,
private val onClickItem: (HomeFollowingNewsUiItem) -> Unit
) : NewsViewHolder(itemView) {
private val rankText = itemView.findViewById<TextView>(R.id.tv_home_following_news_rank)
private val titleText = itemView.findViewById<TextView>(R.id.tv_home_following_news_rank_title)
private val countText = itemView.findViewById<TextView>(R.id.tv_home_following_news_rank_count)
override fun bind(item: HomeFollowingNewsUiItem) {
val ranking = item as HomeFollowingNewsUiItem.Ranking
rankText.text = ranking.rank.toString()
titleText.text = ranking.title
countText.text = ranking.body
itemView.setOnClickListener { onClickItem(ranking) }
}
}
class ContentViewHolder(
itemView: View,
private val onClickItem: (HomeFollowingNewsUiItem) -> Unit
) : NewsViewHolder(itemView) {
private val profileImage = itemView.findViewById<ImageView>(R.id.iv_home_following_news_creator_profile)
private val nicknameText = itemView.findViewById<TextView>(R.id.tv_home_following_news_creator_nickname)
private val createdAtText = itemView.findViewById<TextView>(R.id.tv_home_following_news_created_at)
private val labelText = itemView.findViewById<TextView>(R.id.tv_home_following_news_label)
private val titleText = itemView.findViewById<TextView>(R.id.tv_home_following_news_title)
private val contentText = itemView.findViewById<TextView>(R.id.tv_home_following_news_content)
private val thumbnailImage = itemView.findViewById<ImageView>(R.id.iv_home_following_news_thumbnail)
override fun bind(item: HomeFollowingNewsUiItem) {
val content = item as HomeFollowingNewsUiItem.Content
profileImage.loadHomeCreatorProfileImage(content.creatorProfileImageUrl)
nicknameText.text = content.creatorNickname
createdAtText.text = content.visibleFromText
labelText.setText(content.labelResId)
titleText.text = content.title
contentText.text = content.body
thumbnailImage.isVisible = !content.thumbnailImageUrl.isNullOrBlank()
content.thumbnailImageUrl?.let(thumbnailImage::loadUrl)
itemView.setOnClickListener { onClickItem(content) }
}
}
companion object {
private const val VIEW_TYPE_RANKING = 0
private const val VIEW_TYPE_CONTENT = 1
}
}

View File

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_feed_card"
android:orientation="vertical"
android:padding="@dimen/spacing_14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_home_following_news_creator_profile"
android:layout_width="42dp"
android:layout_height="42dp"
android:background="@drawable/bg_round_corner_999_263238"
android:contentDescription="@null"
android:scaleType="centerCrop"
tools:src="@drawable/ic_placeholder_profile" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_8"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tv_home_following_news_creator_nickname"
style="@style/Typography.Body5"
android:layout_width="match_parent"
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_home_following_news_created_at"
style="@style/Typography.Body6"
android:layout_width="match_parent"
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_home_following_news_title"
style="@style/Typography.Heading4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_14"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/white"
tools:text="콘텐츠 이름" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_8"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_home_following_news_label"
style="@style/Typography.Caption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_feed_category_tag"
android:includeFontPadding="false"
android:paddingHorizontal="@dimen/spacing_4"
android:paddingVertical="2dp"
android:textColor="@color/gray_100"
tools:text="오디오" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_12"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_home_following_news_content"
style="@style/Typography.Body3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="4"
android:textColor="@color/white"
tools:text="크리에이터가 남긴 최근 소식이 노출됩니다. 긴 내용은 말줄임 처리합니다." />
<ImageView
android:id="@+id/iv_home_following_news_thumbnail"
android:layout_width="92dp"
android:layout_height="92dp"
android:layout_marginStart="@dimen/spacing_8"
android:background="@drawable/bg_feed_community_image"
android:contentDescription="@null"
android:scaleType="centerCrop"
tools:src="@drawable/ic_launcher_background" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingVertical="@dimen/spacing_8">
<TextView
android:id="@+id/tv_home_following_news_rank"
style="@style/Typography.Heading3"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:textColor="@color/green_400"
tools:text="1" />
<TextView
android:id="@+id/tv_home_following_news_rank_title"
style="@style/Typography.Body4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_8"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/white"
tools:text="최근 소식 제목" />
<TextView
android:id="@+id/tv_home_following_news_rank_count"
style="@style/Typography.Body6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_8"
android:includeFontPadding="false"
android:textColor="@color/gray_500"
tools:text="999" />
</LinearLayout>