Advertisement
Guest User

ProsesBooking

a guest
Nov 14th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.90 KB | None | 0 0
  1. class ProsesBooking : Fragment() {
  2.  
  3.  
  4.     private var listener: OnListFragmentInteractionListener? = null
  5.  
  6.     override fun onCreateView(
  7.         inflater: LayoutInflater, container: ViewGroup?,
  8.         savedInstanceState: Bundle?
  9.     ): View? {
  10.         val view = inflater.inflate(R.layout.fragment_item_list, container, false)
  11.  
  12.  
  13.         this.exPlore()
  14.  
  15.         return view
  16.     }
  17.  
  18.     private fun exPlore() {
  19.         val auth = FirebaseAuth.getInstance()
  20.  
  21.  
  22.         val database = FirebaseDatabase.getInstance()
  23.         val myRef = database.getReference(Constan.tb_Booking)
  24.  
  25.         val data = ArrayList<Booking>()
  26.         val query = myRef.orderByChild("driver").equalTo(auth.currentUser?.uid)
  27.  
  28.         query.addValueEventListener(object : ValueEventListener {
  29.             override fun onDataChange(dataSnapshot: DataSnapshot) {
  30.  
  31.                 for (issue in dataSnapshot.children) {
  32.  
  33.                     val dataFirebase = issue.getValue(Booking::class.java)
  34.  
  35.                     if (dataFirebase?.status == 2) {
  36.  
  37.  
  38.                         val booking = Booking()
  39.                         booking.tanggal = dataFirebase.tanggal
  40.                         booking.uid = dataFirebase.uid
  41.                         booking.lokasiAwal = dataFirebase.lokasiAwal
  42.                         booking.latAwal = dataFirebase.latAwal
  43.                         booking.lonAwal = dataFirebase.lonAwal
  44.                         booking.latTujuan = dataFirebase.latAwal
  45.                         booking.lonTujuan = dataFirebase.lonTujuan
  46.                         booking.lokasiTujuan = dataFirebase.lokasiTujuan
  47.                         booking.jarak = dataFirebase.jarak
  48.                         booking.harga = dataFirebase.harga
  49.                         booking.status = dataFirebase.status
  50.                         data.add(booking)
  51.  
  52.  
  53.  
  54.                         showData(data)
  55.  
  56.                     }
  57.                 }
  58.  
  59.  
  60.             }
  61.  
  62.             override fun onCancelled(error: DatabaseError) {
  63.                 // Failed to read value
  64.  
  65.             }
  66.         })
  67.  
  68.  
  69.     }
  70.  
  71.     private fun showData(data: ArrayList<Booking>) {
  72.  
  73.         try {
  74.             list.adapter = BookingAdapter(data, object : OnListFragmentInteractionListener,
  75.                 RequestBooking.OnListFragmentInteractionListener {
  76.                 override fun onListFragmentInteraction(item: Booking?) {
  77.  
  78.                     startActivity<DetailRequest>(Constan.booking to item!!, Constan.status to 2)
  79.                 }
  80.             })
  81.             list.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
  82.  
  83.         } catch (e: IllegalStateException) {
  84.  
  85.         }
  86.     }
  87.  
  88.  
  89.     override fun onDetach() {
  90.         super.onDetach()
  91.         listener = null
  92.     }
  93.  
  94.  
  95.     interface OnListFragmentInteractionListener {
  96.         // TODO: Update argument type and name
  97.         fun onListFragmentInteraction(item: Booking?)
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement