Skip to content

Commit

Permalink
Merge pull request #325 from Runnect/feature/fix-discover-course-scrap
Browse files Browse the repository at this point in the history
[FIX] 코스 발견 / 스크랩 함수의 로직 수정
  • Loading branch information
leeeha authored Feb 15, 2024
2 parents 2df094d + 1a60a18 commit 2dbb194
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ class DiscoverMarathonAdapter(
}

fun updateMarathonCourseScrap(
targetIndex: Int,
publicCourseId: Int,
scrap: Boolean
) {
currentList[targetIndex].scrap = scrap
notifyItemChanged(targetIndex)
currentList.forEachIndexed { index, course ->
if (course.id == publicCourseId) {
course.scrap = scrap
notifyItemChanged(index)
return
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ class DiscoverRecommendAdapter(
}

fun updateRecommendCourseScrap(
targetIndex: Int,
publicCourseId: Int,
scrap: Boolean
) {
currentList[targetIndex].scrap = scrap
notifyItemChanged(targetIndex)
currentList.forEachIndexed { index, course ->
if (course.id == publicCourseId) {
course.scrap = scrap
notifyItemChanged(index)
return
}
}
}

fun addRecommendCourseNextPage(nextPageItems: List<DiscoverMultiViewItem.RecommendCourse>) {
Expand All @@ -105,7 +110,7 @@ class DiscoverRecommendAdapter(
val newList = currentList.toMutableList()
newList.addAll(nextPageItems)

submitList(newList) { // 비동기 작업이 끝나고 나서 호출되는 콜백 함수
submitList(newList) {
Timber.d("after item count : $itemCount")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,9 @@ class DiscoverMultiViewAdapter(
publicCourseId: Int,
scrap: Boolean
) {
val multiViewItems = marathonCourses + recommendCourses
val targetItem = multiViewItems.find { item ->
item.id == publicCourseId
} ?: return

when (targetItem) {
is MarathonCourse -> {
val targetIndex = marathonCourses.indexOf(targetItem)
multiViewHolderFactory.marathonCourseAdapter.updateMarathonCourseScrap(
targetIndex = targetIndex,
scrap = scrap
)
}

is RecommendCourse -> {
val targetIndex = recommendCourses.indexOf(targetItem)
multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseScrap(
targetIndex = targetIndex,
scrap = scrap
)
}
multiViewHolderFactory.apply {
marathonCourseAdapter.updateMarathonCourseScrap(publicCourseId, scrap)
recommendCourseAdapter.updateRecommendCourseScrap(publicCourseId, scrap)
}
}
}

0 comments on commit 2dbb194

Please sign in to comment.