Skip to content

Commit

Permalink
[feat] #224 리뷰 작성, 빵집 상세뷰 BreadTypsChips 동적 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan2dani committed Feb 17, 2024
1 parent 47b65cd commit 78c60a0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BakeryListFragment :
viewModel.bakeryListState.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Success -> {
bakeryAdapter.setBakeryList(it.data.toMutableList())
// bakeryAdapter.setBakeryList(it.data.toMutableList())
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
import com.sopt.geonppang.R
import com.sopt.geonppang.databinding.ActivityDetailBinding
import com.sopt.geonppang.domain.model.BakeryInfo
import com.sopt.geonppang.domain.model.BakeryInformation
import com.sopt.geonppang.presentation.common.WebViewActivity
import com.sopt.geonppang.presentation.model.BakeryReviewWritingInfo
import com.sopt.geonppang.presentation.report.ReportActivity
import com.sopt.geonppang.presentation.reviewWriting.ReviewWritingActivity
import com.sopt.geonppang.presentation.type.BreadFilterType
import com.sopt.geonppang.util.AmplitudeUtils
import com.sopt.geonppang.util.ChipFactory
import com.sopt.geonppang.util.CustomSnackbar
import com.sopt.geonppang.util.UiState
import com.sopt.geonppang.util.binding.BindingActivity
import com.sopt.geonppang.util.extension.breadTypeListToChips
import com.sopt.geonppang.util.extension.setOnSingleClickListener
import com.sopt.geonppang.util.extension.toBreadTypePointM1Chip
import com.sopt.geonppang.util.extension.toReviewRecommendedKeyWordChip
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand All @@ -38,11 +44,7 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_
private lateinit var detailNoReviewAdapter: DetailNoReviewAdapter
private lateinit var concatAdapter: ConcatAdapter
private var bakeryId = -1

private val String.toChip: Chip
get() = ChipFactory.create(layoutInflater).also {
it.text = this
}
lateinit var breadTypeList: List<BreadFilterType>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -59,10 +61,10 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_
private fun initLayout() {
viewModel.fetchDetailReview(bakeryId)

detailBakeryInfoAdapter = DetailBakeryInfoAdapter(::moveToWebPage)
detailBakeryInfoAdapter = DetailBakeryInfoAdapter(::moveToWebPage, ::initBreadTypeChips)
detailMenuAdapter = DetailMenuAdapter()
detailReviewGraphAdapter = DetailReviewGraphAdapter()
detailReviewAdapter = DetailReviewAdapter(::initChip, ::moveToReport)
detailReviewAdapter = DetailReviewAdapter(::initRecommendKeyWordChip, ::moveToReport)
detailNoReviewAdapter = DetailNoReviewAdapter()

concatAdapter = ConcatAdapter(
Expand Down Expand Up @@ -103,10 +105,13 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_
}

private fun collectData() {
viewModel.bakeryInfo.flowWithLifecycle(lifecycle).onEach {
viewModel.bakeryInfo.flowWithLifecycle(lifecycle).onEach { it ->
it?.let { bakeryInfo ->
detailBakeryInfoAdapter.setBakeryInfo(bakeryInfo)
detailMenuAdapter.submitList(bakeryInfo.menuList)
breadTypeList = bakeryInfo.breadTypeIdList


}
}.launchIn(lifecycleScope)

Expand Down Expand Up @@ -152,16 +157,29 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_
}.launchIn(lifecycleScope)
}

private fun initChip(chipGroup: ChipGroup, position: Int) {
private fun initRecommendKeyWordChip(chipGroup: ChipGroup, position: Int) {
viewModel.reviewData.value?.detailReviewList?.get(position)?.recommendKeywordList?.let { recommendKeywordList ->
for (recommendKeyword in recommendKeywordList) {
chipGroup.addView(
recommendKeyword.recommendKeywordName.toChip
recommendKeyword.recommendKeywordName.toReviewRecommendedKeyWordChip(
layoutInflater
)
)
}
}
}

private fun initBreadTypeChips(chipGroup: ChipGroup) {
if (breadTypeList.isNotEmpty()) {
chipGroup.breadTypeListToChips(
breadTypeList = breadTypeList,
toChip = {
this.toBreadTypePointM1Chip(layoutInflater)
}
)
}
}

private fun moveToTop(recyclerView: RecyclerView) {
recyclerView.smoothScrollToPosition(FIRST_POSITION)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ package com.sopt.geonppang.presentation.detail
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.ChipGroup
import com.sopt.geonppang.databinding.ItemDetailBakeryInfoBinding
import com.sopt.geonppang.domain.model.BakeryInfo
import com.sopt.geonppang.util.AmplitudeUtils

class DetailBakeryInfoAdapter(
private val moveToWebPage: (String) -> Unit
private val moveToWebPage: (String) -> Unit,
private val initBreadTypeChips: (ChipGroup) -> Unit,
) : RecyclerView.Adapter<DetailBakeryInfoAdapter.DetailBakeryInfoViewHolder>() {
private val bakeryInfoList: MutableList<BakeryInfo> = mutableListOf()

class DetailBakeryInfoViewHolder(val binding: ItemDetailBakeryInfoBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(
bakeryInfo: BakeryInfo,
moveToWebPage: (String) -> Unit
moveToWebPage: (String) -> Unit,
initBreadTypeChips: (ChipGroup) -> Unit,
) {
with(binding) {
binding.bakeryInfo = bakeryInfo

initBreadTypeChips(binding.chipGroupItemDetailBakeryInfoBreadType)

tvItemDetailBakeryInfoHomepage.setOnClickListener {
AmplitudeUtils.trackEvent(CLICK_WEBSITE)
moveToWebPage(bakeryInfo.homepageUrl)
Expand All @@ -43,7 +48,7 @@ class DetailBakeryInfoAdapter(
override fun getItemCount(): Int = bakeryInfoList.size

override fun onBindViewHolder(holder: DetailBakeryInfoViewHolder, position: Int) {
holder.onBind(bakeryInfoList[position], moveToWebPage)
holder.onBind(bakeryInfoList[position], moveToWebPage, initBreadTypeChips)
}

fun setBakeryInfo(bakeryInfo: BakeryInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,10 @@ class DetailViewModel @Inject constructor(
BakeryReviewWritingInfo(
_bakeryInfo.bakeryName,
_bakeryInfo.bakeryPicture,
BakeryReviewWritingInfo.BreadType(
_bakeryInfo.breadType.isGlutenFree,
_bakeryInfo.breadType.isVegan,
_bakeryInfo.breadType.isNutFree,
_bakeryInfo.breadType.isSugarFree,
),
_bakeryInfo.breadTypeIdList,
_bakeryInfo.firstNearStation,
_bakeryInfo.secondNearStation
)
} ?: BakeryReviewWritingInfo("", "", null, "", "")
} ?: BakeryReviewWritingInfo("", "", listOf(), "", "")
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.sopt.geonppang.presentation.model

import android.os.Parcelable
import com.sopt.geonppang.presentation.type.BreadFilterType
import kotlinx.android.parcel.Parcelize

@Parcelize
data class BakeryReviewWritingInfo(
val bakeryName: String,
val bakeryPicture: String,
val breadType: BreadType?,
val breadTypeList: List<BreadFilterType>,
val firstNearestStation: String,
val secondNearestStation: String?,
) : Parcelable {
@Parcelize
data class BreadType(
val isGlutenFree: Boolean,
val isVegan: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
) : Parcelable
}
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import com.sopt.geonppang.presentation.type.LikeType
import com.sopt.geonppang.util.AmplitudeUtils
import com.sopt.geonppang.util.UiState
import com.sopt.geonppang.util.binding.BindingActivity
import com.sopt.geonppang.util.extension.breadTypeListToChips
import com.sopt.geonppang.util.extension.hideKeyboard
import com.sopt.geonppang.util.extension.setOnSingleClickListener
import com.sopt.geonppang.util.extension.toBreadTypePointM2Chip
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand All @@ -41,7 +43,17 @@ class ReviewWritingActivity :
private fun initLayout() {
val bakeryReviewWritingInfo =
intent.getParcelableExtra<BakeryReviewWritingInfo>(BAKERY_INFO)
bakeryReviewWritingInfo?.let { viewModel.setBakeryInfo(it) }
bakeryReviewWritingInfo?.let { bakeryInfo ->
viewModel.setBakeryInfo(bakeryInfo)

binding.cgBakeryBreadTypes
.breadTypeListToChips(
breadTypeList = bakeryInfo.breadTypeList,
toChip = {
this.toBreadTypePointM2Chip(layoutInflater)
}
)
}
}

private fun addListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VerticalProgressBar @JvmOverloads constructor(
typedArray.recycle()
}

override fun onDraw(canvas: Canvas?) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)

val width = width.toFloat()
Expand All @@ -43,7 +43,7 @@ class VerticalProgressBar @JvmOverloads constructor(
height.toInt()
)

canvas?.let { canvas ->
canvas.let { canvas ->
backgroundDrawable?.draw(canvas)
progressDrawable?.draw(canvas)
}
Expand Down

0 comments on commit 78c60a0

Please sign in to comment.