Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.olserapratama.pos
- import android.graphics.Color
- import android.view.LayoutInflater
- import android.view.View
- import android.view.ViewGroup
- import android.widget.ImageView
- import android.widget.TextView
- import androidx.constraintlayout.widget.ConstraintLayout
- import androidx.recyclerview.widget.RecyclerView
- import com.olserapratama.pos.R
- import com.olserapratama.pos.adapter.CustomerAdapter
- import com.olserapratama.pos.databinding.ListitemPpobGameBillBinding
- import com.olserapratama.pos.model.ppob.PpobTypeGroupDetail
- import mehdi.sakout.fancybuttons.FancyButton
- import java.text.DecimalFormat
- class BillGameAdapter(var listGameBill: ArrayList<PpobTypeGroupDetail>) : RecyclerView.Adapter<BillGameAdapter.CustomerVH>() {
- var mCallback: Callback? = null
- fun setData(mList: ArrayList<PpobTypeGroupDetail>) {
- this.listGameBill = mList
- notifyDataSetChanged()
- }
- interface Callback {
- fun onItemClicked(index: Int)
- }
- fun setCallback(mCallback: Callback) {
- this.mCallback = mCallback
- }
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomerAdapter.CustomerVH {
- val binding = ListitemPpobGameBillBinding.inflate(LayoutInflater.from(parent.context), parent, false)
- return CustomerAdapter.CustomerVH(binding, this)
- }
- override fun onBindViewHolder(holder: CustomerAdapter.CustomerVH, position: Int) {
- // val data = listGameBill[position]
- holder.bind(listGameBill[position])
- holder.clGameBill.setOnClickListener {
- mCallback?.onItemClicked(position)
- }
- }
- override fun getItemCount(): Int {
- var count = 0
- if (listGameBill != null) count += listGameBill.size
- return count
- }
- //nah pakai yang custom ini item clicknya
- class CustomerVH(val binding: ListitemPpobGameBillBinding) :
- RecyclerView.ViewHolder(binding.root) {
- var tvTextName: TextView? = null
- var tvTextPrice: TextView? = null
- var clGameBill: ConstraintLayout? = null
- private var selectedPosition: Int? = null
- init {
- selectedPosition = null
- tvTextName = binding.textName
- tvTextPrice = binding.textPrice
- clGameBill = binding.clGameBill
- }
- fun bind(data: PpobTypeGroupDetail) {
- val decimalFormat = DecimalFormat("##,###,###")
- val hargaJual = data.hargaJual ?: 0
- with(binding) {
- tvTextName!!.text = data.detail
- tvTextPrice!!.text = data.fhargaJual
- selectedPosition = bindingAdapterPosition
- clGameBill.setOnClickListener {
- selectedPosition = bindingAdapterPosition
- }
- when (selectedPosition) {
- null -> {
- tvTextName!!.setTextColor(Color.parseColor("#000000"))
- tvTextPrice!!.setTextColor(Color.parseColor("#808080"))
- clGameBill.background = root.context.getDrawable(R.drawable.bg_round_border_grey)
- }
- bindingAdapterPosition -> {
- tvTextName!!.setTextColor(Color.parseColor("#1976D2"))
- tvTextPrice!!.setTextColor(Color.parseColor("#4CAF50"))
- clGameBill.background = root.context.getDrawable(R.drawable.bg_round_border_grey_disable)
- }
- else -> {
- tvTextName!!.setTextColor(Color.parseColor("#000000"))
- tvTextPrice!!.setTextColor(Color.parseColor("#808080"))
- clGameBill.background = root.context.getDrawable(R.drawable.bg_round_border_grey)
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement