diff --git a/data/src/main/java/co/orange/data/dto/response/ProductDto.kt b/data/src/main/java/co/orange/data/dto/response/ProductDto.kt index e4da0131..35f71abf 100644 --- a/data/src/main/java/co/orange/data/dto/response/ProductDto.kt +++ b/data/src/main/java/co/orange/data/dto/response/ProductDto.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable @Serializable data class ProductDto( @SerialName("productId") - val productId: Long, + val productId: String, @SerialName("kakaoProductId") val kakaoProductId: Long, @SerialName("name") diff --git a/domain/src/main/kotlin/co/orange/domain/entity/response/ProductModel.kt b/domain/src/main/kotlin/co/orange/domain/entity/response/ProductModel.kt index 39c682c4..36e5d45f 100644 --- a/domain/src/main/kotlin/co/orange/domain/entity/response/ProductModel.kt +++ b/domain/src/main/kotlin/co/orange/domain/entity/response/ProductModel.kt @@ -1,24 +1,11 @@ package co.orange.domain.entity.response data class ProductModel( - val productId: Long, + val productId: String, val kakaoProductId: Long, val name: String, val imgUrl: String, val originPrice: Int, val salePrice: Int, val interestCount: Int, -) { - companion object { - fun imageOnlyProductModel(imgUrl: String) = - ProductModel( - -1, - -1, - "", - imgUrl, - 0, - 0, - 0, - ) - } -} +) diff --git a/presentation/src/main/java/co/orange/presentation/detail/DetailActivity.kt b/presentation/src/main/java/co/orange/presentation/detail/DetailActivity.kt index 6b8bb98e..be68f3c5 100644 --- a/presentation/src/main/java/co/orange/presentation/detail/DetailActivity.kt +++ b/presentation/src/main/java/co/orange/presentation/detail/DetailActivity.kt @@ -107,7 +107,7 @@ class DetailActivity : BaseActivity(R.layout.activity_det @JvmStatic fun createIntent( context: Context, - productId: Long, + productId: String, productUrl: String, originPrice: Int, salePrice: Int, diff --git a/presentation/src/main/java/co/orange/presentation/main/home/HomeAdapter.kt b/presentation/src/main/java/co/orange/presentation/main/home/HomeAdapter.kt index 36dd6f21..77761fbc 100644 --- a/presentation/src/main/java/co/orange/presentation/main/home/HomeAdapter.kt +++ b/presentation/src/main/java/co/orange/presentation/main/home/HomeAdapter.kt @@ -16,6 +16,7 @@ class HomeAdapter( private val likeClick: (Unit) -> (Unit), ) : ListAdapter(diffUtil) { private var itemList = mutableListOf() + private var bannerItem: String? = null override fun onCreateViewHolder( parent: ViewGroup, @@ -52,7 +53,7 @@ class HomeAdapter( ) { when (holder) { is HomeBannerViewHolder -> { - if (itemList.isNotEmpty()) holder.onBind(itemList[0]) + bannerItem?.let { holder.onBind(it) } } is HomeProductViewHolder -> { @@ -73,8 +74,8 @@ class HomeAdapter( else -> VIEW_TYPE_PRODUCT } - fun addItemList(newItems: List) { - this.itemList.addAll(newItems) + fun addBannerItem(bannerUrl: String) { + this.bannerItem = bannerUrl notifyDataSetChanged() } @@ -83,14 +84,6 @@ class HomeAdapter( notifyDataSetChanged() } - fun removeItem(position: Int) { - if (this.itemList.isNotEmpty()) { - this.itemList.removeAt(position) - notifyItemRemoved(position + HEADER_COUNT) - notifyItemRangeChanged(position + HEADER_COUNT, itemCount) - } - } - companion object { private val diffUtil = ItemDiffCallback( diff --git a/presentation/src/main/java/co/orange/presentation/main/home/HomeBannerViewHolder.kt b/presentation/src/main/java/co/orange/presentation/main/home/HomeBannerViewHolder.kt index c80f3955..57c9ebfd 100644 --- a/presentation/src/main/java/co/orange/presentation/main/home/HomeBannerViewHolder.kt +++ b/presentation/src/main/java/co/orange/presentation/main/home/HomeBannerViewHolder.kt @@ -2,7 +2,6 @@ package co.orange.presentation.main.home import androidx.recyclerview.widget.RecyclerView import co.orange.core.extension.setOnSingleClickListener -import co.orange.domain.entity.response.ProductModel import coil.load import kr.genti.presentation.databinding.ItemHomeBannerBinding @@ -11,9 +10,9 @@ class HomeBannerViewHolder( val bannerClick: (Unit) -> (Unit), ) : RecyclerView.ViewHolder(binding.root) { - fun onBind(item: ProductModel) { + fun onBind(item: String) { with(binding) { - ivHomeBanner.load(item.imgUrl) + ivHomeBanner.load(item) root.setOnSingleClickListener { bannerClick } diff --git a/presentation/src/main/java/co/orange/presentation/main/home/HomeFragment.kt b/presentation/src/main/java/co/orange/presentation/main/home/HomeFragment.kt index 4f0039ae..9396ab1a 100644 --- a/presentation/src/main/java/co/orange/presentation/main/home/HomeFragment.kt +++ b/presentation/src/main/java/co/orange/presentation/main/home/HomeFragment.kt @@ -160,11 +160,15 @@ class HomeFragment() : BaseFragment(R.layout.fragment_home) private fun observeGetHomeDataState() { viewModel.getHomeDataState.flowWithLifecycle(lifecycle).onEach { state -> when (state) { - is UiState.Success -> adapter.setItemList(state.data) + is UiState.Success -> { + adapter.addBannerItem(state.data.homeImgUrl) + adapter.setItemList(state.data.productList) + } + is UiState.Failure -> toast(stringOf(R.string.error_msg)) else -> return@onEach } - } + }.launchIn(lifecycleScope) } override fun onDestroyView() { diff --git a/presentation/src/main/java/co/orange/presentation/main/home/HomeViewModel.kt b/presentation/src/main/java/co/orange/presentation/main/home/HomeViewModel.kt index fe3aba4a..76ed12c6 100644 --- a/presentation/src/main/java/co/orange/presentation/main/home/HomeViewModel.kt +++ b/presentation/src/main/java/co/orange/presentation/main/home/HomeViewModel.kt @@ -4,8 +4,7 @@ import android.net.Uri import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import co.orange.core.state.UiState -import co.orange.domain.entity.response.ProductModel -import co.orange.domain.entity.response.ProductModel.Companion.imageOnlyProductModel +import co.orange.domain.entity.response.HomeModel import co.orange.domain.repository.HomeRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -30,8 +29,8 @@ class HomeViewModel private val _isCheckedAgain = MutableSharedFlow() val isCheckedAgain: SharedFlow = _isCheckedAgain - private val _getHomeDataState = MutableStateFlow>>(UiState.Empty) - val getHomeDataState: StateFlow>> = _getHomeDataState + private val _getHomeDataState = MutableStateFlow>(UiState.Empty) + val getHomeDataState: StateFlow> = _getHomeDataState fun setCheckedState(state: Boolean) { viewModelScope.launch { @@ -43,12 +42,7 @@ class HomeViewModel viewModelScope.launch { homeRepository.getHomeData() .onSuccess { - val itemList = it.productList.toMutableList() - itemList.add( - 0, - imageOnlyProductModel(it.homeImgUrl), - ) - _getHomeDataState.value = UiState.Success(itemList) + _getHomeDataState.value = UiState.Success(it) } .onFailure { _getHomeDataState.value = UiState.Failure(it.message.toString()) diff --git a/presentation/src/main/java/co/orange/presentation/search/SearchViewModel.kt b/presentation/src/main/java/co/orange/presentation/search/SearchViewModel.kt index 484685e1..5ff5f31f 100644 --- a/presentation/src/main/java/co/orange/presentation/search/SearchViewModel.kt +++ b/presentation/src/main/java/co/orange/presentation/search/SearchViewModel.kt @@ -17,7 +17,7 @@ class SearchViewModel listOf("향수", "이승준", "곰인형", "성년의 날 선물", "멀티비타민"), listOf( ProductModel( - 1, + "1", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -26,7 +26,7 @@ class SearchViewModel 12, ), ProductModel( - 2, + "2", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -40,7 +40,7 @@ class SearchViewModel val mockItemList = listOf( ProductModel( - 1, + "1", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -49,7 +49,7 @@ class SearchViewModel 12, ), ProductModel( - 2, + "2", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -58,7 +58,7 @@ class SearchViewModel 34, ), ProductModel( - 3, + "3", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -67,7 +67,7 @@ class SearchViewModel 56, ), ProductModel( - 4, + "4", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -76,7 +76,7 @@ class SearchViewModel 78, ), ProductModel( - 5, + "5", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -85,7 +85,7 @@ class SearchViewModel 910, ), ProductModel( - 6, + "6", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f", @@ -94,7 +94,7 @@ class SearchViewModel 112, ), ProductModel( - 7, + "7", 0, "퓨어 오일 퍼퓸 10 ml 긴제목테스트트트트트", "https://github.com/Marchbreeze/Marchbreeze/assets/97405341/cd2c0454-92b4-41e7-ae2f-319f83e2426f",