forked from woowacourse/android-shopping-cart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CartAdapter.kt
36 lines (29 loc) · 1.23 KB
/
CartAdapter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package woowacourse.shopping.view.cart
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import woowacourse.shopping.model.CartProductModel
class CartAdapter(
private val items: List<CartViewItem>,
private val onItemClick: OnItemClick,
) : RecyclerView.Adapter<CartItemViewHolder>() {
interface OnItemClick {
fun onRemoveClick(id: Int)
fun onNextClick()
fun onPrevClick()
fun onUpdateCount(id: Int, count: Int)
fun onSelectProduct(product: CartProductModel)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartItemViewHolder {
return CartItemViewHolder.of(parent, CartViewType.values()[viewType], onItemClick)
}
override fun getItemViewType(position: Int): Int {
return items[position].type.ordinal
}
override fun getItemCount(): Int = items.size
override fun onBindViewHolder(holder: CartItemViewHolder, position: Int) {
when (holder) {
is CartItemViewHolder.CartProductViewHolder -> holder.bind(items[position] as CartViewItem.CartProductItem)
is CartItemViewHolder.CartPaginationViewHolder -> holder.bind(items[position] as CartViewItem.PaginationItem)
}
}
}