SHARE
TWEET

Untitled

a guest May 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ru.feedback.app
  2.  
  3. import android.os.Bundle
  4. import android.support.v7.widget.RecyclerView
  5. import android.view.View
  6. import android.view.ViewGroup
  7. import com.hannesdorfmann.adapterdelegates3.AdapterDelegate
  8. import kotlinx.android.synthetic.main.item_search_result_product.view.*
  9. import ru.feedback.app.domain.catalog.BasketItem
  10. import ru.feedback.app.domain.catalog.Product
  11. import ru.feedback.app.extension.inflate
  12. import ru.feedback.app.extension.loadImage
  13. import ru.feedback.app.extension.toPriceString
  14. import ru.feedback.app.presentation.promo.PromoStartParams
  15. import ru.feedback.app.ui.global.IconKeys
  16. import ru.feedback.app.ui.global.IconLoader
  17. import ru.feedback.app.ui.promo.PromoFragment
  18.  
  19.  
  20. class RecomendationsAdapterDelegate(
  21.     private val companyId: Long,
  22.     private val productClickListener: (Product, Long) -> Unit
  23. ) : AdapterDelegate<MutableList<Any>>() {
  24.  
  25.     override fun isForViewType(items: MutableList<Any>, position: Int) =
  26.             items[position] is Product
  27.  
  28.     override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder =
  29.             ViewHolder(parent.inflate(R.layout.item_recommend_result_product))
  30.  
  31.     override fun onBindViewHolder(
  32.             items: MutableList<Any>,
  33.             position: Int,
  34.             viewHolder: RecyclerView.ViewHolder,
  35.             payloads: MutableList<Any>
  36.     ) = (viewHolder as ViewHolder).bind(items[position] as Product)
  37.  
  38.     private inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
  39.  
  40.  
  41.  
  42.  
  43.         private lateinit var item: Product
  44.  
  45.         init {
  46.             view.run {
  47.                productRoot.setOnClickListener { productClickListener (item, companyId)}
  48.             }
  49.         }
  50.  
  51.         fun bind(item: Product) {
  52.             //this.item2 = productdata as Product
  53.             this@ViewHolder.item = item
  54.             with(itemView) {
  55.                 productName.text = item.name
  56.                 productPrice.text = item.cost.toPriceString()
  57.                 IconLoader.loadIcon(context, IconKeys.Common.PLACEHOLDER_IMAGE) { placeholder ->
  58.                     productIcon.loadImage(item.logotype, placeholderBitmap = placeholder)
  59.                 }
  60.             }
  61.  
  62.  
  63.         }
  64.     }
  65.  
  66.    /* companion object {
  67.         private const val ARG_COMPANY_ID = "arg_company_id"
  68.  
  69.         fun newInstance(startParams: RecomendationsAdapterDelegate) = RecomendationsAdapterDelegate().apply {
  70.             arguments = Bundle().apply {
  71.                 putLong(ARG_COMPANY_ID, startParams.companyId)
  72.             }
  73.         }
  74.     }*/
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top