Skip to content

Commit

Permalink
[FIX/#236] 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Mar 10, 2024
1 parent 56a1256 commit 7142e8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.going.presentation.profile.participant

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.ProfilePreferenceData
import com.going.domain.entity.request.ParticipantProfileRequestModel
import com.going.domain.entity.response.ParticipantProfileResponseModel
import com.going.domain.repository.ProfileRepository
Expand Down Expand Up @@ -36,4 +37,12 @@ class ParticipantProfileViewModel @Inject constructor(
}
}
}

fun setPreferenceData(styleA: Int, styleB: Int, styleC: Int, styleD: Int, styleE: Int) = listOf(
ProfilePreferenceData("01", "계획은 어느 정도로 세울까요?", "철저하게", "즉흥으로", styleA),
ProfilePreferenceData("02", "장소 선택의 기준은 무엇인가요?", "관광지", "로컬장소", styleB),
ProfilePreferenceData("03", "어느 식당을 갈까요?", "유명 맛집", "가까운 곳", styleC),
ProfilePreferenceData("04", "기억하고 싶은 순간에!", "사진필수", "눈에 담기", styleD),
ProfilePreferenceData("05", "하루 일정을 어떻게 채우나요?", "알차게", "여유롭게", styleE)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.going.presentation.profile.participant.profiletag
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -25,8 +24,6 @@ class ParticipantProfileTagFragment :
ViewModelProvider(requireActivity())[ParticipantProfileViewModel::class.java]
}

private val tagViewModel by activityViewModels<ParticipantProfileTagViewModel>()

private var _adapter: ParticipantProfileTagAdapter? = null
private val adapter get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

Expand All @@ -36,14 +33,7 @@ class ParticipantProfileTagFragment :
initAdapter()
getPreferenceIndex()
initItemDecoration()
}

override fun onResume() {
super.onResume()

participantViewModel.participantProfile.flowWithLifecycle(lifecycle).onEach {
getPreferenceIndex()
}.launchIn(lifecycleScope)
observePreferenceChange()
}

private fun initAdapter() {
Expand All @@ -54,7 +44,7 @@ class ParticipantProfileTagFragment :
private fun getPreferenceIndex() {
participantViewModel.profileTmp.run {
adapter.submitList(
tagViewModel.setPreferenceData(
participantViewModel.setPreferenceData(
styleA,
styleB,
styleC,
Expand Down Expand Up @@ -97,6 +87,12 @@ class ParticipantProfileTagFragment :
binding.rvPreferenceTag.addItemDecoration(itemDeco)
}

private fun observePreferenceChange() {
participantViewModel.participantProfile.flowWithLifecycle(lifecycle).onEach {
getPreferenceIndex()
}.launchIn(lifecycleScope)
}

fun scrollTop() = binding.nsvPreferenceTag.scrollTo(0, 0)

}

0 comments on commit 7142e8a

Please sign in to comment.