SHARE
TWEET

Untitled

a guest Oct 15th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.gahfy.pseudokonkretnapka
  2.  
  3. import android.content.Context
  4. import android.util.Log
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup
  8. import android.widget.ImageView
  9. import androidx.constraintlayout.widget.ConstraintLayout
  10. import androidx.recyclerview.widget.RecyclerView
  11. import com.bumptech.glide.Glide
  12. import kotlinx.android.synthetic.main.my_text_view.view.*
  13.  
  14. class RvAdapter(val books: ArrayList<Book>, val context: Context) : RecyclerView.Adapter<ViewHolder>() {
  15.  
  16.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  17.         val view: View = (LayoutInflater.from(context).inflate(R.layout.my_text_view, parent, false))
  18.         return ViewHolder(view)
  19.     }
  20.  
  21.     override fun getItemCount(): Int {
  22.         return books.size
  23.     }
  24.  
  25.  
  26.     fun getItem(position: Int): Book {
  27.         return books[position]
  28.     }
  29.     override fun getItemId(position: Int): Long {
  30.         return super.getItemId(position)
  31.     }
  32.  
  33.     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  34.         val item = getItem(position)
  35.             holder.bindTo(item)
  36.             holder.itemView.setOnClickListener {
  37.                 clickListener?.onItemClick(item)
  38.             }
  39.     }
  40.  
  41.     interface ClickListener {
  42.         fun onItemClick(item: Book)
  43.     }
  44.     interface ScrollListener {
  45.         fun onScrollList(view: RecyclerView)
  46.     }
  47.     fun setClickListener(clickListener: ClickListener) {
  48.         this.clickListener = clickListener
  49.     }
  50.     private var clickListener: ClickListener? = null
  51. }
  52.  
  53. class ViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
  54.     fun bindTo(item: Book){
  55.         item.apply {
  56.             itemView.tvBookName.text = item.bookName
  57.             Glide
  58.                 .with(itemView.context)
  59.                 .load(item.pictureID)
  60.                 .into(itemView.ivObrazek)
  61.             zwieksz(itemView.ivObrazek, item.zwiekszony)
  62.         }
  63.     }
  64.     fun zwieksz(ivObrazek: ImageView, zwiekszony: Boolean){
  65.             if(zwiekszony) {
  66.                 ivObrazek.layoutParams = ConstraintLayout.LayoutParams(700, 700)
  67.             }
  68.             else{
  69.                 ivObrazek.layoutParams = ConstraintLayout.LayoutParams(157, 157)
  70.             }
  71.     }
  72. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top