SHARE
TWEET

Untitled

a guest Jun 16th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. open class JobsAdapter(private val jobs: ArrayList<JobModel>, private val ctx: Context, private val click: Click) : RecyclerView.Adapter<JobsAdapter.JobsHolder>() {
  2.     lateinit var view: View
  3.  
  4.  
  5.     override fun onCreateViewHolder(viewGroup: ViewGroup, p1: Int): JobsHolder {
  6.         view = LayoutInflater.from(viewGroup.context).inflate(R.layout.job_list_item, viewGroup, false)
  7.         return JobsHolder(view)
  8.     }
  9.  
  10.     override fun getItemCount(): Int {
  11.         return jobs.size
  12.     }
  13.  
  14.  
  15.     override fun onBindViewHolder(holder: JobsHolder, position: Int) {
  16.         val jobModel = jobs[position]
  17.         holder.tvPosition.text = jobModel.position
  18.         holder.tvAddress.text = jobModel.location
  19.         holder.tvCompany.text = jobModel.company_name
  20.  
  21.         holder.itemView.setOnClickListener {
  22.             if (!jobModel.isSeen) {
  23.                     Singleton.clickReq(jobModel.id, ctx)
  24.  
  25.             }
  26.  
  27.             holder.itemView.background = ContextCompat.getDrawable(ctx, R.drawable.message_list_item_bg)
  28.  
  29.             click.sendData(Uri.parse(jobModel.job_link).toString(), holder.adapterPosition, jobModel.position!!)
  30.         }
  31.  
  32.         holder.ivAddTo.setOnClickListener {
  33.             holder.progressBar.visibility = View.VISIBLE
  34.             holder.ivAddTo.setBackgroundResource(R.drawable.added_to_notepad)
  35.             holder.ivAddTo.visibility = View.GONE
  36.             holder.ivAddTo.isClickable = false
  37.             Singleton.jobLstPos = position
  38.  
  39.  
  40.  
  41.                 saveToNotepad(jobModel.id)
  42.         }
  43.  
  44.  
  45.         if (jobModel.isSeen) {
  46.             holder.itemView.background = ContextCompat.getDrawable(ctx, R.drawable.message_list_item_bg)
  47.         } else {
  48.             holder.itemView.setBackgroundColor(Color.parseColor("#fafafa"))
  49.         }
  50.     }
  51.  
  52.     override fun onBindViewHolder(holder: JobsHolder, position: Int, payloads: List<Any>) {
  53.         if (payloads.isNotEmpty()) {
  54.             when (payloads[0]) {
  55.                 1 -> {
  56.                     holder.ivAddTo.visibility = View.GONE
  57.                 }
  58.             }
  59.         } else {
  60.             super.onBindViewHolder(holder, position, payloads)
  61.         }
  62.     }
  63.  
  64.     private fun saveToNotepad(id: Int) {
  65.         Singleton.apiService(ctx).saveTo("Bearer " + ctx.getSharedPreferences("appD", 0).getString("access_token", ""), id).enqueue(object : Callback<SaveTo> {
  66.             override fun onResponse(call: Call<SaveTo>, response: Response<SaveTo>) {
  67.                 if (response.isSuccessful) {
  68.                     notifyItemChanged(view.getTag(R.id.tag_3) as Int, 1)
  69.                 }
  70.             }
  71.  
  72.             override fun onFailure(call: Call<SaveTo>, t: Throwable) {
  73.             }
  74.         })
  75.     }
  76.  
  77.     class JobsHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  78.         var tvCompany = itemView.findViewById<TextView>(R.id.tv_company)!!
  79.         var tvDate = itemView.findViewById<TextView>(R.id.tv_date)!!
  80.         var tvPosition = itemView.findViewById<TextView>(R.id.tv_job_title)!!
  81.         var tvAddress = itemView.findViewById<TextView>(R.id.tv_address)!!
  82.         var ivAddTo = itemView.findViewById<ImageView>(R.id.add_to_notepad)!!
  83.         var progressBar = itemView.findViewById<ProgressBar>(R.id.progressBar)
  84.     }
  85. }
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