fix(content): 전체 탭 pagination 스크롤을 안정화한다
This commit is contained in:
@@ -411,11 +411,11 @@ class ContentMainFragment : BaseFragment<FragmentV2MainContentBinding>(
|
||||
hideAllTabEmptyError()
|
||||
updateAllTabGridItemWidth()
|
||||
if (state.selectedType.usesSeriesItems()) {
|
||||
binding.rvContentAllItems.adapter = contentAllSeriesCardAdapter
|
||||
setAllTabAdapterIfNeeded(contentAllSeriesCardAdapter)
|
||||
contentAllAudioCardAdapter.submitItems(emptyList())
|
||||
contentAllSeriesCardAdapter.submitItems(state.seriesItems)
|
||||
} else {
|
||||
binding.rvContentAllItems.adapter = contentAllAudioCardAdapter
|
||||
setAllTabAdapterIfNeeded(contentAllAudioCardAdapter)
|
||||
contentAllSeriesCardAdapter.submitItems(emptyList())
|
||||
contentAllAudioCardAdapter.submitItems(state.audioItems)
|
||||
}
|
||||
@@ -439,6 +439,11 @@ class ContentMainFragment : BaseFragment<FragmentV2MainContentBinding>(
|
||||
contentAllSeriesCardAdapter.setGridItemWidthPx(widthPx)
|
||||
}
|
||||
|
||||
private fun setAllTabAdapterIfNeeded(adapter: RecyclerView.Adapter<*>) {
|
||||
if (binding.rvContentAllItems.adapter == adapter) return
|
||||
binding.rvContentAllItems.adapter = adapter
|
||||
}
|
||||
|
||||
private fun bindAllTabEmpty(state: MainContentAllTabUiState.Empty) {
|
||||
bindAllTabControls(state)
|
||||
binding.layoutContentAllSurface.visibility = View.VISIBLE
|
||||
@@ -485,7 +490,6 @@ class ContentMainFragment : BaseFragment<FragmentV2MainContentBinding>(
|
||||
}
|
||||
|
||||
private fun clearAllTabItems() {
|
||||
binding.rvContentAllItems.adapter = null
|
||||
contentAllAudioCardAdapter.submitItems(emptyList())
|
||||
contentAllSeriesCardAdapter.submitItems(emptyList())
|
||||
}
|
||||
|
||||
+20
-4
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.main.content.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemContentAudioCardBinding
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
@@ -17,12 +18,13 @@ class ContentAllAudioCardAdapter(
|
||||
fun setGridItemWidthPx(widthPx: Int) {
|
||||
if (widthPx <= 0 || gridItemWidthPx == widthPx) return
|
||||
gridItemWidthPx = widthPx
|
||||
notifyDataSetChanged()
|
||||
if (items.isNotEmpty()) notifyItemRangeChanged(0, items.size)
|
||||
}
|
||||
|
||||
fun submitItems(items: List<MainContentAllAudioUiModel>) {
|
||||
this.items = items
|
||||
notifyDataSetChanged()
|
||||
fun submitItems(newItems: List<MainContentAllAudioUiModel>) {
|
||||
val diffResult = DiffUtil.calculateDiff(ContentAllAudioDiffCallback(items, newItems))
|
||||
items = newItems
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
@@ -41,6 +43,20 @@ class ContentAllAudioCardAdapter(
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
private class ContentAllAudioDiffCallback(
|
||||
private val oldList: List<MainContentAllAudioUiModel>,
|
||||
private val newList: List<MainContentAllAudioUiModel>
|
||||
) : DiffUtil.Callback() {
|
||||
override fun getOldListSize(): Int = oldList.size
|
||||
override fun getNewListSize(): Int = newList.size
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean =
|
||||
oldList[oldItemPosition].audioContentId == newList[newItemPosition].audioContentId
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean =
|
||||
oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
|
||||
class ViewHolder(
|
||||
private val binding: ItemContentAudioCardBinding,
|
||||
private val onAudioClick: (Long) -> Unit
|
||||
|
||||
+20
-4
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.main.content.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemContentAllSeriesCardBinding
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
@@ -17,12 +18,13 @@ class ContentAllSeriesCardAdapter(
|
||||
fun setGridItemWidthPx(widthPx: Int) {
|
||||
if (widthPx <= 0 || gridItemWidthPx == widthPx) return
|
||||
gridItemWidthPx = widthPx
|
||||
notifyDataSetChanged()
|
||||
if (items.isNotEmpty()) notifyItemRangeChanged(0, items.size)
|
||||
}
|
||||
|
||||
fun submitItems(items: List<MainContentAllSeriesUiModel>) {
|
||||
this.items = items
|
||||
notifyDataSetChanged()
|
||||
fun submitItems(newItems: List<MainContentAllSeriesUiModel>) {
|
||||
val diffResult = DiffUtil.calculateDiff(ContentAllSeriesDiffCallback(items, newItems))
|
||||
items = newItems
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
@@ -41,6 +43,20 @@ class ContentAllSeriesCardAdapter(
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
private class ContentAllSeriesDiffCallback(
|
||||
private val oldList: List<MainContentAllSeriesUiModel>,
|
||||
private val newList: List<MainContentAllSeriesUiModel>
|
||||
) : DiffUtil.Callback() {
|
||||
override fun getOldListSize(): Int = oldList.size
|
||||
override fun getNewListSize(): Int = newList.size
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean =
|
||||
oldList[oldItemPosition].seriesId == newList[newItemPosition].seriesId
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean =
|
||||
oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
|
||||
class ViewHolder(
|
||||
private val binding: ItemContentAllSeriesCardBinding,
|
||||
private val onSeriesClick: (Long) -> Unit
|
||||
|
||||
Reference in New Issue
Block a user