Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI/#11] 옵션선택뷰 / 바텀시트 UI 구현 #12

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.orange.presentation.detail
import android.content.Context
import android.content.Intent
import android.graphics.Paint
import android.net.Uri
import android.os.Bundle
import androidx.activity.viewModels
import androidx.core.view.isVisible
Expand All @@ -20,6 +21,9 @@ import kr.genti.presentation.databinding.ActivityDetailBinding
@AndroidEntryPoint
class DetailActivity : BaseActivity<ActivityDetailBinding>(R.layout.activity_detail) {
private val viewModel by viewModels<DetailViewModel>()

private var optionBottomSheet: OptionBottomSheet? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -38,8 +42,11 @@ class DetailActivity : BaseActivity<ActivityDetailBinding>(R.layout.activity_det
}

private fun initDetailViewBtnListener() {
// TODO
binding.btnDetailView.setOnSingleClickListener { }
binding.btnDetailView.setOnSingleClickListener {
if (viewModel.mockProduct.infoUrl.isNotEmpty()) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(viewModel.mockProduct.infoUrl)))
}
}
}

private fun initLikeBtnListener() {
Expand All @@ -48,8 +55,10 @@ class DetailActivity : BaseActivity<ActivityDetailBinding>(R.layout.activity_det
}

private fun initPurchaseBtnListener() {
// TODO
binding.btnPurchase.setOnSingleClickListener { }
binding.btnPurchase.setOnSingleClickListener {
optionBottomSheet = OptionBottomSheet()
optionBottomSheet?.show(supportFragmentManager, BOTTOM_SHEET_OPTION)
}
}

private fun getIntentInfo() {
Expand Down Expand Up @@ -80,11 +89,19 @@ class DetailActivity : BaseActivity<ActivityDetailBinding>(R.layout.activity_det
}
}

override fun onDestroy() {
super.onDestroy()

optionBottomSheet = null
}

companion object {
private const val EXTRA_PRODUCT_URL = "EXTRA_PRODUCT_URL"
private const val EXTRA_ORIGIN_PRICE = "EXTRA_ORIGIN_PRICE"
private const val EXTRA_SALE_PRICE = "EXTRA_SALE_PRICE"

private const val BOTTOM_SHEET_OPTION = "BOTTOM_SHEET_OPTION"

@JvmStatic
fun createIntent(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.orange.presentation.detail

import androidx.lifecycle.ViewModel
import co.orange.domain.entity.response.OptionModel
import co.orange.domain.entity.response.ProductDetailModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand All @@ -20,6 +21,11 @@ constructor(
12,
"",
123,
listOf()
listOf(
OptionModel(1,"옵션 1", listOf()),
OptionModel(2,"옵션 2", listOf()),
OptionModel(3,"옵션 3", listOf()),
OptionModel(4,"옵션 4", listOf())
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package co.orange.presentation.detail

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import co.orange.domain.entity.response.OptionModel
import kr.genti.core.util.ItemDiffCallback
import kr.genti.presentation.databinding.ItemOptionBinding

class OptionAdapter(
private val itemClick: (Int, Long) -> Unit,
) : ListAdapter<OptionModel, OptionViewHolder>(diffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OptionViewHolder {
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemOptionBinding =
ItemOptionBinding.inflate(inflater, parent, false)
return OptionViewHolder(binding, itemClick)
}

override fun onBindViewHolder(holder: OptionViewHolder, position: Int) {
val item = getItem(position) ?: return
holder.onBind(item, position)
}

fun addList(newItems: List<OptionModel>) {
val currentItems = currentList.toMutableList()
currentItems.addAll(newItems)
submitList(currentItems)
}

companion object {
private val diffUtil = ItemDiffCallback<OptionModel>(
onItemsTheSame = { old, new -> old.optionId == new.optionId },
onContentsTheSame = { old, new -> old == new },
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package co.orange.presentation.detail

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import co.orange.presentation.main.home.HomeProductViewHolder.Companion.OVER_999
import kr.genti.core.base.BaseBottomSheet
import kr.genti.core.extension.setOnSingleClickListener
import kr.genti.presentation.R
import kr.genti.presentation.databinding.BottomSheetOptionBinding

class OptionBottomSheet :
BaseBottomSheet<BottomSheetOptionBinding>(R.layout.bottom_sheet_option) {

private val viewModel by activityViewModels<DetailViewModel>()

private var _adapter: OptionAdapter? = null
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

override fun onStart() {
super.onStart()
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initDetailViewBtnListener()
initAdapter()
setInterestCount()
setOptionData()
}

private fun initDetailViewBtnListener() {
binding.btnDetailView.setOnSingleClickListener {
if (viewModel.mockProduct.infoUrl.isNotEmpty()) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(viewModel.mockProduct.infoUrl)))
}
}
}

private fun initAdapter() {
_adapter = OptionAdapter(
itemClick = ::initItemClickListener,
)
binding.rvOption.adapter = adapter
}

private fun initItemClickListener(position: Int, optionId: Long) {
// TODO
}

private fun setInterestCount() {
binding.tvOptionLike.text = if (viewModel.mockProduct.interestCount < 1000) {
viewModel.mockProduct.interestCount.toString()
} else {
OVER_999
}
}

private fun setOptionData() {
adapter.addList(viewModel.mockProduct.optionList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.orange.presentation.detail

import androidx.recyclerview.widget.RecyclerView
import co.orange.domain.entity.response.OptionModel
import kr.genti.core.extension.setOnSingleClickListener
import kr.genti.presentation.databinding.ItemOptionBinding

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

fun onBind(item: OptionModel, position: Int) {
// TODO: 수정된 UI 대응
with(binding) {
tvOptionItemTitle.text = item.type
root.setOnSingleClickListener {
itemClick(position, item.optionId)
}
}
}
}
9 changes: 9 additions & 0 deletions presentation/src/main/res/drawable/ic_check_unselected.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="21dp"
android:height="21dp"
android:viewportWidth="21"
android:viewportHeight="21">
<path
android:pathData="M10.748,20.988C5.287,20.988 0.748,16.449 0.748,10.988C0.748,5.518 5.277,0.988 10.738,0.988C16.209,0.988 20.748,5.518 20.748,10.988C20.748,16.449 16.219,20.988 10.748,20.988ZM10.748,19.322C15.375,19.322 19.081,15.616 19.081,10.988C19.081,6.361 15.366,2.655 10.738,2.655C6.111,2.655 2.425,6.361 2.425,10.988C2.425,15.616 6.121,19.322 10.748,19.322ZM9.67,15.645C9.346,15.645 9.081,15.508 8.836,15.184L6.444,12.243C6.307,12.057 6.219,11.851 6.219,11.635C6.219,11.204 6.552,10.861 6.974,10.861C7.248,10.861 7.464,10.939 7.699,11.253L9.63,13.753L13.699,7.224C13.885,6.939 14.13,6.782 14.375,6.782C14.787,6.782 15.179,7.067 15.179,7.508C15.179,7.724 15.052,7.939 14.944,8.135L10.464,15.184C10.268,15.488 9.993,15.645 9.67,15.645Z"
android:fillColor="#000000"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_4" />
<corners
android:radius="100dp" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
Loading
Loading