SHARE
TWEET

Untitled

a guest Feb 26th, 2020 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.e_commerce.fragment
  2.  
  3. import android.annotation.SuppressLint
  4. import android.graphics.Color
  5. import android.os.Bundle
  6. import android.util.Log
  7. import android.view.LayoutInflater
  8. import android.view.View
  9. import android.view.ViewGroup
  10. import android.widget.TextView
  11. import android.widget.Toast
  12. import androidx.appcompat.app.AppCompatActivity
  13. import androidx.appcompat.widget.Toolbar
  14. import androidx.fragment.app.Fragment
  15. import androidx.fragment.app.FragmentActivity
  16. import androidx.recyclerview.widget.LinearLayoutManager
  17. import com.example.e_commerce.R
  18. import com.example.e_commerce.adapter.WishlistAdapter
  19. import com.example.e_commerce.helper.SharedPrefHelper
  20. import com.example.e_commerce.model.Wishlist
  21. import com.example.e_commerce.presenter.WishlistPresenter
  22. import com.example.e_commerce.view.WishlistView
  23. import kotlinx.android.synthetic.main.fragment_wishlist.*
  24. import kotlinx.android.synthetic.main.item_wishlist.*
  25.  
  26. class WishlistFragment : Fragment(),WishlistView {
  27.  
  28.     private var items : MutableList<Wishlist> = mutableListOf()
  29.     private lateinit var adapter: WishlistAdapter
  30.  
  31.     private lateinit var item : Wishlist
  32.     private lateinit var presenter: WishlistPresenter
  33.  
  34.     override fun onCreateView(
  35.         inflater: LayoutInflater, container: ViewGroup?,
  36.         savedInstanceState: Bundle?
  37.     ): View? {
  38.         // Inflate the layout for this fragment
  39.         return inflater.inflate(R.layout.fragment_wishlist, container, false)
  40.     }
  41.  
  42.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  43.         super.onViewCreated(view, savedInstanceState)
  44.         setToolbar()
  45.  
  46.         val sharedPreference: SharedPrefHelper = SharedPrefHelper(activity!!.applicationContext)
  47.         val cus_id = sharedPreference.getValueString("cus_id")
  48.  
  49.         presenter = WishlistPresenter(this)
  50.         presenter.getWishlist(cus_id.toString())
  51.  
  52.         adapter = WishlistAdapter(items){}
  53.         adapter.notifyDataSetChanged()
  54.  
  55.         rv_wishlist.layoutManager = LinearLayoutManager(activity)
  56.         rv_wishlist.adapter = adapter
  57.         rv_wishlist.setHasFixedSize(true)
  58.  
  59.     }
  60.  
  61.     override fun onResume() {
  62.         super.onResume()
  63.         rv_wishlist.adapter!!.notifyDataSetChanged()
  64.     }
  65.  
  66.     override fun shwoWishlis(data: List<Wishlist>) {
  67.  
  68.         items.clear()
  69.         items.addAll(data)
  70.  
  71.         item = Wishlist(
  72.             data[0].cusId,
  73.             data[0].id,
  74.             data[0].proId,
  75.             data[0].proImage,
  76.             data[0].proPrice,
  77.             data[0].proTitle
  78.         )
  79.  
  80.         val sharedPreference: SharedPrefHelper = SharedPrefHelper(activity!!.applicationContext)
  81.         val cus_id = sharedPreference.getValueString("cus_id")
  82.  
  83.         /*btn_delete_from_wishlist.setOnClickListener{
  84.             presenter.postWishlist(cus_id.toString(),data[0].proId!!)
  85.         }*/
  86.  
  87.         adapter.notifyDataSetChanged()
  88.         rv_wishlist.adapter = adapter
  89.  
  90.  
  91.     }
  92.  
  93.     override fun onFailedGet() {
  94.         Toast.makeText(activity,"Data Kosong",Toast.LENGTH_SHORT).show()
  95.  
  96.     }
  97.  
  98.     override fun onFailedPost() {
  99.  
  100.  
  101.     }
  102.  
  103.     private fun setToolbar() {
  104.         val toolbar = activity!!.findViewById<View>(R.id.toolbar) as Toolbar
  105.         (activity as AppCompatActivity).setSupportActionBar(toolbar)
  106.         toolbar.background = context!!.getDrawable(R.drawable.bg_semi_black)
  107.  
  108.         val toolbarText = activity!!.findViewById<View>(R.id.toolbar_text) as TextView
  109.         if (toolbarText != null && toolbar != null) {
  110.             toolbarText.text = "Favorite"
  111.             toolbarText.setTextColor(Color.WHITE)
  112.             (activity as AppCompatActivity).setSupportActionBar(toolbar)
  113.         }
  114.  
  115.     }
  116.  
  117.     override fun postWishlist(data: Wishlist) {
  118.         var frg: Fragment? = null
  119.         frg =  (context as FragmentActivity).supportFragmentManager.findFragmentById(R.id.wishlist_container)
  120.         val ft = (context as FragmentActivity).supportFragmentManager.beginTransaction()
  121.         ft.detach(frg!!)
  122.         ft.attach(frg!!)
  123.         ft.commit()
  124.  
  125.         adapter.notifyDataSetChanged()
  126.         rv_wishlist.adapter = adapter
  127.  
  128.     }
  129.  
  130.  
  131. }
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