Skip to content

Commit

Permalink
[fix] #251 최근 본 향수 표시 안되는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Haeeul committed Feb 5, 2024
1 parent aec01c3 commit f42895c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
14 changes: 10 additions & 4 deletions app/src/main/java/com/scentsnote/android/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HomeFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

observe()
initObserve()

initRecommendList()
initPopularList()
Expand Down Expand Up @@ -135,16 +135,22 @@ class HomeFragment : Fragment() {
binding.vpHomeRecommend.adapter = recommendAdapter
}

private fun observe() {
homeViewModel.recommendPerfumeList.observe(requireActivity(), androidx.lifecycle.Observer {
private fun initObserve() {
homeViewModel.recommendPerfumeList.observe(requireActivity()){

recommendAdapter.run {
replaceAll(ArrayList(it))
notifyDataSetChanged()
}

binding.indicatorHome.setViewPager(binding.vpHomeRecommend)
})
}

homeViewModel.recentPerfumeList.observe(requireActivity()) {
binding.clHomeRecent.visibility =
if(it.isNotEmpty()) View.VISIBLE
else View.GONE
}
}

private fun initPopularList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class HomeViewModel : ViewModel(){
val recentPerfumeList : LiveData<MutableList<HomePerfumeItem>>
get() = _recentPerfumeList

private val _isValidRecentList = MutableLiveData<Boolean>(true)
val isValidRecentList : LiveData<Boolean>
get() = _isValidRecentList

private val _newPerfumeList : MutableLiveData<MutableList<HomePerfumeItem>> = MutableLiveData()
val newPerfumeList : LiveData<MutableList<HomePerfumeItem>>
get() = _newPerfumeList
Expand Down Expand Up @@ -73,15 +69,10 @@ class HomeViewModel : ViewModel(){

private suspend fun getRecentPerfumeList(){
try{
_isValidRecentList.postValue(true)
_recentPerfumeList.value = homeRepository.getRecentPerfumeList(ScentsNoteApplication.prefManager.accessToken)
Log.d("getRecentPerfumeList", _recentPerfumeList.value.toString())

if(_recentPerfumeList.value!!.isEmpty()){
_isValidRecentList.postValue(false)
}
}catch (e : HttpException){
_isValidRecentList.postValue(false)
_recentPerfumeList.value = mutableListOf()
Log.d("getRecentPerfumeList error", e.message())
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:visibility="@{viewModel.isValidRecentList? View.VISIBLE : View.GONE}"
android:background="@color/light_gray_f9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down

0 comments on commit f42895c

Please sign in to comment.