diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverMarathonAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverMarathonAdapter.kt index 2c9b3fc9..db375273 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverMarathonAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverMarathonAdapter.kt @@ -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 { diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverRecommendAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverRecommendAdapter.kt index b8b5efeb..e46cf26c 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverRecommendAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/DiscoverRecommendAdapter.kt @@ -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) { @@ -105,7 +110,7 @@ class DiscoverRecommendAdapter( val newList = currentList.toMutableList() newList.addAll(nextPageItems) - submitList(newList) { // 비동기 작업이 끝나고 나서 호출되는 콜백 함수 + submitList(newList) { Timber.d("after item count : $itemCount") } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewAdapter.kt index 30bbdc95..74c85b51 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewAdapter.kt @@ -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) } } } \ No newline at end of file