From 8e1fac6e4d2cb725a12bdbfbbf167c4939e83e2e Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:23:09 +0900 Subject: [PATCH 01/21] =?UTF-8?q?[DEL]=20#307=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=9E=84=ED=8F=AC?= =?UTF-8?q?=ED=8A=B8=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/presentation/discover/DiscoverFragment.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index f2163d67a..ecc080e6a 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -17,7 +17,6 @@ import com.runnect.runnect.R import com.runnect.runnect.binding.BindingFragment import com.runnect.runnect.databinding.FragmentDiscoverBinding import com.runnect.runnect.domain.entity.DiscoverBanner -import com.runnect.runnect.domain.entity.DiscoverMultiViewItem import com.runnect.runnect.presentation.discover.model.EditableDiscoverCourse import com.runnect.runnect.presentation.MainActivity import com.runnect.runnect.presentation.MainActivity.Companion.isVisitorMode @@ -41,7 +40,6 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import timber.log.Timber @AndroidEntryPoint From 86f992bf6d7d2600b886b9408d8a330f71fb8dc5 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:39:29 +0900 Subject: [PATCH 02/21] =?UTF-8?q?[FEAT]=20#307=20=EB=A9=80=ED=8B=B0?= =?UTF-8?q?=EB=B7=B0=20=ED=99=80=EB=8D=94=20=EC=95=88=EC=97=90=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=20=EC=BD=94=EC=8A=A4=20=EC=A0=95=EB=A0=AC=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EB=A6=AC=EC=8A=A4=EB=84=88=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover/adapter/DiscoverRecommendAdapter.kt | 6 +++++- .../discover/adapter/multiview/DiscoverMultiViewHolder.kt | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 f991cc4d4..d24e2fbf2 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 @@ -41,7 +41,7 @@ class DiscoverRecommendAdapter( private val binding: ItemDiscoverRecommendBinding, private val onHeartButtonClick: (Int, Boolean) -> Unit, private val onCourseItemClick: (Int) -> Unit, - private val handleVisitorMode: () -> Unit, + private val handleVisitorMode: () -> Unit ) : RecyclerView.ViewHolder(binding.root) { fun bind(course: DiscoverMultiViewItem.RecommendCourse) { with(binding) { @@ -95,6 +95,10 @@ class DiscoverRecommendAdapter( submitList(newList) } + fun updateRecommendCourseBySorting(items: List) { + submitList(items) + } + companion object { private val diffUtil = ItemDiffCallback( onItemsTheSame = { old, new -> old.id == new.id }, diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index 0364492ca..252e6c7fc 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -65,6 +65,7 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : onHeartButtonClick: (Int, Boolean) -> Unit, onCourseItemClick: (Int) -> Unit, handleVisitorMode: () -> Unit, + private val onSortButtonClick: (String) -> Unit ) : DiscoverMultiViewHolder(binding) { val recommendAdapter by lazy { DiscoverRecommendAdapter( @@ -77,6 +78,7 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : fun bind(courses: List) { Timber.d("추천 코스 리스트 크기: ${courses.size}") initRecommendRecyclerView(courses) + initSortButtonClickListener() } private fun initRecommendRecyclerView(courses: List) { @@ -103,5 +105,11 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : ) } } + + private fun initSortButtonClickListener() { + binding.tvDiscoverRecommendSortByDate.setOnClickListener { + + } + } } } From 79867b84ebdb4d3ad35a9b605387663d547fe428 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:41:49 +0900 Subject: [PATCH 03/21] =?UTF-8?q?[FEAT]=20#307=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EB=94=94=EC=9E=90?= =?UTF-8?q?=EC=9D=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../multiview/DiscoverMultiViewHolder.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index 252e6c7fc..04a2cf733 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -1,8 +1,12 @@ package com.runnect.runnect.presentation.discover.adapter.multiview +import android.content.Context +import android.graphics.Typeface +import android.widget.TextView import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.runnect.runnect.R import com.runnect.runnect.databinding.ItemDiscoverMultiviewMarathonBinding import com.runnect.runnect.databinding.ItemDiscoverMultiviewRecommendBinding import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.MarathonCourse @@ -13,6 +17,7 @@ import com.runnect.runnect.presentation.discover.model.EditableDiscoverCourse import com.runnect.runnect.util.custom.deco.DiscoverMarathonItemDecoration import com.runnect.runnect.util.custom.deco.DiscoverRecommendItemDecoration import com.runnect.runnect.util.custom.deco.GridSpacingItemDecoration +import com.runnect.runnect.util.extension.colorOf import timber.log.Timber sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : @@ -105,11 +110,41 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : ) } } - private fun initSortButtonClickListener() { binding.tvDiscoverRecommendSortByDate.setOnClickListener { + val context = it.context ?: return@setOnClickListener + activateTextStyle(view = it as TextView, context = context) + deactivateOtherTextStyle( + view = binding.tvDiscoverRecommendSortByScrap, + context = context + ) + onSortButtonClick.invoke(SORT_BY_DATE) + } + binding.tvDiscoverRecommendSortByScrap.setOnClickListener { + val context = it.context ?: return@setOnClickListener + activateTextStyle(view = it as TextView, context = context) + deactivateOtherTextStyle( + view = binding.tvDiscoverRecommendSortByDate, + context = context + ) + onSortButtonClick.invoke(SORT_BY_SCRAP) } } + + private fun activateTextStyle(view: TextView, context: Context) { + view.setTextColor(context.colorOf(R.color.M1)) + view.typeface = context.fontOf(R.font.pretendard_semibold, Typeface.NORMAL) + } + + private fun deactivateOtherTextStyle(view: TextView, context: Context) { + view.setTextColor(context.colorOf(R.color.G2)) + view.typeface = context.fontOf(R.font.pretendard_regular, Typeface.NORMAL) + } + + companion object { + private const val SORT_BY_DATE = "date" + private const val SORT_BY_SCRAP = "scrap" + } } } From 40d57acb21b2d21c775f3b2e1c4e55f43b3fc635 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:50:17 +0900 Subject: [PATCH 04/21] =?UTF-8?q?[ADD]=20#307=20=ED=8F=B0=ED=8A=B8=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=ED=99=95=EC=9E=A5=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/runnect/runnect/util/extension/ContextExt.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/runnect/runnect/util/extension/ContextExt.kt b/app/src/main/java/com/runnect/runnect/util/extension/ContextExt.kt index e7f491a14..cafff350e 100644 --- a/app/src/main/java/com/runnect/runnect/util/extension/ContextExt.kt +++ b/app/src/main/java/com/runnect/runnect/util/extension/ContextExt.kt @@ -4,6 +4,7 @@ import android.app.AlertDialog import android.content.Context import android.content.Intent import android.graphics.Color +import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.net.Uri import android.view.Gravity @@ -13,10 +14,13 @@ import android.view.inputmethod.InputMethodManager import android.widget.Toast import androidx.annotation.ColorRes import androidx.annotation.DrawableRes +import androidx.annotation.FontRes +import androidx.annotation.StyleRes import androidx.appcompat.widget.AppCompatButton import androidx.appcompat.widget.LinearLayoutCompat import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.snackbar.Snackbar @@ -182,3 +186,6 @@ fun Context.showSnackbar(anchorView: View, message: String, @GravityFlag gravity fun Context.colorOf(@ColorRes resId: Int) = ContextCompat.getColor(this, resId) fun Context.drawableOf(@DrawableRes resId: Int) = ContextCompat.getDrawable(this, resId) + +fun Context.fontOf(@FontRes resId: Int, @StyleRes style: Int): Typeface = + Typeface.create(ResourcesCompat.getFont(this, resId), style) \ No newline at end of file From d28a5745f28bf79ef8aa535f7c64d5c21f86d6ce Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:50:51 +0900 Subject: [PATCH 05/21] =?UTF-8?q?[FEAT]=20#307=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=EB=84=88=EB=A5=BC=20=EB=A9=80=ED=8B=B0=EB=B7=B0=20=EC=96=B4?= =?UTF-8?q?=EB=8C=91=ED=84=B0=EC=97=90=EC=84=9C=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 9 ++++++--- .../adapter/multiview/DiscoverMultiViewAdapter.kt | 4 +++- .../adapter/multiview/DiscoverMultiViewHolder.kt | 12 ++++++++++++ .../multiview/DiscoverMultiViewHolderFactory.kt | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index da733b04a..aa61293af 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -96,6 +96,9 @@ class DiscoverFragment : BindingFragment(R.layout.fragm }, handleVisitorMode = { context?.let { showCourseScrapWarningToast(it) } + }, + onSortButtonClick = { criteria -> + viewModel.sortRecommendCourse() } ).apply { binding.rvDiscoverMultiView.adapter = this @@ -331,7 +334,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm } private fun setupMarathonCourseGetStateObserver() { - viewModel.marathonCourseState.observe(viewLifecycleOwner) { state -> + viewModel.marathonCourseGetState.observe(viewLifecycleOwner) { state -> when (state) { is UiStateV2.Success -> { multiViewAdapter.initMarathonCourses(state.data) @@ -351,7 +354,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm } private fun setupRecommendCourseGetStateObserver() { - viewModel.recommendCourseState.observe(viewLifecycleOwner) { state -> + viewModel.recommendCourseGetState.observe(viewLifecycleOwner) { state -> when (state) { is UiStateV2.Loading -> showLoadingProgressBar() @@ -385,7 +388,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm } private fun setupRecommendCourseNextPageStateObserver() { - viewModel.nextPageState.observe(viewLifecycleOwner) { state -> + viewModel.recommendCourseNextPageState.observe(viewLifecycleOwner) { state -> when (state) { is UiStateV2.Success -> { multiViewAdapter.addRecommendCourseNextPage(state.data) 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 b4c3465b6..3bd3bd81a 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 @@ -11,6 +11,7 @@ class DiscoverMultiViewAdapter( private val onHeartButtonClick: (Int, Boolean) -> Unit, private val onCourseItemClick: (Int) -> Unit, private val handleVisitorMode: () -> Unit, + private val onSortButtonClick: (String) -> Unit ) : RecyclerView.Adapter() { private val multiViewHolderFactory by lazy { DiscoverMultiViewHolderFactory() } private val marathonCourses = arrayListOf() @@ -23,7 +24,8 @@ class DiscoverMultiViewAdapter( viewType = viewType, onHeartButtonClick = onHeartButtonClick, onCourseItemClick = onCourseItemClick, - handleVisitorMode = handleVisitorMode + handleVisitorMode = handleVisitorMode, + onSortButtonClick = onSortButtonClick ) } diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index 04a2cf733..4ee70e09c 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -18,6 +18,7 @@ import com.runnect.runnect.util.custom.deco.DiscoverMarathonItemDecoration import com.runnect.runnect.util.custom.deco.DiscoverRecommendItemDecoration import com.runnect.runnect.util.custom.deco.GridSpacingItemDecoration import com.runnect.runnect.util.extension.colorOf +import com.runnect.runnect.util.extension.fontOf import timber.log.Timber sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : @@ -111,23 +112,34 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : } } private fun initSortButtonClickListener() { + initSortByDateClickListener() + initSortByScrapClickListener() + } + + private fun initSortByDateClickListener() { binding.tvDiscoverRecommendSortByDate.setOnClickListener { val context = it.context ?: return@setOnClickListener + activateTextStyle(view = it as TextView, context = context) deactivateOtherTextStyle( view = binding.tvDiscoverRecommendSortByScrap, context = context ) + onSortButtonClick.invoke(SORT_BY_DATE) } + } + private fun initSortByScrapClickListener() { binding.tvDiscoverRecommendSortByScrap.setOnClickListener { val context = it.context ?: return@setOnClickListener + activateTextStyle(view = it as TextView, context = context) deactivateOtherTextStyle( view = binding.tvDiscoverRecommendSortByDate, context = context ) + onSortButtonClick.invoke(SORT_BY_SCRAP) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolderFactory.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolderFactory.kt index 1eb5667aa..60fb681bf 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolderFactory.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolderFactory.kt @@ -16,6 +16,7 @@ class DiscoverMultiViewHolderFactory { onHeartButtonClick: (Int, Boolean) -> Unit, onCourseItemClick: (Int) -> Unit, handleVisitorMode: () -> Unit, + onSortButtonClick: (String) -> Unit ): DiscoverMultiViewHolder { when (viewType) { DiscoverMultiViewType.MARATHON.ordinal -> { @@ -34,7 +35,8 @@ class DiscoverMultiViewHolderFactory { binding = parent.getViewDataBinding(layoutRes = R.layout.item_discover_multiview_recommend), onHeartButtonClick = onHeartButtonClick, onCourseItemClick = onCourseItemClick, - handleVisitorMode = handleVisitorMode + handleVisitorMode = handleVisitorMode, + onSortButtonClick = onSortButtonClick ) recommendCourseAdapter = viewHolder.recommendAdapter return viewHolder From bfec184e96a15d50c90169f88f01e0edc1a8ad35 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:51:10 +0900 Subject: [PATCH 06/21] =?UTF-8?q?[MOD]=20#307=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=BD=94=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover/DiscoverViewModel.kt | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 548ce07f5..0ba78b0b8 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -26,17 +26,21 @@ class DiscoverViewModel @Inject constructor( val bannerGetState: LiveData>> get() = _bannerGetState - private val _marathonCourseState = MutableLiveData>>() - val marathonCourseState: LiveData>> - get() = _marathonCourseState + private val _marathonCourseGetState = MutableLiveData>>() + val marathonCourseGetState: LiveData>> + get() = _marathonCourseGetState - private val _recommendCourseState = MutableLiveData>>() - val recommendCourseState: LiveData>> - get() = _recommendCourseState + private val _recommendCourseGetState = MutableLiveData>>() + val recommendCourseGetState: LiveData>> + get() = _recommendCourseGetState - private val _nextPageState = MutableLiveData>>() - val nextPageState: LiveData>> - get() = _nextPageState + private val _recommendCourseNextPageState = MutableLiveData>>() + val recommendCourseNextPageState: LiveData>> + get() = _recommendCourseNextPageState + + private val _recommendCourseSortState = MutableLiveData>>() + val recommendCourseSortState: LiveData>> + get() = _recommendCourseSortState private val _courseScrapState = MutableLiveData>() val courseScrapState: LiveData> @@ -85,21 +89,21 @@ class DiscoverViewModel @Inject constructor( private fun getMarathonCourses() { viewModelScope.launch { - _marathonCourseState.value = UiStateV2.Loading + _marathonCourseGetState.value = UiStateV2.Loading courseRepository.getMarathonCourse() .onSuccess { courses -> if (courses == null) { - _marathonCourseState.value = + _marathonCourseGetState.value = UiStateV2.Failure("MARATHON COURSE DATA IS NULL") return@launch } - _marathonCourseState.value = UiStateV2.Success(courses) + _marathonCourseGetState.value = UiStateV2.Success(courses) Timber.d("MARATHON COURSE GET SUCCESS") } .onFailure { exception -> - _marathonCourseState.value = UiStateV2.Failure(exception.message.toString()) + _marathonCourseGetState.value = UiStateV2.Failure(exception.message.toString()) Timber.e("MARATHON COURSE GET FAIL") } } @@ -107,36 +111,36 @@ class DiscoverViewModel @Inject constructor( fun getRecommendCourses() { viewModelScope.launch { - _recommendCourseState.value = UiStateV2.Loading + _recommendCourseGetState.value = UiStateV2.Loading courseRepository.getRecommendCourse( pageNo = FIRST_PAGE_NUM.toString(), ordering = DEFAULT_SORT_CRITERIA ).onSuccess { pagingData -> if (pagingData == null) { - _recommendCourseState.value = + _recommendCourseGetState.value = UiStateV2.Failure("RECOMMEND COURSE DATA IS NULL") return@onSuccess } isRecommendCoursePageEnd = pagingData.isEnd - _recommendCourseState.value = UiStateV2.Success(pagingData.recommendCourses) + _recommendCourseGetState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE GET SUCCESS") }.onFailure { exception -> - _recommendCourseState.value = UiStateV2.Failure(exception.message.toString()) + _recommendCourseGetState.value = UiStateV2.Failure(exception.message.toString()) Timber.e("RECOMMEND COURSE GET FAIL") } } } - fun isNextPageLoading() = nextPageState.value is UiStateV2.Loading + fun isNextPageLoading() = recommendCourseNextPageState.value is UiStateV2.Loading fun getRecommendCourseNextPage() { viewModelScope.launch { if (isRecommendCoursePageEnd) return@launch Timber.d("다음 페이지를 요청했어요!") - _nextPageState.value = UiStateV2.Loading + _recommendCourseNextPageState.value = UiStateV2.Loading currentPageNumber++ courseRepository.getRecommendCourse( @@ -145,22 +149,26 @@ class DiscoverViewModel @Inject constructor( ) .onSuccess { pagingData -> if (pagingData == null) { - _nextPageState.value = + _recommendCourseNextPageState.value = UiStateV2.Failure("RECOMMEND COURSE NEXT PAGE DATA IS NULL") return@onSuccess } isRecommendCoursePageEnd = pagingData.isEnd - _nextPageState.value = UiStateV2.Success(pagingData.recommendCourses) + _recommendCourseNextPageState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE NEXT PAGE GET SUCCESS") } .onFailure { exception -> - _nextPageState.value = UiStateV2.Failure(exception.message.toString()) + _recommendCourseNextPageState.value = UiStateV2.Failure(exception.message.toString()) Timber.e("RECOMMEND COURSE NEXT PAGE GET FAIL") } } } + fun sortRecommendCourse() { + + } + fun postCourseScrap(id: Int, scrapTF: Boolean) { viewModelScope.launch { _courseScrapState.value = UiStateV2.Loading From f500d716239d035b305f5ddff92d4ea750af2178 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:53:55 +0900 Subject: [PATCH 07/21] =?UTF-8?q?[FEAT]=20#307=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EB=A1=9C=EB=B6=80=ED=84=B0=20=EC=A0=95=EB=A0=AC=EB=90=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=9B=EC=95=84=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 2 +- .../discover/DiscoverViewModel.kt | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index aa61293af..730b3b65b 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -98,7 +98,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm context?.let { showCourseScrapWarningToast(it) } }, onSortButtonClick = { criteria -> - viewModel.sortRecommendCourse() + viewModel.sortRecommendCourses(criteria) } ).apply { binding.rvDiscoverMultiView.adapter = this diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 0ba78b0b8..550fe0a80 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -165,8 +165,28 @@ class DiscoverViewModel @Inject constructor( } } - fun sortRecommendCourse() { + fun sortRecommendCourses(criteria: String) { + viewModelScope.launch { + _recommendCourseSortState.value = UiStateV2.Loading + courseRepository.getRecommendCourse( + pageNo = FIRST_PAGE_NUM.toString(), + ordering = criteria + ).onSuccess { pagingData -> + if (pagingData == null) { + _recommendCourseSortState.value = + UiStateV2.Failure("RECOMMEND COURSE DATA IS NULL") + return@onSuccess + } + + isRecommendCoursePageEnd = pagingData.isEnd + _recommendCourseSortState.value = UiStateV2.Success(pagingData.recommendCourses) + Timber.d("RECOMMEND COURSE SORT SUCCESS") + }.onFailure { exception -> + _recommendCourseSortState.value = UiStateV2.Failure(exception.message.toString()) + Timber.e("RECOMMEND COURSE SORT FAIL") + } + } } fun postCourseScrap(id: Int, scrapTF: Boolean) { From 961aefb480bdc68d1c6d18d96eb7b91175b647d8 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 00:59:42 +0900 Subject: [PATCH 08/21] =?UTF-8?q?[MOD]=20#307=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8=EC=84=9C=20=EB=B3=80=EA=B2=BD=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=A0=95=EB=A0=AC=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EC=82=AC=EC=9A=A9=EB=90=98=EB=8A=94=20=EC=9D=B8?= =?UTF-8?q?=EC=9E=90=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/data/repository/CourseRepositoryImpl.kt | 4 ++-- .../java/com/runnect/runnect/data/service/CourseService.kt | 2 +- .../runnect/data/source/remote/RemoteCourseDataSource.kt | 4 ++-- .../runnect/runnect/domain/repository/CourseRepository.kt | 2 +- .../runnect/presentation/discover/DiscoverViewModel.kt | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/data/repository/CourseRepositoryImpl.kt b/app/src/main/java/com/runnect/runnect/data/repository/CourseRepositoryImpl.kt index 540a03cd1..730876f3a 100644 --- a/app/src/main/java/com/runnect/runnect/data/repository/CourseRepositoryImpl.kt +++ b/app/src/main/java/com/runnect/runnect/data/repository/CourseRepositoryImpl.kt @@ -33,11 +33,11 @@ class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSourc override suspend fun getRecommendCourse( pageNo: String, - ordering: String + sort: String ): Result = runCatching { val response = remoteCourseDataSource.getRecommendCourse( pageNo = pageNo, - ordering = ordering + sort = sort ).data response?.let { diff --git a/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt b/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt index aa579c61b..96e0448f4 100644 --- a/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt +++ b/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt @@ -19,7 +19,7 @@ interface CourseService { @GET("/api/public-course") suspend fun getRecommendCourse( @Query("pageNo") pageNo: String, - @Query("ordering") ordering: String + @Query("sort") sort: String ): BaseResponse @POST("/api/scrap") diff --git a/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteCourseDataSource.kt b/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteCourseDataSource.kt index ffb83942d..6a6879d71 100644 --- a/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteCourseDataSource.kt +++ b/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteCourseDataSource.kt @@ -24,9 +24,9 @@ class RemoteCourseDataSource @Inject constructor( suspend fun getRecommendCourse( pageNo: String, - ordering: String + sort: String ): BaseResponse = - courseService.getRecommendCourse(pageNo = pageNo, ordering = ordering) + courseService.getRecommendCourse(pageNo = pageNo, sort = sort) suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): BaseResponse = courseService.postCourseScrap(requestPostCourseScrap) diff --git a/app/src/main/java/com/runnect/runnect/domain/repository/CourseRepository.kt b/app/src/main/java/com/runnect/runnect/domain/repository/CourseRepository.kt index ec56b0e9b..a9bc5c5c5 100644 --- a/app/src/main/java/com/runnect/runnect/domain/repository/CourseRepository.kt +++ b/app/src/main/java/com/runnect/runnect/domain/repository/CourseRepository.kt @@ -26,7 +26,7 @@ interface CourseRepository { suspend fun getRecommendCourse( pageNo: String, - ordering: String + sort: String ): Result suspend fun getCourseSearch(keyword: String): Result?> diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 550fe0a80..bf608b68d 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -115,7 +115,7 @@ class DiscoverViewModel @Inject constructor( courseRepository.getRecommendCourse( pageNo = FIRST_PAGE_NUM.toString(), - ordering = DEFAULT_SORT_CRITERIA + sort = DEFAULT_SORT_CRITERIA ).onSuccess { pagingData -> if (pagingData == null) { _recommendCourseGetState.value = @@ -145,7 +145,7 @@ class DiscoverViewModel @Inject constructor( courseRepository.getRecommendCourse( pageNo = currentPageNumber.toString(), - ordering = DEFAULT_SORT_CRITERIA + sort = DEFAULT_SORT_CRITERIA ) .onSuccess { pagingData -> if (pagingData == null) { @@ -171,7 +171,7 @@ class DiscoverViewModel @Inject constructor( courseRepository.getRecommendCourse( pageNo = FIRST_PAGE_NUM.toString(), - ordering = criteria + sort = criteria ).onSuccess { pagingData -> if (pagingData == null) { _recommendCourseSortState.value = From 240c9ae2d7aa950c1e9384d9139dd7a8757ebbde Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 01:12:43 +0900 Subject: [PATCH 09/21] =?UTF-8?q?[FEAT]=20#307=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=BD=94=EC=8A=A4=20=EC=A0=95=EB=A0=AC=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EB=B7=B0=20=EA=B0=B1=EC=8B=A0=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 21 +++++++++++++++++++ .../discover/DiscoverViewModel.kt | 13 ++++++++++-- .../multiview/DiscoverMultiViewAdapter.kt | 8 +++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index 730b3b65b..bb12b5113 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -274,6 +274,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm setupMarathonCourseGetStateObserver() setupRecommendCourseGetStateObserver() setupRecommendCourseNextPageStateObserver() + setupRecommendCourseSortStateObserver() setupCourseScrapStateObserver() } @@ -407,6 +408,26 @@ class DiscoverFragment : BindingFragment(R.layout.fragm } } + private fun setupRecommendCourseSortStateObserver() { + viewModel.recommendCourseSortState.observe(viewLifecycleOwner) { state -> + when (state) { + is UiStateV2.Success -> { + multiViewAdapter.updateRecommendCourseBySorting(state.data) + } + + is UiStateV2.Failure -> { + context?.showSnackbar( + anchorView = binding.root, + message = state.msg, + gravity = Gravity.TOP + ) + } + + else -> {} + } + } + } + private fun setupCourseScrapStateObserver() { viewModel.courseScrapState.observe(viewLifecycleOwner) { state -> if (state is UiStateV2.Failure) { diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index bf608b68d..9ed60a634 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -51,6 +51,7 @@ class DiscoverViewModel @Inject constructor( private var isRecommendCoursePageEnd = false private var currentPageNumber = FIRST_PAGE_NUM + private var currentSortCriteria = DEFAULT_SORT_CRITERIA init { getDiscoverBanners() @@ -71,6 +72,7 @@ class DiscoverViewModel @Inject constructor( private fun initRecommendCoursePagingData() { isRecommendCoursePageEnd = false currentPageNumber = FIRST_PAGE_NUM + currentSortCriteria = DEFAULT_SORT_CRITERIA } private fun getDiscoverBanners() { @@ -139,13 +141,13 @@ class DiscoverViewModel @Inject constructor( viewModelScope.launch { if (isRecommendCoursePageEnd) return@launch - Timber.d("다음 페이지를 요청했어요!") + Timber.d("다음 페이지를 요청했어요! 정렬 기준: $currentSortCriteria") _recommendCourseNextPageState.value = UiStateV2.Loading currentPageNumber++ courseRepository.getRecommendCourse( pageNo = currentPageNumber.toString(), - sort = DEFAULT_SORT_CRITERIA + sort = currentSortCriteria ) .onSuccess { pagingData -> if (pagingData == null) { @@ -166,6 +168,9 @@ class DiscoverViewModel @Inject constructor( } fun sortRecommendCourses(criteria: String) { + initRecommendCoursePagingData() + saveCurrentSortCriteria(criteria) + viewModelScope.launch { _recommendCourseSortState.value = UiStateV2.Loading @@ -189,6 +194,10 @@ class DiscoverViewModel @Inject constructor( } } + private fun saveCurrentSortCriteria(criteria: String) { + currentSortCriteria = criteria + } + fun postCourseScrap(id: Int, scrapTF: Boolean) { viewModelScope.launch { _courseScrapState.value = UiStateV2.Loading 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 3bd3bd81a..3604d78cb 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 @@ -95,6 +95,14 @@ class DiscoverMultiViewAdapter( multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(items) } + fun updateRecommendCourseBySorting(items: List) { + recommendCourses.apply { + clear() + addAll(items) + } + multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(items) + } + fun updateCourseItem( publicCourseId: Int, updatedCourse: EditableDiscoverCourse From 40ee5d91dc7aea0e470fdc1df8f6f1b605f502cf Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 17:00:13 +0900 Subject: [PATCH 10/21] =?UTF-8?q?[MOD]=20#307=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=ED=9B=84=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EB=B0=9C=EA=B2=AC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B0=B1=EC=8B=A0=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/runnect/runnect/presentation/MainActivity.kt | 2 +- .../runnect/runnect/presentation/discover/DiscoverFragment.kt | 4 ++-- .../discover/adapter/multiview/DiscoverMultiViewHolder.kt | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/MainActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/MainActivity.kt index 161bee765..7bef940ae 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/MainActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/MainActivity.kt @@ -149,7 +149,7 @@ class MainActivity : BindingActivity(R.layout.activity_main var storageScrapFragment: StorageScrapFragment? = null fun updateCourseDiscoverScreen() { - discoverFragment?.getRecommendCourses() + discoverFragment?.refreshDiscoverCourses() } fun updateStorageScrapScreen() { diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index bb12b5113..6bd052380 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -469,8 +469,8 @@ class DiscoverFragment : BindingFragment(R.layout.fragm return layoutManager.findFirstCompletelyVisibleItemPosition() > 0 } - fun getRecommendCourses() { - viewModel.getRecommendCourses() + fun refreshDiscoverCourses() { + viewModel.refreshDiscoverCourses() } override fun onAttach(context: Context) { diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index 4ee70e09c..16f17a823 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -82,7 +82,6 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : } fun bind(courses: List) { - Timber.d("추천 코스 리스트 크기: ${courses.size}") initRecommendRecyclerView(courses) initSortButtonClickListener() } From ed203de14f6f80d71824dd9cdaba2a5beda05daa Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 17:54:24 +0900 Subject: [PATCH 11/21] =?UTF-8?q?[FIX]=20#307=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EB=B0=9C=EA=B2=AC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A6=AC?= =?UTF-8?q?=ED=94=84=EB=A0=88=EC=8B=9C=20=ED=95=98=EB=A9=B4=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EA=B8=B0=EC=A4=80=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 1 - .../discover/DiscoverViewModel.kt | 11 +++++--- .../multiview/DiscoverMultiViewHolder.kt | 25 +++++++++++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index 6bd052380..cae8836e3 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -141,7 +141,6 @@ class DiscoverFragment : BindingFragment(R.layout.fragm ViewPager2.OnPageChangeCallback() { override fun onPageSelected(position: Int) { super.onPageSelected(position) - Timber.d("viewpager position: $position") updateBannerPosition(position) updateBannerIndicatorPosition() } diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 9ed60a634..54d86f5bb 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -65,13 +65,18 @@ class DiscoverViewModel @Inject constructor( fun refreshDiscoverCourses() { getMarathonCourses() + initRecommendCoursePagingData() + initRecommendCourseSortCriteria() getRecommendCourses() } private fun initRecommendCoursePagingData() { isRecommendCoursePageEnd = false currentPageNumber = FIRST_PAGE_NUM + } + + private fun initRecommendCourseSortCriteria() { currentSortCriteria = DEFAULT_SORT_CRITERIA } @@ -111,7 +116,7 @@ class DiscoverViewModel @Inject constructor( } } - fun getRecommendCourses() { + private fun getRecommendCourses() { viewModelScope.launch { _recommendCourseGetState.value = UiStateV2.Loading @@ -169,7 +174,7 @@ class DiscoverViewModel @Inject constructor( fun sortRecommendCourses(criteria: String) { initRecommendCoursePagingData() - saveCurrentSortCriteria(criteria) + updateCurrentSortCriteria(criteria) viewModelScope.launch { _recommendCourseSortState.value = UiStateV2.Loading @@ -194,7 +199,7 @@ class DiscoverViewModel @Inject constructor( } } - private fun saveCurrentSortCriteria(criteria: String) { + private fun updateCurrentSortCriteria(criteria: String) { currentSortCriteria = criteria } diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index 16f17a823..ab700b119 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -13,13 +13,10 @@ import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.MarathonCourse import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.RecommendCourse import com.runnect.runnect.presentation.discover.adapter.DiscoverMarathonAdapter import com.runnect.runnect.presentation.discover.adapter.DiscoverRecommendAdapter -import com.runnect.runnect.presentation.discover.model.EditableDiscoverCourse import com.runnect.runnect.util.custom.deco.DiscoverMarathonItemDecoration import com.runnect.runnect.util.custom.deco.DiscoverRecommendItemDecoration -import com.runnect.runnect.util.custom.deco.GridSpacingItemDecoration import com.runnect.runnect.util.extension.colorOf import com.runnect.runnect.util.extension.fontOf -import timber.log.Timber sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) { @@ -83,6 +80,7 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : fun bind(courses: List) { initRecommendRecyclerView(courses) + initSortButtonTextStyle() initSortButtonClickListener() } @@ -110,6 +108,17 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : ) } } + + private fun initSortButtonTextStyle() { + binding.tvDiscoverRecommendSortByDate.apply { + activateTextStyle(view = this, context = this.context) + } + + binding.tvDiscoverRecommendSortByScrap.apply { + deactivateTextStyle(view = this, context = this.context) + } + } + private fun initSortButtonClickListener() { initSortByDateClickListener() initSortByScrapClickListener() @@ -118,13 +127,11 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : private fun initSortByDateClickListener() { binding.tvDiscoverRecommendSortByDate.setOnClickListener { val context = it.context ?: return@setOnClickListener - activateTextStyle(view = it as TextView, context = context) - deactivateOtherTextStyle( + deactivateTextStyle( view = binding.tvDiscoverRecommendSortByScrap, context = context ) - onSortButtonClick.invoke(SORT_BY_DATE) } } @@ -132,13 +139,11 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : private fun initSortByScrapClickListener() { binding.tvDiscoverRecommendSortByScrap.setOnClickListener { val context = it.context ?: return@setOnClickListener - activateTextStyle(view = it as TextView, context = context) - deactivateOtherTextStyle( + deactivateTextStyle( view = binding.tvDiscoverRecommendSortByDate, context = context ) - onSortButtonClick.invoke(SORT_BY_SCRAP) } } @@ -148,7 +153,7 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : view.typeface = context.fontOf(R.font.pretendard_semibold, Typeface.NORMAL) } - private fun deactivateOtherTextStyle(view: TextView, context: Context) { + private fun deactivateTextStyle(view: TextView, context: Context) { view.setTextColor(context.colorOf(R.color.G2)) view.typeface = context.fontOf(R.font.pretendard_regular, Typeface.NORMAL) } From ff6c2ced1fccb5a9122ae9a1368b614f7f960b90 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 24 Jan 2024 18:09:33 +0900 Subject: [PATCH 12/21] =?UTF-8?q?[MOD]=20#307=20=EB=8B=A4=EC=9D=8C=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/presentation/discover/DiscoverFragment.kt | 1 - .../presentation/discover/adapter/DiscoverRecommendAdapter.kt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index cae8836e3..561d22122 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -102,7 +102,6 @@ class DiscoverFragment : BindingFragment(R.layout.fragm } ).apply { binding.rvDiscoverMultiView.adapter = this - binding.rvDiscoverMultiView.setHasFixedSize(true) } } 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 d24e2fbf2..89996c7ba 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 @@ -90,8 +90,7 @@ class DiscoverRecommendAdapter( } fun addRecommendCourseNextPage(items: List) { - val newList = currentList.toMutableList() - newList.addAll(items) + val newList = currentList + items submitList(newList) } From 036a39afca5067828012743c8d683389634968fd Mon Sep 17 00:00:00 2001 From: leeeha Date: Mon, 5 Feb 2024 18:03:22 +0900 Subject: [PATCH 13/21] =?UTF-8?q?[FIX]=20#307=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=EB=A6=AC=EC=82=AC=EC=9D=B4=ED=81=B4=EB=9F=AC=EB=B7=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20submitList=20=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover/adapter/DiscoverRecommendAdapter.kt | 7 ++++--- .../discover/adapter/multiview/DiscoverMultiViewAdapter.kt | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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 89996c7ba..73ff01a0c 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 @@ -90,12 +90,13 @@ class DiscoverRecommendAdapter( } fun addRecommendCourseNextPage(items: List) { - val newList = currentList + items - submitList(newList) + notifyItemRangeInserted(itemCount - 1, items.size) + Timber.d("item count in inner recyclerview: ${items.size} ${itemCount}") } fun updateRecommendCourseBySorting(items: List) { - submitList(items) + notifyDataSetChanged() + Timber.d("item count in inner recyclerview: ${items.size} ${itemCount}") } companion object { 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 3604d78cb..c64408195 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 @@ -92,6 +92,8 @@ class DiscoverMultiViewAdapter( fun addRecommendCourseNextPage(items: List) { recommendCourses.addAll(items) + Timber.d("item count in outer recyclerview: ${items.size} ${recommendCourses.size}") + multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(items) } @@ -100,6 +102,8 @@ class DiscoverMultiViewAdapter( clear() addAll(items) } + Timber.d("item count in outer recyclerview: ${items.size} ${recommendCourses.size}") + multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(items) } From 12ab35345f7acc7fba372be98315be54dd5dc6bc Mon Sep 17 00:00:00 2001 From: leeeha Date: Mon, 5 Feb 2024 18:21:59 +0900 Subject: [PATCH 14/21] =?UTF-8?q?[CHORE]=20#307=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=BD=94=EC=8A=A4=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B8=EC=9E=90=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 전체 페이지 데이터가 아니라 일부 페이지 데이터임을 명확하게 알 수 있도록 --- .../discover/adapter/DiscoverRecommendAdapter.kt | 10 +++++----- .../multiview/DiscoverMultiViewAdapter.kt | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) 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 73ff01a0c..2844e9181 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 @@ -89,14 +89,14 @@ class DiscoverRecommendAdapter( notifyItemChanged(targetIndex) } - fun addRecommendCourseNextPage(items: List) { - notifyItemRangeInserted(itemCount - 1, items.size) - Timber.d("item count in inner recyclerview: ${items.size} ${itemCount}") + fun addRecommendCourseNextPage(nextPageItems: List) { + notifyItemRangeInserted(itemCount - 1, nextPageItems.size) + Timber.d("item count in inner recyclerview: ${nextPageItems.size} ${itemCount}") } - fun updateRecommendCourseBySorting(items: List) { + fun updateRecommendCourseBySorting(firstPageItems: List) { notifyDataSetChanged() - Timber.d("item count in inner recyclerview: ${items.size} ${itemCount}") + Timber.d("item count in inner recyclerview: ${firstPageItems.size} ${itemCount}") } companion object { 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 c64408195..ee4cf042f 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 @@ -90,21 +90,21 @@ class DiscoverMultiViewAdapter( return viewTypes.indexOfFirst { viewType == it } } - fun addRecommendCourseNextPage(items: List) { - recommendCourses.addAll(items) - Timber.d("item count in outer recyclerview: ${items.size} ${recommendCourses.size}") + fun addRecommendCourseNextPage(nextPageItems: List) { + recommendCourses.addAll(nextPageItems) + Timber.d("item count in outer recyclerview: ${nextPageItems.size} ${recommendCourses.size}") - multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(items) + multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(nextPageItems) } - fun updateRecommendCourseBySorting(items: List) { + fun updateRecommendCourseBySorting(firstPageItems: List) { recommendCourses.apply { clear() - addAll(items) + addAll(firstPageItems) } - Timber.d("item count in outer recyclerview: ${items.size} ${recommendCourses.size}") + Timber.d("item count in outer recyclerview: ${firstPageItems.size} ${recommendCourses.size}") - multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(items) + multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(firstPageItems) } fun updateCourseItem( From b2ecbfe598d0a5b891cbd0a51eea87dbb4f9a072 Mon Sep 17 00:00:00 2001 From: leeeha Date: Tue, 6 Feb 2024 15:54:21 +0900 Subject: [PATCH 15/21] =?UTF-8?q?[FIX]=20#307=20=EC=99=B8=EB=B6=80?= =?UTF-8?q?=EC=99=80=20=EB=82=B4=EB=B6=80=20=EB=A6=AC=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=ED=81=B4=EB=9F=AC=EB=B7=B0=EC=97=90=EC=84=9C=20=EC=84=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=8B=A4=EB=A5=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B9=8A=EC=9D=80=20=EB=B3=B5=EC=82=AC=20=EC=88=98=ED=96=89?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/DiscoverRecommendAdapter.kt | 26 +++++++++++++++---- .../multiview/DiscoverMultiViewAdapter.kt | 8 +++--- 2 files changed, 24 insertions(+), 10 deletions(-) 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 2844e9181..3372a32c6 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 @@ -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( @@ -90,18 +91,33 @@ class DiscoverRecommendAdapter( } fun addRecommendCourseNextPage(nextPageItems: List) { - 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) { - 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( - onItemsTheSame = { old, new -> old.id == new.id }, + onItemsTheSame = { old, new -> old === new }, onContentsTheSame = { old, new -> old == new } ) } 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 ee4cf042f..85a5805a3 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 @@ -36,7 +36,9 @@ class DiscoverMultiViewAdapter( } is DiscoverMultiViewHolder.RecommendCourseViewHolder -> { - holder.bind(recommendCourses) + // 내부 리사이클러뷰에서는 완전히 새로운 리스트를 참조하도록 깊은 복사 수행 + val newList = recommendCourses.map { it.copy() }.toList() + holder.bind(newList) } } } @@ -92,8 +94,6 @@ class DiscoverMultiViewAdapter( fun addRecommendCourseNextPage(nextPageItems: List) { recommendCourses.addAll(nextPageItems) - Timber.d("item count in outer recyclerview: ${nextPageItems.size} ${recommendCourses.size}") - multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(nextPageItems) } @@ -102,8 +102,6 @@ class DiscoverMultiViewAdapter( clear() addAll(firstPageItems) } - Timber.d("item count in outer recyclerview: ${firstPageItems.size} ${recommendCourses.size}") - multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(firstPageItems) } From 0e7333d4074ba51eff9f63f63439bb9061575274 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 7 Feb 2024 23:06:19 +0900 Subject: [PATCH 16/21] =?UTF-8?q?[REFACTOR]=20#307=20=EC=99=B8=EB=B6=80=20?= =?UTF-8?q?=EB=A6=AC=EC=82=AC=EC=9D=B4=ED=81=B4=EB=9F=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=96=B4=EB=8C=91=ED=84=B0=EC=97=90=EC=84=9C=EB=8A=94=20?= =?UTF-8?q?=EC=B6=94=EC=B2=9C=20=EC=BD=94=EC=8A=A4=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=EC=9E=91=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 2 +- .../adapter/DiscoverMarathonAdapter.kt | 13 ++++--- .../adapter/DiscoverRecommendAdapter.kt | 16 +++++---- .../multiview/DiscoverMultiViewAdapter.kt | 34 +++---------------- 4 files changed, 23 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index bf3af0050..3dfe671c2 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -411,7 +411,7 @@ class DiscoverFragment : BindingFragment(R.layout.fragm viewModel.recommendCourseSortState.observe(viewLifecycleOwner) { state -> when (state) { is UiStateV2.Success -> { - multiViewAdapter.updateRecommendCourseBySorting(state.data) + multiViewAdapter.sortRecommendCourseFirstPage(state.data) } is UiStateV2.Failure -> { 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 1e3f57f7e..c07b49b5d 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 @@ -78,14 +78,17 @@ class DiscoverMarathonAdapter( } fun updateMarathonCourseItem( - targetIndex: Int, + publicCourseId: Int, updatedCourse: EditableDiscoverCourse ) { - currentList[targetIndex].apply { - title = updatedCourse.title - scrap = updatedCourse.scrap + currentList.forEachIndexed { index, course -> + if (course.id == publicCourseId) { + course.title = updatedCourse.title + course.scrap = updatedCourse.scrap + notifyItemChanged(index) + return + } } - notifyItemChanged(targetIndex) } 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 3372a32c6..f12119923 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 @@ -11,7 +11,6 @@ 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( @@ -80,14 +79,17 @@ class DiscoverRecommendAdapter( } fun updateRecommendCourseItem( - targetIndex: Int, + publicCourseId: Int, updatedCourse: EditableDiscoverCourse ) { - currentList[targetIndex].apply { - title = updatedCourse.title - scrap = updatedCourse.scrap + currentList.forEachIndexed { index, course -> + if (course.id == publicCourseId) { + course.title = updatedCourse.title + course.scrap = updatedCourse.scrap + notifyItemChanged(index) + return + } } - notifyItemChanged(targetIndex) } fun addRecommendCourseNextPage(nextPageItems: List) { @@ -101,7 +103,7 @@ class DiscoverRecommendAdapter( } } - fun updateRecommendCourseBySorting(firstPageItems: List) { + fun sortRecommendCourseFirstPage(firstPageItems: List) { Timber.d("before item count : $itemCount") val newList = currentList.toMutableList() 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 85a5805a3..5a0c60911 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 @@ -5,7 +5,6 @@ import androidx.recyclerview.widget.RecyclerView import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.MarathonCourse import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.RecommendCourse import com.runnect.runnect.presentation.discover.model.EditableDiscoverCourse -import timber.log.Timber class DiscoverMultiViewAdapter( private val onHeartButtonClick: (Int, Boolean) -> Unit, @@ -93,43 +92,20 @@ class DiscoverMultiViewAdapter( } fun addRecommendCourseNextPage(nextPageItems: List) { - recommendCourses.addAll(nextPageItems) multiViewHolderFactory.recommendCourseAdapter.addRecommendCourseNextPage(nextPageItems) } - fun updateRecommendCourseBySorting(firstPageItems: List) { - recommendCourses.apply { - clear() - addAll(firstPageItems) - } - multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseBySorting(firstPageItems) + fun sortRecommendCourseFirstPage(firstPageItems: List) { + multiViewHolderFactory.recommendCourseAdapter.sortRecommendCourseFirstPage(firstPageItems) } fun updateCourseItem( publicCourseId: Int, updatedCourse: EditableDiscoverCourse ) { - val multiViewItems = marathonCourses + recommendCourses - val targetItem = multiViewItems.find { item -> - item.id == publicCourseId - } ?: return - - when (targetItem) { - is MarathonCourse -> { - val targetIndex = marathonCourses.indexOf(targetItem) - multiViewHolderFactory.marathonCourseAdapter.updateMarathonCourseItem( - targetIndex = targetIndex, - updatedCourse = updatedCourse - ) - } - - is RecommendCourse -> { - val targetIndex = recommendCourses.indexOf(targetItem) - multiViewHolderFactory.recommendCourseAdapter.updateRecommendCourseItem( - targetIndex = targetIndex, - updatedCourse = updatedCourse - ) - } + multiViewHolderFactory.apply { + marathonCourseAdapter.updateMarathonCourseItem(publicCourseId, updatedCourse) + recommendCourseAdapter.updateRecommendCourseItem(publicCourseId, updatedCourse) } } } \ No newline at end of file From 51d91cfc3e11378630aab760bc9d0bae0016a675 Mon Sep 17 00:00:00 2001 From: leeeha Date: Wed, 7 Feb 2024 23:24:52 +0900 Subject: [PATCH 17/21] =?UTF-8?q?[MOD]=20#307=20=EB=8B=A4=EC=9D=8C=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=9A=94=EC=B2=AD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=A1=B0=EA=B1=B4=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EB=82=B4=EC=9A=A9=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/discover/DiscoverFragment.kt | 15 +++++---------- .../presentation/discover/DiscoverViewModel.kt | 10 +++++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index 3dfe671c2..1b7e9d361 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -40,7 +40,6 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import timber.log.Timber @AndroidEntryPoint class DiscoverFragment : BindingFragment(R.layout.fragment_discover) { @@ -192,19 +191,15 @@ class DiscoverFragment : BindingFragment(R.layout.fragm val isScrollDown = dy > 0 if (isScrollDown) showCircleUploadButton() - checkNextPageLoadingCondition(recyclerView) + if (checkNextPageLoadingCondition(recyclerView)) { + viewModel.getRecommendCourseNextPage() + } } }) } - private fun checkNextPageLoadingCondition(recyclerView: RecyclerView) { - if (isCourseLoadingCompleted() && !recyclerView.canScrollVertically(SCROLL_DIRECTION)) { - Timber.d("스크롤이 끝에 도달했어요!") - if (!viewModel.isNextPageLoading()) { - viewModel.getRecommendCourseNextPage() - } - } - } + private fun checkNextPageLoadingCondition(recyclerView: RecyclerView) = + isCourseLoadingCompleted() && !recyclerView.canScrollVertically(SCROLL_DIRECTION) && !viewModel.isNextPageLoading() private fun isCourseLoadingCompleted() = ::multiViewAdapter.isInitialized && multiViewAdapter.itemCount >= DiscoverMultiViewType.values().size diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 54d86f5bb..273e44d9c 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -144,14 +144,14 @@ class DiscoverViewModel @Inject constructor( fun getRecommendCourseNextPage() { viewModelScope.launch { + // 다음 페이지가 없으면 요청하지 않는다. if (isRecommendCoursePageEnd) return@launch Timber.d("다음 페이지를 요청했어요! 정렬 기준: $currentSortCriteria") _recommendCourseNextPageState.value = UiStateV2.Loading - currentPageNumber++ courseRepository.getRecommendCourse( - pageNo = currentPageNumber.toString(), + pageNo = (currentPageNumber + 1).toString(), sort = currentSortCriteria ) .onSuccess { pagingData -> @@ -161,12 +161,16 @@ class DiscoverViewModel @Inject constructor( return@onSuccess } + // 전역변수 업데이트 isRecommendCoursePageEnd = pagingData.isEnd + currentPageNumber++ + _recommendCourseNextPageState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE NEXT PAGE GET SUCCESS") } .onFailure { exception -> - _recommendCourseNextPageState.value = UiStateV2.Failure(exception.message.toString()) + _recommendCourseNextPageState.value = + UiStateV2.Failure(exception.message.toString()) Timber.e("RECOMMEND COURSE NEXT PAGE GET FAIL") } } From fe29a6e7d514fa9b04702cdcb7af70725207e945 Mon Sep 17 00:00:00 2001 From: leeeha Date: Fri, 9 Feb 2024 19:13:08 +0900 Subject: [PATCH 18/21] =?UTF-8?q?[MOD]=20#307=20=EB=B7=B0=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=EC=97=90=EC=84=9C=20=EC=B6=94=EC=B2=9C=EC=BD=94?= =?UTF-8?q?=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20=EC=A0=84=EC=97=AD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EA=B0=B1=EC=8B=A0=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover/DiscoverViewModel.kt | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 273e44d9c..4dd79c988 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -65,19 +65,21 @@ class DiscoverViewModel @Inject constructor( fun refreshDiscoverCourses() { getMarathonCourses() - - initRecommendCoursePagingData() - initRecommendCourseSortCriteria() + updateRecommendCourseSortCriteria( + criteria = DEFAULT_SORT_CRITERIA + ) getRecommendCourses() } - private fun initRecommendCoursePagingData() { - isRecommendCoursePageEnd = false - currentPageNumber = FIRST_PAGE_NUM + private fun updateRecommendCoursePagingData(isEnd: Boolean, pageNo: Int) { + isRecommendCoursePageEnd = isEnd + currentPageNumber = pageNo + Timber.d("isEnd: ${isRecommendCoursePageEnd}, page: ${currentPageNumber}") } - private fun initRecommendCourseSortCriteria() { - currentSortCriteria = DEFAULT_SORT_CRITERIA + private fun updateRecommendCourseSortCriteria(criteria: String) { + currentSortCriteria = criteria + Timber.d("sort: ${currentSortCriteria}") } private fun getDiscoverBanners() { @@ -122,7 +124,7 @@ class DiscoverViewModel @Inject constructor( courseRepository.getRecommendCourse( pageNo = FIRST_PAGE_NUM.toString(), - sort = DEFAULT_SORT_CRITERIA + sort = currentSortCriteria ).onSuccess { pagingData -> if (pagingData == null) { _recommendCourseGetState.value = @@ -130,9 +132,14 @@ class DiscoverViewModel @Inject constructor( return@onSuccess } - isRecommendCoursePageEnd = pagingData.isEnd _recommendCourseGetState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE GET SUCCESS") + + updateRecommendCoursePagingData( + isEnd = pagingData.isEnd, + pageNo = FIRST_PAGE_NUM + ) + }.onFailure { exception -> _recommendCourseGetState.value = UiStateV2.Failure(exception.message.toString()) Timber.e("RECOMMEND COURSE GET FAIL") @@ -147,7 +154,6 @@ class DiscoverViewModel @Inject constructor( // 다음 페이지가 없으면 요청하지 않는다. if (isRecommendCoursePageEnd) return@launch - Timber.d("다음 페이지를 요청했어요! 정렬 기준: $currentSortCriteria") _recommendCourseNextPageState.value = UiStateV2.Loading courseRepository.getRecommendCourse( @@ -161,9 +167,10 @@ class DiscoverViewModel @Inject constructor( return@onSuccess } - // 전역변수 업데이트 - isRecommendCoursePageEnd = pagingData.isEnd - currentPageNumber++ + updateRecommendCoursePagingData( + isEnd = pagingData.isEnd, + pageNo = currentPageNumber + 1 + ) _recommendCourseNextPageState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE NEXT PAGE GET SUCCESS") @@ -177,15 +184,14 @@ class DiscoverViewModel @Inject constructor( } fun sortRecommendCourses(criteria: String) { - initRecommendCoursePagingData() - updateCurrentSortCriteria(criteria) + updateRecommendCourseSortCriteria(criteria) viewModelScope.launch { _recommendCourseSortState.value = UiStateV2.Loading courseRepository.getRecommendCourse( pageNo = FIRST_PAGE_NUM.toString(), - sort = criteria + sort = currentSortCriteria ).onSuccess { pagingData -> if (pagingData == null) { _recommendCourseSortState.value = @@ -193,7 +199,11 @@ class DiscoverViewModel @Inject constructor( return@onSuccess } - isRecommendCoursePageEnd = pagingData.isEnd + updateRecommendCoursePagingData( + isEnd = pagingData.isEnd, + pageNo = FIRST_PAGE_NUM + ) + _recommendCourseSortState.value = UiStateV2.Success(pagingData.recommendCourses) Timber.d("RECOMMEND COURSE SORT SUCCESS") }.onFailure { exception -> @@ -203,10 +213,6 @@ class DiscoverViewModel @Inject constructor( } } - private fun updateCurrentSortCriteria(criteria: String) { - currentSortCriteria = criteria - } - fun postCourseScrap(id: Int, scrapTF: Boolean) { viewModelScope.launch { _courseScrapState.value = UiStateV2.Loading From 760df349cc9e5598375ae285a53dbfb3b4031af9 Mon Sep 17 00:00:00 2001 From: leeeha Date: Fri, 9 Feb 2024 19:59:01 +0900 Subject: [PATCH 19/21] =?UTF-8?q?[CHORE]=20#307=20getRecommendCourses=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EC=97=90=EC=84=9C=20=EC=A0=84=EC=97=AD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EA=B0=B1=EC=8B=A0=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=8B=9C=EC=A0=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/presentation/discover/DiscoverViewModel.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt index 4dd79c988..f74624510 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverViewModel.kt @@ -132,14 +132,14 @@ class DiscoverViewModel @Inject constructor( return@onSuccess } - _recommendCourseGetState.value = UiStateV2.Success(pagingData.recommendCourses) - Timber.d("RECOMMEND COURSE GET SUCCESS") - updateRecommendCoursePagingData( isEnd = pagingData.isEnd, pageNo = FIRST_PAGE_NUM ) + _recommendCourseGetState.value = UiStateV2.Success(pagingData.recommendCourses) + Timber.d("RECOMMEND COURSE GET SUCCESS") + }.onFailure { exception -> _recommendCourseGetState.value = UiStateV2.Failure(exception.message.toString()) Timber.e("RECOMMEND COURSE GET FAIL") From 0dce6cfb007ab89951923a2b4d181d170296309b Mon Sep 17 00:00:00 2001 From: leeeha Date: Sat, 10 Feb 2024 15:45:25 +0900 Subject: [PATCH 20/21] =?UTF-8?q?[ADD]=20#307=20=EC=8A=A4=EC=99=80?= =?UTF-8?q?=EC=9D=B4=ED=94=84=20=EB=A6=AC=ED=94=84=EB=A0=88=EC=8B=9C=20?= =?UTF-8?q?=EC=A7=81=ED=9B=84=EC=97=90=20=EA=B0=81=20=EB=A9=80=ED=8B=B0?= =?UTF-8?q?=EB=B7=B0=20=ED=83=80=EC=9E=85=EC=9D=98=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EB=B9=84=EC=9A=B0=EA=B3=A0=20notify=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/presentation/discover/DiscoverFragment.kt | 8 +++++++- .../discover/adapter/multiview/DiscoverMultiViewHolder.kt | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index 1b7e9d361..595a20b48 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -223,6 +223,9 @@ class DiscoverFragment : BindingFragment(R.layout.fragm private fun initRefreshLayoutListener() { binding.refreshLayout.setOnRefreshListener { + multiViewAdapter.initMarathonCourses(emptyList()) + multiViewAdapter.initRecommendCourses(emptyList()) + viewModel.refreshDiscoverCourses() binding.refreshLayout.isRefreshing = false } @@ -354,8 +357,11 @@ class DiscoverFragment : BindingFragment(R.layout.fragm is UiStateV2.Loading -> showLoadingProgressBar() is UiStateV2.Success -> { - dismissLoadingProgressBar() + // todo: 리프레시에 의한 추천코스 어댑터의 submitList 동작이 완료되고 나서 multiViewAdapter.initRecommendCourses(state.data) + + // todo: 로딩 프로그레스바를 삭제해야 한다. + dismissLoadingProgressBar() } is UiStateV2.Failure -> { diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt index ab700b119..5d480ce10 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/adapter/multiview/DiscoverMultiViewHolder.kt @@ -17,6 +17,7 @@ import com.runnect.runnect.util.custom.deco.DiscoverMarathonItemDecoration import com.runnect.runnect.util.custom.deco.DiscoverRecommendItemDecoration import com.runnect.runnect.util.extension.colorOf import com.runnect.runnect.util.extension.fontOf +import timber.log.Timber sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) { @@ -88,7 +89,10 @@ sealed class DiscoverMultiViewHolder(binding: ViewDataBinding) : binding.rvDiscoverRecommend.apply { layoutManager = GridLayoutManager(context, 2) adapter = recommendAdapter.apply { - submitList(courses) + Timber.e("refresh before item count: ${itemCount}") + submitList(courses) { + Timber.e("refresh after item count: ${itemCount}") + } } addItemDecorationOnlyOnce(this) } From 2632907d339889b09e7c602ac718beeef966c7d5 Mon Sep 17 00:00:00 2001 From: leeeha Date: Sat, 10 Feb 2024 15:50:15 +0900 Subject: [PATCH 21/21] =?UTF-8?q?[ADD]=20#307=20=EB=A6=AC=ED=94=84?= =?UTF-8?q?=EB=A0=88=EC=8B=9C=20=EA=B4=80=EB=A0=A8=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/presentation/discover/DiscoverFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt index 595a20b48..7141c91eb 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/discover/DiscoverFragment.kt @@ -223,9 +223,11 @@ class DiscoverFragment : BindingFragment(R.layout.fragm private fun initRefreshLayoutListener() { binding.refreshLayout.setOnRefreshListener { + // 리프레시 직후에 비어있는 리스트로 리사이클러뷰 초기화 multiViewAdapter.initMarathonCourses(emptyList()) multiViewAdapter.initRecommendCourses(emptyList()) + // 서버통신 직후에 첫 페이지 데이터로 리사이클러뷰 초기화 viewModel.refreshDiscoverCourses() binding.refreshLayout.isRefreshing = false }