Skip to content

Commit

Permalink
[FEAT/#76] 구매 약관 버튼 활성화 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Aug 18, 2024
1 parent 63da255 commit dae543b
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ data class AddressInfoDto(
val zipCode: String? = null,
@SerialName("address")
val address: String? = null,
@SerialName("phone")
val phone: String? = null,
@SerialName("recipientPhone")
val recipientPhone: String? = null,
) {
fun toModel() = AddressInfoModel(recipient, zipCode, address, phone)
fun toModel() = AddressInfoModel(recipient, zipCode, address, recipientPhone)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ data class AddressInfoModel(
val recipient: String? = null,
val zipCode: String? = null,
val address: String? = null,
val phone: String? = null,
val recipientPhone: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BuyFinishedActivity :
item.addressInfo[0].zipCode,
item.addressInfo[0].address,
).breakLines()
tvFinishedDeliveryPhone.text = item.addressInfo[0].phone
tvFinishedDeliveryPhone.text = item.addressInfo[0].recipientPhone
tvFinishedTransactionMethod.text = item.paymentInfo[0].method
tvFinishedTransactionDate.text = item.paymentInfo[0].completedAt
tvFinishedPayMoney.text = item.originPrice.setNumberForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BuyInfoActivity :
item.addressInfo[0].zipCode,
item.addressInfo[0].address,
).breakLines()
tvInfoDeliveryPhone.text = item.addressInfo[0].phone
tvInfoDeliveryPhone.text = item.addressInfo[0].recipientPhone
tvInfoTransactionMethod.text = item.paymentInfo[0].method
tvInfoTransactionDate.text = item.paymentInfo[0].completedAt
tvInfoPayMoney.text = item.originPrice.setNumberForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import co.orange.core.extension.breakLines
import co.orange.core.extension.setNumberForm
import co.orange.core.extension.setOnSingleClickListener
import co.orange.core.extension.stringOf
import co.orange.core.extension.toPhoneFrom
import co.orange.core.extension.toast
import co.orange.core.state.UiState
import co.orange.domain.entity.response.AddressInfoModel
import co.orange.domain.entity.response.BuyProgressModel
import co.orange.presentation.buy.push.BuyPushActivity
import co.orange.presentation.setting.delivery.DeliveryActivity
Expand All @@ -33,6 +35,7 @@ class BuyProgressActivity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding.vm = viewModel
initExitBtnListener()
initDeliveryChangeBtnListener()
initTermBtnListener()
Expand All @@ -52,10 +55,15 @@ class BuyProgressActivity :
}

private fun initDeliveryChangeBtnListener() {
binding.btnChangeDelivery.setOnSingleClickListener {
Intent(this, DeliveryActivity::class.java).apply {
startActivity(this)
}
with(binding) {
btnChangeDelivery.setOnSingleClickListener { navigateToAddAddress() }
btnDeliveryAdd.setOnSingleClickListener { navigateToAddAddress() }
}
}

private fun navigateToAddAddress() {
Intent(this, DeliveryActivity::class.java).apply {
startActivity(this)
}
}

Expand Down Expand Up @@ -117,17 +125,23 @@ class BuyProgressActivity :
tvConfirmPriceCharge.text =
getString(R.string.add_plus, item.charge.setNumberForm())
tvConfirmPriceTotal.text = item.totalPrice.setNumberForm()
if (item.addressInfo.recipient != null) {
}
setAddress(item.addressInfo)
}

private fun setAddress(address: AddressInfoModel) {
if (address.recipient != null) {
with(binding) {
btnDeliveryAdd.isVisible = false
layoutDeliveryItem.isVisible = true
tvDeliveryName.text = item.addressInfo.recipient
tvDeliveryName.text = address.recipient
tvDeliveryAddress.text =
getString(
R.string.address_short_format,
item.addressInfo.zipCode,
item.addressInfo.address,
address.zipCode,
address.address,
).breakLines()
tvDeliveryPhone.text = item.addressInfo.phone
tvDeliveryPhone.text = address.recipientPhone?.toPhoneFrom()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.orange.presentation.buy.progress

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.orange.core.state.UiState
Expand All @@ -19,16 +20,49 @@ class BuyProgressViewModel
) : ViewModel() {
var productId: String = ""

var isTermAllSelected = MutableLiveData<Boolean>(false)
var isTermServiceSelected = MutableLiveData<Boolean>(false)
var isTermPurchaseSelected = MutableLiveData<Boolean>(false)
var isAddressSelected = false
var isMethodSelected = true
var isCompleted = MutableLiveData<Boolean>(false)

private val _getBuyProgressDataState =
MutableStateFlow<UiState<BuyProgressModel>>(UiState.Empty)
val getBuyProgressDataState: StateFlow<UiState<BuyProgressModel>> = _getBuyProgressDataState

fun checkAllTerm() {
isTermServiceSelected.value = isTermAllSelected.value?.not()
isTermPurchaseSelected.value = isTermAllSelected.value?.not()
isTermAllSelected.value = isTermAllSelected.value?.not()
checkIsCompleted()
}

fun checkServiceTerm() {
isTermServiceSelected.value = isTermServiceSelected.value?.not()
checkIsCompleted()
}

fun checkPurchaseTerm() {
isTermPurchaseSelected.value = isTermPurchaseSelected.value?.not()
checkIsCompleted()
}

private fun checkIsCompleted() {
isTermAllSelected.value =
(isTermServiceSelected.value == true && isTermPurchaseSelected.value == true)
isCompleted.value =
(isTermServiceSelected.value == true && isTermPurchaseSelected.value == true && isAddressSelected && isMethodSelected)
}

fun getBuyProgressDataFromServer() {
_getBuyProgressDataState.value = UiState.Loading
viewModelScope.launch {
// TODO 추후 productId 활용
buyRepository.getBuyProgressData("0110055338")
.onSuccess {
isAddressSelected = !it.addressInfo.address.isNullOrEmpty()
checkIsCompleted()
_getBuyProgressDataState.value = UiState.Success(it)
}
.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import co.orange.domain.entity.response.ProductOptionModel
import kr.genti.presentation.databinding.ItemOptionBinding

class OptionAdapter(
private val itemClick: (Int, Long, Long) -> Unit,
private val itemClick: (Long, Long) -> Unit,
) : ListAdapter<ProductOptionModel, OptionViewHolder>(diffUtil) {
override fun onCreateViewHolder(
parent: ViewGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class OptionBottomSheet :
}

private fun initItemClickListener(
position: Int,
optionId: Long,
optionDetailId: Long,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import kr.genti.presentation.databinding.ItemOptionBinding

class OptionViewHolder(
val binding: ItemOptionBinding,
private val itemClick: (Int, Long, Long) -> Unit,
private val itemClick: (Long, Long) -> Unit,
) : RecyclerView.ViewHolder(binding.root) {
var selectedItemId: Long = -1
var selectedPosition: Int = -1

fun onBind(
item: ProductOptionModel,
position: Int,
) {
selectedItemId = item.optionId
selectedPosition = position
with(binding) {
tvOptionItemTitle.text = item.type
tvOptionItemTitle.setOnClickListener {
Expand All @@ -34,6 +32,6 @@ class OptionViewHolder(
}

private fun initItemClickListener(optionDetailId: Long) {
itemClick(selectedPosition, selectedItemId, optionDetailId)
itemClick(selectedItemId, optionDetailId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SellInfoActivity :
item.addressInfo[0].zipCode,
item.addressInfo[0].address,
).breakLines()
tvInfoDeliveryPhone.text = item.addressInfo[0].phone
tvInfoDeliveryPhone.text = item.addressInfo[0].recipientPhone
tvInfoTransactionMethod.text = item.paymentInfo[0].method
tvInfoTransactionDate.text = item.paymentInfo[0].completedAt
tvInfoPayKakao.text = item.originPrice.setNumberForm()
Expand Down
25 changes: 17 additions & 8 deletions presentation/src/main/res/layout/activity_buy_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

<data>

<import type="android.view.View" />

<variable
name="vm"
type="co.orange.presentation.buy.progress.BuyProgressViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -335,6 +340,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"
android:onClick="@{() -> vm.checkAllTerm()}"
android:orientation="horizontal"
android:paddingVertical="11dp"
android:paddingStart="4dp"
Expand All @@ -345,7 +351,7 @@
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_check_circle_filled" />
android:src="@{vm.isTermAllSelected ? @drawable/ic_check_circle_filled : @drawable/ic_check_circle_unfilled}" />

<TextView
style="@style/TextAppearance.DDanzi.Body1"
Expand All @@ -360,8 +366,9 @@
android:id="@+id/btn_term_service"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/shape_gray1_line_5_rect"
android:background="@{vm.isTermServiceSelected ? @drawable/shape_black_line_5_rect : @drawable/shape_gray1_line_5_rect}"
android:gravity="center_vertical"
android:onClick="@{() -> vm.checkServiceTerm()}"
android:orientation="horizontal"
android:padding="11dp"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -372,7 +379,7 @@
android:id="@+id/iv_buy_term_service"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sel_check_term" />
android:src="@{vm.isTermServiceSelected ? @drawable/ic_check_term_selected : @drawable/ic_check_term_unselected}" />

<TextView
android:id="@+id/tv_buy_term_service"
Expand All @@ -381,7 +388,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="@string/confirm_term_tv_first"
android:textColor="@color/gray_2" />
android:textColor="@{vm.isTermServiceSelected ? @color/black : @color/gray_2}" />

</LinearLayout>

Expand All @@ -403,8 +410,9 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/shape_gray1_line_5_rect"
android:background="@{vm.isTermPurchaseSelected ? @drawable/shape_black_line_5_rect : @drawable/shape_gray1_line_5_rect}"
android:gravity="center_vertical"
android:onClick="@{() -> vm.checkPurchaseTerm()}"
android:orientation="horizontal"
android:padding="11dp"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -415,7 +423,7 @@
android:id="@+id/iv_buy_term_purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sel_check_term" />
android:src="@{vm.isTermPurchaseSelected ? @drawable/ic_check_term_selected : @drawable/ic_check_term_unselected}" />

<TextView
android:id="@+id/tv_buy_term_purchase"
Expand All @@ -424,7 +432,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="@string/confirm_term_tv_second"
android:textColor="@color/gray_2" />
android:textColor="@{vm.isTermPurchaseSelected ? @color/black : @color/gray_2}" />

</LinearLayout>

Expand Down Expand Up @@ -459,7 +467,8 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="30dp"
android:background="@drawable/shape_black_fill_10_rect"
android:background="@drawable/sel_btn"
android:enabled="@{vm.isCompleted}"
android:gravity="center"
android:paddingVertical="15dp"
android:text="@string/buy_confirm_tv_title"
Expand Down

0 comments on commit dae543b

Please sign in to comment.