Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.udacoding.wisatapedia.control.ui.activity.transaction
- import android.annotation.SuppressLint
- import android.support.v7.widget.RecyclerView
- import android.util.Log
- import android.view.LayoutInflater
- import android.view.View
- import android.view.ViewGroup
- import android.widget.CheckBox
- import com.blogbasbas.yukkotlin.util.currencyFormatter
- import com.bumptech.glide.Glide
- import com.bumptech.glide.request.RequestOptions
- import com.google.gson.Gson
- import com.udacoding.wisatapedia.BuildConfig
- import com.udacoding.wisatapedia.R
- import com.udacoding.wisatapedia.db.model_db.TransactionModel
- import kotlinx.android.synthetic.main.content_list_transaction.view.*
- /**
- * Created by User on 18/02/2019.
- */
- class RvAdapterTransaction(val data: List<TransactionModel>,
- private val listenerMin: (TransactionModel) -> Unit,
- private val listenerAdd: (TransactionModel) -> Unit,
- private val listenerDelete: (TransactionModel) -> Unit
- ) : RecyclerView.Adapter<RvAdapterTransaction.ViewHolder>() {
- // open val transactionModelArrayList: ArrayList<TransactionModel>? = null
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
- val view: View = LayoutInflater.from(parent.context).inflate(R.layout.content_list_transaction, parent, false)
- return ViewHolder(view)
- }
- override fun getItemCount(): Int = data.size
- // var mCheckedIds = SparseBooleanArray()
- // fun checkCheckBox(pos: Int, value: Boolean) {
- // if (value) {
- // mCheckedIds.put(pos, true)
- //
- // } else {
- // mCheckedIds.delete(pos)
- // }
- // notifyDataSetChanged()
- // }
- @SuppressLint("SetTextI18n")
- override fun onBindViewHolder(holder: ViewHolder, position: Int) {
- var dataItem = data?.get(position)
- holder.bindItem(data[position], listenerMin, listenerAdd, listenerDelete)
- holder.setIsRecyclable(false)
- // holder.view.chekcbox_title_at_transaction.isChecked = mCheckedIds.get(position)
- // holder.view.chekcbox_name_transaction.isChecked = mCheckedIds.get(position)
- holder.view.chekcbox_name_transaction.isChecked = data.get(position).getChecked()
- holder.view.chekcbox_name_transaction.tag = data.get(position)
- holder.view.chekcbox_name_transaction.setOnClickListener {
- val check = it as CheckBox
- val dataChekbox = check.tag as TransactionModel
- dataChekbox.setChecked(check.isChecked)
- data.get(position).setChecked(check.isChecked)
- Log.e("tag","data checkbox ${Gson().toJson(dataChekbox)}")
- Log.e("tag","data ${data.get(position).setChecked(check.isChecked)}")
- }
- holder.view.chekcbox_title_at_transaction.setOnClickListener {
- // checkBox(position, holder)
- }
- Glide.with(holder.view).load(BuildConfig.HOST_URL + "images/tours/product/default/${dataItem.photoProduct}").apply(RequestOptions.placeholderOf(R.drawable.ic_launcher_background)).into(holder.view.img_title_transaction)
- Glide.with(holder.view).load(BuildConfig.HOST_URL + "images/tours/product/default/${dataItem.photoProduct}").apply(RequestOptions.placeholderOf(R.drawable.ic_launcher_background)).into(holder.view.img_product_list_transaction)
- holder.view.tv_title_seller_transaction_acitivity.text = dataItem.sellerProduct
- holder.view.tv_name_category_at_trasanction.text = dataItem.nameCategory
- holder.view.tv_name_product_at_transaction.text = "E-Ticket - " + dataItem.titleProduct
- holder.view.integer_number_amount.text = dataItem.amountProduct
- holder.view.tv_price_product_list_transaction.text = "Rp" + currencyFormatter(dataItem.priceProduct.toString())
- }
- private fun checkBox(position: Int, holder: ViewHolder) {
- // if (data.get(position).getChecked()) {
- // data.get(position).setChecked(false)
- // holder.view.chekcbox_title_at_transaction.isChecked = false
- // holder.view.chekcbox_name_transaction.isChecked = false
- //
- // Log.e("TAG ", "checkbox transaction unchecked:")
- //
- //
- //
- // } else {
- //
- // data.get(position).setChecked(true)
- // holder.view.chekcbox_title_at_transaction.isChecked = true
- // holder.view.chekcbox_name_transaction.isChecked = true
- // Log.e("TAG ", "checkbox transaction checked:")
- // }
- }
- class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
- fun bindItem(transactionModel: TransactionModel,
- listenerMin: (TransactionModel) -> Unit,
- listenerAdd: (TransactionModel) -> Unit,
- listinerDelete: (TransactionModel) -> Unit) {
- view.btn_decrease.setOnClickListener {
- listenerMin(transactionModel)
- }
- view.btn_increase.setOnClickListener {
- listenerAdd(transactionModel)
- }
- view.btn_delete_transaction.setOnClickListener {
- listinerDelete(transactionModel)
- }
- }
- }
- fun getDataCheckBox(): List<TransactionModel> {
- return data
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement