Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. package com.udacoding.wisatapedia.control.ui.activity.transaction
  2.  
  3. import android.annotation.SuppressLint
  4. import android.support.v7.widget.RecyclerView
  5. import android.util.Log
  6. import android.view.LayoutInflater
  7. import android.view.View
  8. import android.view.ViewGroup
  9. import android.widget.CheckBox
  10. import com.blogbasbas.yukkotlin.util.currencyFormatter
  11. import com.bumptech.glide.Glide
  12. import com.bumptech.glide.request.RequestOptions
  13. import com.google.gson.Gson
  14. import com.udacoding.wisatapedia.BuildConfig
  15. import com.udacoding.wisatapedia.R
  16. import com.udacoding.wisatapedia.db.model_db.TransactionModel
  17. import kotlinx.android.synthetic.main.content_list_transaction.view.*
  18.  
  19.  
  20. /**
  21. * Created by User on 18/02/2019.
  22. */
  23. class RvAdapterTransaction(val data: List<TransactionModel>,
  24. private val listenerMin: (TransactionModel) -> Unit,
  25. private val listenerAdd: (TransactionModel) -> Unit,
  26. private val listenerDelete: (TransactionModel) -> Unit
  27. ) : RecyclerView.Adapter<RvAdapterTransaction.ViewHolder>() {
  28.  
  29. // open val transactionModelArrayList: ArrayList<TransactionModel>? = null
  30.  
  31. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  32. val view: View = LayoutInflater.from(parent.context).inflate(R.layout.content_list_transaction, parent, false)
  33. return ViewHolder(view)
  34.  
  35. }
  36.  
  37. override fun getItemCount(): Int = data.size
  38.  
  39.  
  40. // var mCheckedIds = SparseBooleanArray()
  41. // fun checkCheckBox(pos: Int, value: Boolean) {
  42. // if (value) {
  43. // mCheckedIds.put(pos, true)
  44. //
  45. // } else {
  46. // mCheckedIds.delete(pos)
  47. // }
  48. // notifyDataSetChanged()
  49. // }
  50.  
  51. @SuppressLint("SetTextI18n")
  52. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  53.  
  54. var dataItem = data?.get(position)
  55.  
  56. holder.bindItem(data[position], listenerMin, listenerAdd, listenerDelete)
  57. holder.setIsRecyclable(false)
  58.  
  59.  
  60. // holder.view.chekcbox_title_at_transaction.isChecked = mCheckedIds.get(position)
  61. // holder.view.chekcbox_name_transaction.isChecked = mCheckedIds.get(position)
  62.  
  63.  
  64. holder.view.chekcbox_name_transaction.isChecked = data.get(position).getChecked()
  65. holder.view.chekcbox_name_transaction.tag = data.get(position)
  66.  
  67.  
  68. holder.view.chekcbox_name_transaction.setOnClickListener {
  69.  
  70. val check = it as CheckBox
  71. val dataChekbox = check.tag as TransactionModel
  72. dataChekbox.setChecked(check.isChecked)
  73. data.get(position).setChecked(check.isChecked)
  74.  
  75. Log.e("tag","data checkbox ${Gson().toJson(dataChekbox)}")
  76. Log.e("tag","data ${data.get(position).setChecked(check.isChecked)}")
  77.  
  78. }
  79.  
  80. holder.view.chekcbox_title_at_transaction.setOnClickListener {
  81. // checkBox(position, holder)
  82. }
  83.  
  84.  
  85.  
  86.  
  87. 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)
  88. 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)
  89.  
  90. holder.view.tv_title_seller_transaction_acitivity.text = dataItem.sellerProduct
  91. holder.view.tv_name_category_at_trasanction.text = dataItem.nameCategory
  92. holder.view.tv_name_product_at_transaction.text = "E-Ticket - " + dataItem.titleProduct
  93. holder.view.integer_number_amount.text = dataItem.amountProduct
  94. holder.view.tv_price_product_list_transaction.text = "Rp" + currencyFormatter(dataItem.priceProduct.toString())
  95.  
  96.  
  97. }
  98.  
  99. private fun checkBox(position: Int, holder: ViewHolder) {
  100. // if (data.get(position).getChecked()) {
  101. // data.get(position).setChecked(false)
  102. // holder.view.chekcbox_title_at_transaction.isChecked = false
  103. // holder.view.chekcbox_name_transaction.isChecked = false
  104. //
  105. // Log.e("TAG ", "checkbox transaction unchecked:")
  106. //
  107. //
  108. //
  109. // } else {
  110. //
  111. // data.get(position).setChecked(true)
  112. // holder.view.chekcbox_title_at_transaction.isChecked = true
  113. // holder.view.chekcbox_name_transaction.isChecked = true
  114. // Log.e("TAG ", "checkbox transaction checked:")
  115. // }
  116.  
  117. }
  118.  
  119.  
  120. class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
  121.  
  122.  
  123. fun bindItem(transactionModel: TransactionModel,
  124. listenerMin: (TransactionModel) -> Unit,
  125. listenerAdd: (TransactionModel) -> Unit,
  126. listinerDelete: (TransactionModel) -> Unit) {
  127.  
  128.  
  129. view.btn_decrease.setOnClickListener {
  130. listenerMin(transactionModel)
  131.  
  132. }
  133. view.btn_increase.setOnClickListener {
  134. listenerAdd(transactionModel)
  135. }
  136. view.btn_delete_transaction.setOnClickListener {
  137. listinerDelete(transactionModel)
  138. }
  139.  
  140.  
  141. }
  142.  
  143. }
  144.  
  145.  
  146. fun getDataCheckBox(): List<TransactionModel> {
  147. return data
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement