Skip to content

Commit

Permalink
[FIX] #307 외부와 내부 리사이클러뷰에서 서로 다른 리스트를 사용하도록 깊은 복사 수행하기
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Feb 6, 2024
1 parent 12ab353 commit b2ecbfe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.runnect.runnect.domain.entity.DiscoverMultiViewItem
import com.runnect.runnect.presentation.MainActivity
import com.runnect.runnect.presentation.discover.model.EditableDiscoverCourse
import com.runnect.runnect.util.callback.diff.ItemDiffCallback
import okhttp3.internal.wait
import timber.log.Timber

class DiscoverRecommendAdapter(
Expand Down Expand Up @@ -90,18 +91,33 @@ class DiscoverRecommendAdapter(
}

fun addRecommendCourseNextPage(nextPageItems: List<DiscoverMultiViewItem.RecommendCourse>) {
notifyItemRangeInserted(itemCount - 1, nextPageItems.size)
Timber.d("item count in inner recyclerview: ${nextPageItems.size} ${itemCount}")
Timber.d("before item count : $itemCount")

val newList = currentList.toMutableList()
newList.addAll(nextPageItems)

submitList(newList) { // 비동기 작업이 끝나고 나서 호출되는 콜백 함수
Timber.d("after item count : $itemCount")
}
}

fun updateRecommendCourseBySorting(firstPageItems: List<DiscoverMultiViewItem.RecommendCourse>) {
notifyDataSetChanged()
Timber.d("item count in inner recyclerview: ${firstPageItems.size} ${itemCount}")
Timber.d("before item count : $itemCount")

val newList = currentList.toMutableList()
newList.apply {
clear()
addAll(firstPageItems)
}

submitList(newList) {
Timber.d("after item count : $itemCount")
}
}

companion object {
private val diffUtil = ItemDiffCallback<DiscoverMultiViewItem.RecommendCourse>(
onItemsTheSame = { old, new -> old.id == new.id },
onItemsTheSame = { old, new -> old === new },
onContentsTheSame = { old, new -> old == new }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class DiscoverMultiViewAdapter(
}

is DiscoverMultiViewHolder.RecommendCourseViewHolder -> {
holder.bind(recommendCourses)
// 내부 리사이클러뷰에서는 완전히 새로운 리스트를 참조하도록 깊은 복사 수행
val newList = recommendCourses.map { it.copy() }.toList()
holder.bind(newList)
}
}
}
Expand Down Expand Up @@ -92,8 +94,6 @@ class DiscoverMultiViewAdapter(

fun addRecommendCourseNextPage(nextPageItems: List<RecommendCourse>) {
recommendCourses.addAll(nextPageItems)
Timber.d("item count in outer recyclerview: ${nextPageItems.size} ${recommendCourses.size}")

multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(nextPageItems)
}

Expand All @@ -102,8 +102,6 @@ class DiscoverMultiViewAdapter(
clear()
addAll(firstPageItems)
}
Timber.d("item count in outer recyclerview: ${firstPageItems.size} ${recommendCourses.size}")

multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(firstPageItems)
}

Expand Down

0 comments on commit b2ecbfe

Please sign in to comment.