fix(home): 라이브 전체 항목을 항상 표시한다

This commit is contained in:
2026-07-31 18:34:23 +09:00
parent d592038edd
commit dd4a5167a9
5 changed files with 263 additions and 4 deletions

View File

@@ -14,13 +14,13 @@ 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 showAllItem: Boolean = false
private var onClick: ((HomeRecommendationLiveUiModel) -> Unit)? = null
private var onMoreClick: (() -> Unit)? = null
fun submitItems(items: List<HomeRecommendationLiveUiModel>) {
this.items = items.take(MAX_VISIBLE_LIVE_COUNT)
hasMore = items.size > MAX_VISIBLE_LIVE_COUNT
showAllItem = items.isNotEmpty()
notifyDataSetChanged()
}
@@ -49,10 +49,10 @@ class HomeLiveAdapter : RecyclerView.Adapter<HomeLiveAdapter.LiveViewHolder>() {
}
}
override fun getItemCount(): Int = items.size + if (hasMore) 1 else 0
override fun getItemCount(): Int = items.size + if (showAllItem) 1 else 0
override fun getItemViewType(position: Int): Int {
return if (hasMore && position == itemCount - 1) VIEW_TYPE_MORE else VIEW_TYPE_LIVE
return if (showAllItem && position == itemCount - 1) VIEW_TYPE_MORE else VIEW_TYPE_LIVE
}
private fun liveItemLayoutParams(parent: ViewGroup): RecyclerView.LayoutParams {

View File

@@ -1043,6 +1043,28 @@ class HomeMainFragmentLayoutTest {
assertEquals(14.dpToPx(), layoutParams.marginEnd)
}
@Test
fun `홈 라이브 어댑터는 라이브가 있으면 전체 항목을 추가한다`() {
val context = ApplicationProvider.getApplicationContext<Context>()
val parent = RecyclerView(context)
parent.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
val adapter = HomeLiveAdapter()
adapter.submitItems(emptyList())
assertEquals(0, adapter.itemCount)
adapter.submitItems(listOf(liveItem(1L)))
assertEquals(2, adapter.itemCount)
val viewHolder = adapter.onCreateViewHolder(parent, adapter.getItemViewType(1))
assertEquals(
context.getString(R.string.screen_home_theme_all),
(viewHolder.itemView as TextView).text.toString()
)
adapter.submitItems((1L..20L).map(::liveItem))
assertEquals(21, adapter.itemCount)
}
@Test
fun `home live adapter appends all item after twenty lives`() {
val context = ApplicationProvider.getApplicationContext<Context>()