feat(home): 인기 커뮤니티 adapter를 추가한다
This commit is contained in:
@@ -112,7 +112,12 @@ fun HomePopularCommunityPostItem.toUiModel(): HomeRecommendationPopularCommunity
|
||||
keywordText = "",
|
||||
createdAtText = createdAt,
|
||||
commentCount = commentCount.toInt(),
|
||||
likeCount = likeCount.toInt()
|
||||
likeCount = likeCount.toInt(),
|
||||
imageUrl = imageUrl,
|
||||
audioUrl = audioUrl,
|
||||
price = price,
|
||||
existOrdered = existOrdered,
|
||||
showKeyword = false
|
||||
),
|
||||
paidStatus = toPaidStatus()
|
||||
)
|
||||
|
||||
@@ -45,6 +45,11 @@ data class HomeRecommendationPopularCommunityPostSection(
|
||||
val items: List<HomeRecommendationPopularCommunityPostUiModel>
|
||||
)
|
||||
|
||||
fun HomeRecommendationPopularCommunityPostSection.visibleHomePopularCommunityPosts():
|
||||
List<HomeRecommendationPopularCommunityPostUiModel> {
|
||||
return items.take(HOME_POPULAR_COMMUNITY_MAX_POST_COUNT)
|
||||
}
|
||||
|
||||
data class HomeRecommendationLiveUiModel(
|
||||
val liveId: Long,
|
||||
val creatorId: Long,
|
||||
@@ -116,3 +121,4 @@ sealed interface HomeRecommendationPaidStatus {
|
||||
}
|
||||
|
||||
private const val HOME_GENRE_CREATOR_MAX_GROUP_COUNT = 5
|
||||
private const val HOME_POPULAR_COMMUNITY_MAX_POST_COUNT = 10
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.home.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.dispose
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
import kr.co.vividnext.sodalive.v2.main.home.model.HomeRecommendationPopularCommunityPostSection
|
||||
import kr.co.vividnext.sodalive.v2.main.home.model.HomeRecommendationPopularCommunityPostUiModel
|
||||
import kr.co.vividnext.sodalive.v2.main.home.model.visibleHomePopularCommunityPosts
|
||||
import kr.co.vividnext.sodalive.v2.widget.feed.FeedCommunityView
|
||||
import kr.co.vividnext.sodalive.v2.widget.feed.FeedItem
|
||||
|
||||
class HomePopularCommunityAdapter(
|
||||
private val onClickItem: (FeedItem.Community) -> Unit
|
||||
) : RecyclerView.Adapter<HomePopularCommunityAdapter.CommunityViewHolder>() {
|
||||
private var items: List<HomeRecommendationPopularCommunityPostUiModel> = emptyList()
|
||||
|
||||
fun submitSection(section: HomeRecommendationPopularCommunityPostSection) {
|
||||
items = section.visibleHomePopularCommunityPosts()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommunityViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(
|
||||
R.layout.view_feed_community,
|
||||
parent,
|
||||
false
|
||||
) as FeedCommunityView
|
||||
view.layoutParams = RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
).apply { bottomMargin = parent.resources.getDimensionPixelSize(R.dimen.spacing_8) }
|
||||
return CommunityViewHolder(view, onClickItem)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CommunityViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
class CommunityViewHolder(
|
||||
private val view: FeedCommunityView,
|
||||
private val onClickItem: (FeedItem.Community) -> Unit
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
fun bind(item: HomeRecommendationPopularCommunityPostUiModel) {
|
||||
view.bind(item.item)
|
||||
view.setOnFeedClick { feedItem -> onClickItem(feedItem as FeedItem.Community) }
|
||||
bindImage(item.item.creatorImageUrl, view.profileImageView())
|
||||
bindImage(item.item.imageUrl.takeIf { item.item.price <= 0 || item.item.existOrdered }, view.communityImageView())
|
||||
}
|
||||
|
||||
private fun bindImage(imageUrl: String?, imageView: android.widget.ImageView) {
|
||||
if (imageUrl.isNullOrBlank()) {
|
||||
imageView.dispose()
|
||||
imageView.setImageDrawable(null)
|
||||
} else {
|
||||
imageView.loadUrl(imageUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user