Skip to content

Commit

Permalink
Merge pull request #298 from Scents-Note/fix/251-home
Browse files Browse the repository at this point in the history
[fix] 최근 본 향수 버그 수정
  • Loading branch information
Haeeul authored Feb 13, 2024
2 parents a028fa6 + 9242a2c commit 302952f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ interface RemoteDataSource {
suspend fun getRecommendPerfumeList(token: String) : MutableList<RecommendPerfumeItem>
suspend fun getCommonPerfumeList(token: String) : MutableList<HomePerfumeItem>
suspend fun getRecentPerfumeList(token: String) : MutableList<HomePerfumeItem>
suspend fun getNewPerfumeList() : MutableList<HomePerfumeItem>
suspend fun getNewPerfumeList(requestSize: Int?) : MutableList<HomePerfumeItem>
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class RemoteDataSourceImpl : RemoteDataSource{
return api.getRecentList(token).data.rows
}

override suspend fun getNewPerfumeList(): MutableList<HomePerfumeItem> {
return api.getNewPerfumeList().data.rows
override suspend fun getNewPerfumeList(requestSize: Int?): MutableList<HomePerfumeItem> {
return api.getNewPerfumeList(requestSize).data.rows
}

override suspend fun getReview(reviewIdx: Int): ResponseReview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ interface ScentsNoteService {
// Home - New Perfume List
@GET("perfume/new")
suspend fun getNewPerfumeList(

@Query("requestSize") requestSize : Int?
):ResponseBase<ResponseHomePerfumeList>

@GET("perfume/{perfumeIdx}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeRepository {
suspend fun getRecommendPerfumeList(token : String) = remoteDataSource.getRecommendPerfumeList(token)
suspend fun getCommonPerfumeList(token : String) = remoteDataSource.getCommonPerfumeList(token)
suspend fun getRecentPerfumeList(token : String) = remoteDataSource.getRecentPerfumeList(token)
suspend fun getNewPerfumeList() = remoteDataSource.getNewPerfumeList()
suspend fun getNewPerfumeList(requestSize: Int?) = remoteDataSource.getNewPerfumeList(requestSize)
fun postPerfumeLike(token: String, perfumeIdx: Int): Single<ResponseBase<Boolean>> =
ScentsNoteServiceImpl.service.postPerfumeLike(token, perfumeIdx).map { it }
}
24 changes: 18 additions & 6 deletions app/src/main/java/com/scentsnote/android/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.scentsnote.android.ScentsNoteApplication
import com.scentsnote.android.R
import com.scentsnote.android.ScentsNoteApplication.Companion.firebaseAnalytics
Expand All @@ -22,6 +24,7 @@ import com.scentsnote.android.utils.extension.setHeartBtnClickEvent
import com.scentsnote.android.viewmodel.home.HomeViewModel
import com.scentsnote.android.utils.extension.setOnSafeClickListener
import com.scentsnote.android.utils.extension.setPageViewEvent
import kotlinx.coroutines.launch
import java.util.*

/**
Expand Down Expand Up @@ -60,7 +63,7 @@ class HomeFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

observe()
initObserve()

initRecommendList()
initPopularList()
Expand All @@ -71,8 +74,11 @@ class HomeFragment : Fragment() {
override fun onResume() {
super.onResume()

viewLifecycleOwner.lifecycleScope.launchWhenCreated {
homeViewModel.getHomePerfumeList()
viewLifecycleOwner.lifecycleScope.launch {
homeViewModel.run {
getHomePerfumeList()
getNewPerfumeList(10)
}
}

firebaseAnalytics.setPageViewEvent("HomePage",this::class.java.name)
Expand Down Expand Up @@ -135,16 +141,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 @@ -6,6 +6,9 @@ import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.scentsnote.android.R
import com.scentsnote.android.ScentsNoteApplication.Companion.firebaseAnalytics
import com.scentsnote.android.databinding.ActivityMoreNewPerfumeBinding
Expand All @@ -14,6 +17,7 @@ import com.scentsnote.android.viewmodel.home.HomeViewModel
import com.scentsnote.android.utils.base.BaseWebViewActivity
import com.scentsnote.android.utils.extension.setHeartBtnClickEvent
import com.scentsnote.android.utils.extension.setPageViewEvent
import kotlinx.coroutines.launch

/**
* 홈 화면 - 새로운 향수 더보기
Expand All @@ -31,6 +35,10 @@ class MoreNewPerfumeActivity : AppCompatActivity() {
binding.lifecycleOwner = this
binding.viewModel = homeViewModel

lifecycleScope.launch {
homeViewModel.getNewPerfumeList(null)
}

initNewList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,14 @@ 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

init {
viewModelScope.launch {
getHomePerfumeList()
}
}

suspend fun getHomePerfumeList(){
getRecommendPerfumeList()
getCommonPerfumeList()
getRecentPerfumeList()
getNewPerfumeList()
}

private suspend fun getRecommendPerfumeList(){
Expand All @@ -73,22 +62,17 @@ 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())
}
}

private suspend fun getNewPerfumeList(){
suspend fun getNewPerfumeList(requestSize: Int?){
try{
_newPerfumeList.value = homeRepository.getNewPerfumeList()
_newPerfumeList.value = homeRepository.getNewPerfumeList(requestSize)
Log.d("getNewPerfumeList", _newPerfumeList.value.toString())
}catch (e : HttpException){
Log.d("getNewPerfumeList error", e.message())
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/background_white_circle_fill.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
</shape>
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
23 changes: 17 additions & 6 deletions app/src/main/res/layout/rv_item_home_recent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,32 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<de.hdodenhof.circleimageview.CircleImageView
<ImageView
android:id="@+id/act_perfume_detail_iv_write"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
setImage="@{item.imageUrl}"
android:src="@drawable/dummy_perfume_image"
app:civ_circle_background_color="@color/white"
android:background="@drawable/background_white_circle_fill"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/imageView57"
setImage="@{item.imageUrl}"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="@+id/act_perfume_detail_iv_write"
app:layout_constraintEnd_toEndOf="@+id/act_perfume_detail_iv_write"
app:layout_constraintStart_toStartOf="@+id/act_perfume_detail_iv_write"
app:layout_constraintTop_toTopOf="@+id/act_perfume_detail_iv_write"
bind:srcCompat="@drawable/dummy_perfume_image" />

<ImageView
android:id="@+id/btn_like"
setLikeList="@{item.isLiked}"
Expand Down

0 comments on commit 302952f

Please sign in to comment.