SHARE
TWEET

Untitled

a guest Feb 26th, 2020 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.e_commerce.adapter
  2.  
  3. import android.app.Activity
  4. import android.util.Log
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup
  8. import androidx.recyclerview.widget.RecyclerView
  9. import com.example.e_commerce.R
  10. import com.example.e_commerce.helper.SharedPrefHelper
  11. import com.example.e_commerce.model.Wishlist
  12. import com.example.e_commerce.presenter.WishlistPresenter
  13. import com.example.e_commerce.view.WishlistView
  14. import com.squareup.picasso.Picasso
  15. import kotlinx.android.synthetic.main.item_wishlist.view.*
  16. import androidx.fragment.app.Fragment
  17. import androidx.fragment.app.FragmentActivity
  18. import android.app.PendingIntent.getActivity
  19. import android.widget.Toast
  20. import com.example.e_commerce.fragment.WishlistFragment
  21. import com.example.e_commerce.model.AddWishlist
  22. import com.example.e_commerce.presenter.AddWishlistPresenter
  23. import com.example.e_commerce.view.AddWishtlistView
  24.  
  25.  
  26.  
  27. class WishlistAdapter (val product: List<Wishlist>, val listener : (Wishlist)->(Unit))
  28.     : RecyclerView.Adapter<WishlistViewHolder>(){
  29.  
  30.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WishlistViewHolder {
  31.         return WishlistViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_wishlist,parent,false))
  32.     }
  33.  
  34.     override fun getItemCount(): Int = product.size
  35.  
  36.     override fun onBindViewHolder(holder: WishlistViewHolder, position: Int) {
  37.         holder.bindItem(product[position],listener)
  38.  
  39.     }
  40.  
  41. }
  42.  
  43. class WishlistViewHolder(view: View): RecyclerView.ViewHolder(view), AddWishtlistView {
  44.     private var items: MutableList<Wishlist> = mutableListOf()
  45.  
  46.     private lateinit var presenter: AddWishlistPresenter
  47.  
  48.     fun bindItem(item: Wishlist, listener: (Wishlist) -> Unit) {
  49.         itemView.tv_name_product_wishlist.text = item.proTitle
  50.         item.proImage.let {
  51.             Picasso.get().load(it).into(itemView.iv_product_wishlist)
  52.         }
  53.  
  54.         itemView.setOnClickListener {
  55.             listener(item)
  56.         }
  57.  
  58.         presenter = AddWishlistPresenter(this)
  59.  
  60.         itemView.btn_delete_from_wishlist.setOnClickListener {
  61.             itemView.btn_delete_from_wishlist.setBackgroundResource(R.drawable.ic_favorite_white)
  62.             Log.e("cekcek", item.proTitle)
  63.             val sharedPreference: SharedPrefHelper = SharedPrefHelper(it.context)
  64.             val cus_id = sharedPreference.getValueString("cus_id")
  65.             presenter.postWishlist(cus_id.toString(), item.proId!!)
  66.             presenter.getWishlist(cus_id.toString())
  67.             Toast.makeText(it.context, "Delete Berhasil", Toast.LENGTH_SHORT).show()
  68.  
  69.  
  70.         }
  71.  
  72.  
  73.  
  74.     }
  75.  
  76.     override fun onSucces(data: AddWishlist) {
  77.  
  78.     }
  79.  
  80.     override fun postWishlist(data: Wishlist) {
  81.  
  82.     }
  83.  
  84.     override fun getWishlist(data: List<Wishlist>) {
  85.  
  86.     }
  87.  
  88.     override fun onFailedGet() {
  89.  
  90.     }
  91.  
  92.     override fun onFailedPost() {
  93.  
  94.     }
  95.  
  96. }
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