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: ProductList OnClick 추가, DB 적용
  • Loading branch information
hyemdooly committed May 10, 2023
commit 78d597ef5042b807d92ad4adea0998eadfe2594e
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:theme="@style/Theme.Shopping"
tools:targetApi="31">
<activity
android:name=".ProductDetailActivity"
android:name=".view.productdetail.ProductDetailActivity"
android:exported="false" />
<activity
android:name=".view.cart.CartActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ object ProductMockRepository : ProductRepository {
override fun findAll(): List<Product> {
return products
}

override fun find(id: Int): Product {
return products[id]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import woowacourse.shopping.data.CartDbRepository
import woowacourse.shopping.data.ProductMockRepository
import woowacourse.shopping.databinding.ActivityCartBinding

Expand All @@ -20,7 +21,7 @@ class CartActivity : AppCompatActivity() {
supportActionBar?.title = "Cart"

// ID Product로 변환 과정 필요
val cartProducts = ProductMockRepository.findAll()
val cartProducts = CartDbRepository(this).findAll().map { ProductMockRepository.find(it.id) }
binding.recyclerCart.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
binding.recyclerCart.setHasFixedSize(true)
binding.recyclerCart.adapter = CartAdapter(cartProducts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package woowacourse.shopping.view.productdetail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import woowacourse.shopping.R
import woowacourse.shopping.data.CartDbRepository
import woowacourse.shopping.databinding.ActivityProductDetailBinding
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.util.PriceFormatter
import woowacourse.shopping.util.getParcelableCompat
Expand All @@ -28,12 +32,21 @@ class ProductDetailActivity : AppCompatActivity() {
Glide.with(binding.root.context).load(product.imageUrl).into(binding.imgProduct)
binding.textPrice.text = getString(R.string.korean_won, PriceFormatter.format(product.price))
binding.btnPutInCart.setOnClickListener {
CartActivity.newIntent(this)
val cartRepository: CartRepository = CartDbRepository(this)
cartRepository.add(product.id, 1)
val intent = CartActivity.newIntent(this)
startActivity(intent)
}
}

companion object {
const val PRODUCT = "PRODUCT"
private const val NOT_EXIST_DATA_ERROR = "데이터가 넘어오지 않았습니다."

fun newIntent(context: Context, product: ProductModel): Intent {
val intent = Intent(context, ProductDetailActivity::class.java)
intent.putExtra(PRODUCT, product)
return intent
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import androidx.appcompat.app.AppCompatActivity
import woowacourse.shopping.R
import woowacourse.shopping.data.ProductMockRepository
import woowacourse.shopping.databinding.ActivityProductListBinding
import woowacourse.shopping.domain.Product
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.view.cart.CartActivity
import woowacourse.shopping.view.productdetail.ProductDetailActivity

class ProductListActivity : AppCompatActivity(), ProductListContract.View {
private lateinit var binding: ActivityProductListBinding
Expand All @@ -24,8 +25,15 @@ class ProductListActivity : AppCompatActivity(), ProductListContract.View {
supportActionBar?.setDisplayShowCustomEnabled(true)
}

override fun showProducts(products: List<Product>) {
binding.gridProducts.adapter = ProductListAdapter(products)
override fun showProducts(products: List<ProductModel>) {
binding.gridProducts.adapter = ProductListAdapter(products) {
onClick(it)
}
}

private fun onClick(product: ProductModel) {
val intent = ProductDetailActivity.newIntent(binding.root.context, product)
startActivity(intent)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import woowacourse.shopping.R
import woowacourse.shopping.databinding.ItemProductBinding
import woowacourse.shopping.domain.Product
import woowacourse.shopping.model.ProductModel

class ProductListAdapter(
private val products: List<ProductModel>,
private val onItemClick: OnItemClick,
) : RecyclerView.Adapter<ProductViewHolder>() {
fun interface OnItemClick {
fun onClick(product: ProductModel)
}

class ProductListAdapter(private val products: List<Product>) : RecyclerView.Adapter<ProductViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_product, parent, false)
return ProductViewHolder(ItemProductBinding.bind(view))
Expand All @@ -16,6 +23,6 @@ class ProductListAdapter(private val products: List<Product>) : RecyclerView.Ada
override fun getItemCount(): Int = products.size

override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
holder.bind(products[position])
holder.bind(products[position], onItemClick)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package woowacourse.shopping.view.productlist

import woowacourse.shopping.domain.Product
import woowacourse.shopping.model.ProductModel

interface ProductListContract {
interface View {
fun showProducts(products: List<Product>)
fun showProducts(products: List<ProductModel>)
}

interface Presenter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package woowacourse.shopping.view.productlist

import woowacourse.shopping.domain.ProductRepository
import woowacourse.shopping.model.toUiModel

class ProductListPresenter(
private val view: ProductListContract.View,
private val productRepository: ProductRepository,
) : ProductListContract.Presenter {
override fun fetchProducts() {
val products = productRepository.findAll()
view.showProducts(products)
view.showProducts(products.map { it.toUiModel() })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import woowacourse.shopping.R
import woowacourse.shopping.databinding.ItemProductBinding
import woowacourse.shopping.domain.Product
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.util.PriceFormatter

class ProductViewHolder(private val binding: ItemProductBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(product: Product) {
fun bind(product: ProductModel, onClick: ProductListAdapter.OnItemClick) {
binding.product = product
binding.textPrice.text = binding.root.context.getString(R.string.korean_won, PriceFormatter.format(product.price.price))
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)
}
}
9 changes: 7 additions & 2 deletions app/src/main/res/layout/item_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
<data>
<variable
name="product"
type="woowacourse.shopping.domain.Product" />
type="woowacourse.shopping.model.ProductModel" />
<variable
name="onItemClick"
type="woowacourse.shopping.view.productlist.ProductListAdapter.OnItemClick" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가급적이면 들여쓰기를 잘 해주시는 것이 좋습니다.
들여쓰기가 없으니 최상단 element로 느껴지네요.
xml은 특히 작업을 하신 후에 자동포메팅을 사용하시는 것을 권장합니다.

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="10dp">
android:paddingVertical="10dp"
android:onClick="@{() -> onItemClick.onClick(product)}"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/img_product"
android:layout_width="0dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package woowacourse.shopping.domain

interface ProductRepository {
fun findAll(): List<Product>

fun find(id: Int): Product
}