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

[둘리] 1, 2단계 쇼핑 장바구니 제출합니다. #20

Merged
merged 52 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d7cfbc7
docs: 기능 목록 작성
hyemdooly May 9, 2023
2584164
feat: Domain 모듈 생성
hyemdooly May 9, 2023
5ae38d7
feat: 상훔 목록을 관리하는 Repository Interface 생성
hyunji1203 May 9, 2023
d9c9fb4
feat: 장바구니를 관리하는 CartRepository Interface 생성
hyemdooly May 9, 2023
2676ad4
feat: 최근 본 상품 목록을 관리하는 Repository Interface 생성
hyunji1203 May 9, 2023
e65d164
feat: 상품 정보를 담는 Product, 가격을 담는 Price 생성
hyemdooly May 9, 2023
42ca12e
feat: 상품의 정보를 리턴하는 ProductMockRepository 구현
hyunji1203 May 9, 2023
25d3651
feat: ProductListActivity 이미지 제외한 화면 구성 완료
hyemdooly May 9, 2023
ccb8fc1
feat: 메인 색깔 변경
hyemdooly May 9, 2023
52e3bc5
feat: 액션 바에 장바구니 바로가기 메뉴 추가
hyunji1203 May 9, 2023
143e31c
feat: 장바구니 화면의 액션바 안의 백버튼을 누르면 뒤로 이동하는 기능 추가
hyunji1203 May 9, 2023
633ef00
feat: 상품 이미지 Glide 적용
hyemdooly May 9, 2023
1f24cee
refactor: 패키지 이동
hyemdooly May 9, 2023
8dc0249
refactor: ProductListActivity MVP 패턴 적용
hyunji1203 May 9, 2023
7cca774
refactor: 장바구니 아이템 구현
hyemdooly May 10, 2023
f45ba61
feat: 장바구니 리스트 뷰 구현
hyunji1203 May 10, 2023
b58de23
feat: 상품 상세 뷰 구현
hyemdooly May 10, 2023
964767b
feat: 장바구니 DataBase 생성 로직 구현
hyunji1203 May 10, 2023
c2fc7af
feat: CartDbRepository 구현
hyemdooly May 10, 2023
78d597e
feat: ProductList OnClick 추가, DB 적용
hyemdooly May 10, 2023
605c01c
feat: 상품 상세 페이지 액션 바에 뒤로가기 버튼 추가
hyunji1203 May 10, 2023
0aaecc9
refactor: MVP 패턴으로 변경
hyunji1203 May 10, 2023
a2eb1fe
feat: 최근 본 상품 리스트 추가
hyemdooly May 10, 2023
8da62a1
feat: 최근 본 상품 datebase 기능 추가
hyunji1203 May 10, 2023
9270d70
feat: CartProduct DB 적용, 삭제 기능 추가
hyemdooly May 10, 2023
3136470
refactor: find 리턴값 수정
hyemdooly May 11, 2023
3206da5
refactor: notifyItemRemoved 적용
hyemdooly May 11, 2023
b83401a
feat: 페이지네이션 구현 중
hyunji1203 May 11, 2023
f858baa
feat: 더보기 구현중
hyemdooly May 11, 2023
ea478c3
feat: 더보기 구현 완료
hyemdooly May 11, 2023
a143b22
feat: 카트 페이지네이션 구현 중
hyunji1203 May 11, 2023
3bf6ad5
test: ProductListPresenterTest 작성
hyemdooly May 11, 2023
315a8ce
refactor: ProductDetailPresenter cartRepository 추상화 적용
hyemdooly May 11, 2023
9599973
test: ProductDetailPresenter 테스트 추가
hyunji1203 May 11, 2023
8fd10a2
refactor: Pagination 적용중
hyemdooly May 11, 2023
08ccb68
refactor: Pagination 적용중
hyemdooly May 11, 2023
1330e9d
feat: Pagination Button onClick 수정
hyemdooly May 11, 2023
65cee56
fix: 페이지가 넘어가지 않는 오류 수정
hyemdooly May 12, 2023
ef8e6c9
refactor: onCreate 코드 함수 분리
hyemdooly May 12, 2023
bb1c417
refactor: 너무 긴 코드 개행
hyemdooly May 12, 2023
bf285df
refactor: 상수 선언
hyemdooly May 12, 2023
377f7b3
refactor: constraintLayout 자식 뷰 match_parent -> 0dp로 수정
hyemdooly May 12, 2023
11cfe23
refactor: xml formatting
hyemdooly May 12, 2023
4fbc614
refactor: asSequence 사용하여 map 호출 시간 단축
hyemdooly May 12, 2023
68d3fdb
refactor: Next, Prev Pagination 분리
hyemdooly May 13, 2023
5e57cd5
refactor: CartPageStatus 생성, CartAdapter 리팩터링
hyemdooly May 13, 2023
023a703
refactor: LayoutManager xml로 이동
hyemdooly May 13, 2023
d3a1f22
refactor: 상수 선언
hyemdooly May 13, 2023
41b0e02
refactor: CartAdapter에서 CartViewItem 사용하여 Items를 하나로 묶음
hyemdooly May 13, 2023
5eb3cfc
refactor: ProductListActivity 리사이클러뷰 리팩터링
hyemdooly May 13, 2023
6e8f667
test: package 이동, ProductListPresenterTest 수정, CartPresenterTest 작성
hyemdooly May 13, 2023
0b23bbd
refactor: 테스트 코드에서 whildcard import 수정
hyemdooly May 13, 2023
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
Prev Previous commit
Next Next commit
feat: 더보기 구현중
  • Loading branch information
hyemdooly committed May 11, 2023
commit f858baa3f76588eb7c52546504dcb1aa9c82497f
137 changes: 137 additions & 0 deletions app/src/main/java/woowacourse/shopping/data/ProductMockRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,143 @@ object ProductMockRepository : ProductRepository {
10000,
),
),
Product(
15,
"15",
"https://thumbnail9.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2418649993082166-2bfb64be-78dc-4c05-a2e3-1749f856fef8.jpg",
Price(
10000,
),
),
Product(
16,
"16",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1721669748108539-877f91ca-5964-4761-b3e0-bff7b970c31c.jpg",
Price(
10000,
),
),
Product(
17,
"17",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2700754094560515-ebc4cbaa-4c4f-4750-8b41-2e6ae5ab26ed.jpg",
Price(
10000,
),
),
Product(
18,
"18",
"https://thumbnail9.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2418649993082166-2bfb64be-78dc-4c05-a2e3-1749f856fef8.jpg",
Price(
10000,
),
),
Product(
19,
"19",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1721669748108539-877f91ca-5964-4761-b3e0-bff7b970c31c.jpg",
Price(
10000,
),
),
Product(
20,
"20",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2700754094560515-ebc4cbaa-4c4f-4750-8b41-2e6ae5ab26ed.jpg",
Price(
10000,
),
),
Product(
21,
"21",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/6769030628798948-183ad194-f24c-44e6-b92f-1ed198b347cd.jpg",
Price(
10000,
),
),
Product(
22,
"22",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1237954167000478-5b27108a-ee70-4e14-b605-181191a57bcb.jpg",
Price(
10000,
),
),
Product(
23,
"23",
"https://thumbnail9.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2418649993082166-2bfb64be-78dc-4c05-a2e3-1749f856fef8.jpg",
Price(
10000,
),
),
Product(
24,
"24",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1721669748108539-877f91ca-5964-4761-b3e0-bff7b970c31c.jpg",
Price(
10000,
),
),
Product(
25,
"25",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2700754094560515-ebc4cbaa-4c4f-4750-8b41-2e6ae5ab26ed.jpg",
Price(
10000,
),
),
Product(
26,
"26",
"https://thumbnail9.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2418649993082166-2bfb64be-78dc-4c05-a2e3-1749f856fef8.jpg",
Price(
10000,
),
),
Product(
27,
"27",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1721669748108539-877f91ca-5964-4761-b3e0-bff7b970c31c.jpg",
Price(
10000,
),
),
Product(
28,
"28",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2700754094560515-ebc4cbaa-4c4f-4750-8b41-2e6ae5ab26ed.jpg",
Price(
10000,
),
),
Product(
29,
"29",
"https://thumbnail9.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2418649993082166-2bfb64be-78dc-4c05-a2e3-1749f856fef8.jpg",
Price(
10000,
),
),
Product(
30,
"30",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/1721669748108539-877f91ca-5964-4761-b3e0-bff7b970c31c.jpg",
Price(
10000,
),
),
Product(
31,
"31",
"https://thumbnail7.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/2700754094560515-ebc4cbaa-4c4f-4750-8b41-2e6ae5ab26ed.jpg",
Price(
10000,
),
),

)

override fun findAll(): List<Product> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import woowacourse.shopping.R

enum class ItemViewType(@LayoutRes val id: Int) {
RECENT_VIEWED_ITEM(R.layout.item_recent_viewed),
PRODUCT_ITEM(R.layout.item_product)
PRODUCT_ITEM(R.layout.item_product),
SHOW_MORE_ITEM(R.layout.item_show_more)
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package woowacourse.shopping.view.productlist

import android.util.Log
import woowacourse.shopping.domain.Product
import woowacourse.shopping.domain.ProductRepository

class Pagination(private val rangeSize: Int, private val productRepository: ProductRepository) {
private var mark = 0
private var isEnabled = nextItemExist()

fun nextItems(): List<Product> {
Log.d("MARK", mark.toString())
val items = productRepository.findRange(mark, rangeSize)
mark += rangeSize
return items
if (isEnabled) {
val items = productRepository.findRange(mark, rangeSize)
mark += rangeSize
isEnabled = nextItemExist()
return items
}
return emptyList()
}

fun nextItemExist(): Boolean {
private fun nextItemExist(): Boolean {
return productRepository.isExistByMark(mark)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ProductListActivity : AppCompatActivity(), ProductListContract.View {
binding = ActivityProductListBinding.inflate(layoutInflater)
setContentView(binding.root)
presenter = ProductListPresenter(this, ProductMockRepository, RecentViewedDbRepository(this))
presenter.fetchProducts()
supportActionBar?.setDisplayShowCustomEnabled(true)
}

Expand All @@ -36,24 +35,36 @@ class ProductListActivity : AppCompatActivity(), ProductListContract.View {
val gridLayoutManager = GridLayoutManager(this, 2)
gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (recentViewedProducts.isNotEmpty() && position == 0) {
val isHeader = recentViewedProducts.isNotEmpty() && position == 0
val isFooter = if (recentViewedProducts.isNotEmpty()) position == products.size + 1 else position == products.size
return if (isHeader || isFooter) {
2
} else {
1
}
}
}
binding.gridProducts.layoutManager = gridLayoutManager
binding.gridProducts.adapter = ProductListAdapter(recentViewedProducts, products) {
onClick(it)
}
binding.gridProducts.adapter = ProductListAdapter(
recentViewedProducts,
products,
object : ProductListAdapter.OnItemClick {
override fun onProductClick(product: ProductModel) {
showProductDetail(product)
}

override fun onShowMoreClick() {
presenter.showMoreProducts()
}
},
)
}

override fun addProducts() {
binding.gridProducts.adapter?.notifyDataSetChanged()
override fun addProducts(position: Int, size: Int) {
// binding.gridProducts.adapter?.notifyItemRangeInserted(position, size)
}

private fun onClick(product: ProductModel) {
private fun showProductDetail(product: ProductModel) {
val intent = ProductDetailActivity.newIntent(binding.root.context, product)
startActivity(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,39 @@ class ProductListAdapter(
private val products: List<ProductModel>,
private val onItemClick: OnItemClick,
) : RecyclerView.Adapter<ProductViewHolder>() {
fun interface OnItemClick {
fun onClick(product: ProductModel)
interface OnItemClick {
fun onProductClick(product: ProductModel)
fun onShowMoreClick()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
return ProductViewHolder.of(parent, ItemViewType.values()[viewType])
return ProductViewHolder.of(parent, ItemViewType.values()[viewType], onItemClick)
}

override fun getItemViewType(position: Int): Int {
return if (position == 0 && isRecentViewedExist()) {
ItemViewType.RECENT_VIEWED_ITEM.ordinal
} else if (position == itemCount - 1) {
ItemViewType.SHOW_MORE_ITEM.ordinal
} else {
ItemViewType.PRODUCT_ITEM.ordinal
}
}

override fun getItemCount(): Int = if (isRecentViewedExist()) products.size + 1 else products.size
override fun getItemCount(): Int = if (isRecentViewedExist()) products.size + 2 else products.size + 1

override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
holder.adapterPosition
when (holder) {
is ProductViewHolder.RecentViewedViewHolder -> {
holder.bind(recentViewedProducts, onItemClick)
}
is ProductViewHolder.ProductItemViewHolder -> {
val convertPosition = if (isRecentViewedExist()) position - 1 else position
holder.bind(products[convertPosition], onItemClick)
holder.bind(products[convertPosition])
}
is ProductViewHolder.ShowMoreViewHolder -> {
return
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import woowacourse.shopping.model.ProductModel
interface ProductListContract {
interface View {
fun showProducts(recentViewedProducts: List<ProductModel>, products: List<ProductModel>)
fun addProducts()
fun addProducts(position: Int, size: Int)
}

interface Presenter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ class ProductListPresenter(
}

override fun showMoreProducts() {
val mark = products.size
products.addAll(pagination.nextItems().map { it.toUiModel() })
view.addProducts(mark, PAGINATION_SIZE)
}

companion object {
private const val PAGINATION_SIZE = 20
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.bumptech.glide.Glide
import woowacourse.shopping.R
import woowacourse.shopping.databinding.ItemProductBinding
import woowacourse.shopping.databinding.ItemRecentViewedBinding
import woowacourse.shopping.databinding.ItemShowMoreBinding
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.util.PriceFormatter
import woowacourse.shopping.view.productlist.recentviewed.RecentViewedAdapter
Expand All @@ -19,21 +20,30 @@ sealed class ProductViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}
}

class ProductItemViewHolder(private val binding: ItemProductBinding) : ProductViewHolder(binding.root) {
fun bind(product: ProductModel, onClick: ProductListAdapter.OnItemClick) {
class ProductItemViewHolder(private val binding: ItemProductBinding, onItemClick: ProductListAdapter.OnItemClick) : ProductViewHolder(binding.root) {
init {
binding.onItemClick = onItemClick
}
fun bind(product: ProductModel) {
binding.product = product
binding.onItemClick = onClick
binding.textPrice.text = binding.root.context.getString(R.string.korean_won, PriceFormatter.format(product.price))
Glide.with(binding.root.context).load(product.imageUrl).into(binding.imgProduct)
}
}

class ShowMoreViewHolder(binding: ItemShowMoreBinding, onItemClick: ProductListAdapter.OnItemClick) : ProductViewHolder(binding.root) {
init {
binding.onItemClick = onItemClick
}
}

companion object {
fun of(parent: ViewGroup, type: ItemViewType): ProductViewHolder {
fun of(parent: ViewGroup, type: ItemViewType, onItemClick: ProductListAdapter.OnItemClick): ProductViewHolder {
val view = LayoutInflater.from(parent.context).inflate(type.id, parent, false)
return when (type) {
ItemViewType.RECENT_VIEWED_ITEM -> RecentViewedViewHolder(ItemRecentViewedBinding.bind(view))
ItemViewType.PRODUCT_ITEM -> ProductItemViewHolder(ItemProductBinding.bind(view))
ItemViewType.PRODUCT_ITEM -> ProductItemViewHolder(ItemProductBinding.bind(view), onItemClick)
ItemViewType.SHOW_MORE_ITEM -> ShowMoreViewHolder(ItemShowMoreBinding.bind(view), onItemClick)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/back_rounded_bold.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http:https://schemas.android.com/apk/res/android">
<corners android:radius="4dp" />
<stroke android:width="3dp" android:color="@color/rounded_rectangle_stroke" />
</shape>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_height="wrap_content"
android:paddingHorizontal="20dp"
android:paddingVertical="25dp"
android:onClick="@{() -> onItemClick.onClick(product)}"
android:onClick="@{() -> onItemClick.onProductClick(product)}"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/img_product"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_recent_viewed_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="?attr/selectableItemBackground"
android:onClick="@{() -> onItemClick.onClick(product)}">
android:onClick="@{() -> onItemClick.onProductClick(product)}">

<ImageView
android:id="@+id/img_product"
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout/item_show_more.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="onItemClick"
type="woowacourse.shopping.view.productlist.ProductListAdapter.OnItemClick" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_show_more"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/back_rounded_bold"
android:onClick="@{() -> onItemClick.onShowMoreClick()}"
android:text="@string/show_more"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading