feat(home): 라이브 섹션 전체 아이템을 추가한다
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.home.ui
|
||||
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
@@ -11,10 +14,12 @@ import kr.co.vividnext.sodalive.v2.widget.livethumbnail.LiveThumbnailSimpleView
|
||||
|
||||
class HomeLiveAdapter : RecyclerView.Adapter<HomeLiveAdapter.LiveViewHolder>() {
|
||||
private var items: List<HomeRecommendationLiveUiModel> = emptyList()
|
||||
private var hasMore: Boolean = false
|
||||
private var onClick: ((HomeRecommendationLiveUiModel) -> Unit)? = null
|
||||
|
||||
fun submitItems(items: List<HomeRecommendationLiveUiModel>) {
|
||||
this.items = items
|
||||
this.items = items.take(MAX_VISIBLE_LIVE_COUNT)
|
||||
hasMore = items.size > MAX_VISIBLE_LIVE_COUNT
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
@@ -23,20 +28,54 @@ class HomeLiveAdapter : RecyclerView.Adapter<HomeLiveAdapter.LiveViewHolder>() {
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LiveViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.view_live_thumbnail_simple, parent, false)
|
||||
view.layoutParams = recyclerItemLayoutParams(parent)
|
||||
return LiveViewHolder(view as LiveThumbnailSimpleView)
|
||||
return if (viewType == VIEW_TYPE_MORE) {
|
||||
MoreViewHolder(createMoreView(parent))
|
||||
} else {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.view_live_thumbnail_simple, parent, false)
|
||||
view.layoutParams = liveItemLayoutParams(parent)
|
||||
LiveItemViewHolder(view as LiveThumbnailSimpleView)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: LiveViewHolder, position: Int) {
|
||||
holder.bind(items[position], onClick)
|
||||
when (holder) {
|
||||
is LiveItemViewHolder -> holder.bind(items[position], onClick)
|
||||
is MoreViewHolder -> holder.bind()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
override fun getItemCount(): Int = items.size + if (hasMore) 1 else 0
|
||||
|
||||
class LiveViewHolder(
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (hasMore && position == itemCount - 1) VIEW_TYPE_MORE else VIEW_TYPE_LIVE
|
||||
}
|
||||
|
||||
private fun liveItemLayoutParams(parent: ViewGroup): RecyclerView.LayoutParams {
|
||||
return RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
).apply { marginEnd = parent.resources.getDimensionPixelSize(R.dimen.spacing_14) }
|
||||
}
|
||||
|
||||
private fun createMoreView(parent: ViewGroup): TextView {
|
||||
return TextView(parent.context).apply {
|
||||
layoutParams = RecyclerView.LayoutParams(
|
||||
parent.resources.getDimensionPixelSize(R.dimen.home_live_more_width),
|
||||
parent.resources.getDimensionPixelSize(R.dimen.home_live_row_height)
|
||||
)
|
||||
gravity = Gravity.CENTER
|
||||
setBackgroundResource(R.color.black)
|
||||
setText(R.string.screen_home_theme_all)
|
||||
setTextAppearance(R.style.Typography_Body5)
|
||||
setTextColor(parent.context.getColor(R.color.soda_400))
|
||||
}
|
||||
}
|
||||
|
||||
sealed class LiveViewHolder(view: View) : RecyclerView.ViewHolder(view)
|
||||
|
||||
class LiveItemViewHolder(
|
||||
private val view: LiveThumbnailSimpleView
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
) : LiveViewHolder(view) {
|
||||
fun bind(
|
||||
item: HomeRecommendationLiveUiModel,
|
||||
onClick: ((HomeRecommendationLiveUiModel) -> Unit)?
|
||||
@@ -54,4 +93,18 @@ class HomeLiveAdapter : RecyclerView.Adapter<HomeLiveAdapter.LiveViewHolder>() {
|
||||
view.setOnLiveThumbnailClick(if (onClick == null) null else { _: LiveThumbnailItem -> onClick.invoke(item) })
|
||||
}
|
||||
}
|
||||
|
||||
class MoreViewHolder(
|
||||
private val view: TextView
|
||||
) : LiveViewHolder(view) {
|
||||
fun bind() {
|
||||
view.setOnClickListener(null)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MAX_VISIBLE_LIVE_COUNT = 20
|
||||
private const val VIEW_TYPE_LIVE = 0
|
||||
private const val VIEW_TYPE_MORE = 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user