SHARE
TWEET

Untitled

a guest Sep 15th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.dycode.edu.firebasestrorageexamples
  2.  
  3. import androidx.appcompat.app.AppCompatActivity
  4. import android.os.Bundle
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup
  8. import androidx.appcompat.widget.ScrollingTabContainerView
  9. import androidx.recyclerview.widget.RecyclerView
  10. import com.bumptech.glide.Glide
  11. import com.firebase.ui.firestore.FirestoreRecyclerAdapter
  12. import com.firebase.ui.firestore.FirestoreRecyclerOptions
  13. import com.google.android.gms.common.data.DataHolder
  14. import com.google.firebase.firestore.FirebaseFirestore
  15. import kotlinx.android.extensions.LayoutContainer
  16. import kotlinx.android.synthetic.main.activity_show_image.*
  17. import kotlinx.android.synthetic.main.item_image.*
  18. import kotlinx.android.synthetic.main.item_image.view.*
  19.  
  20. class ShowImageActivity : AppCompatActivity() {
  21.  
  22.     lateinit var firebaseFirestore: FirebaseFirestore
  23.     lateinit var adapter: FirestoreRecyclerAdapter<MImage>
  24.  
  25.     override fun onCreate(savedInstanceState: Bundle?) {
  26.         super.onCreate(savedInstanceState)
  27.         setContentView(R.layout.activity_show_image)
  28.  
  29.         firebaseFirestore = FirebaseFirestore.getInstance()
  30.         getImageList()
  31.     }
  32.  
  33.     private fun getImageList() {
  34.         val query = firebaseFirestore.collection("posts")
  35.  
  36.         val response = FirestoreRecyclerOptions.Builder<MImage>()
  37.             .setQuery(query, MImage::class.java).build()
  38.  
  39.         val adapter = object : FirestoreRecyclerAdapter<MImage, ImageHolder>(response) {
  40.             override fun onBindViewHolder(holder: ImageHolder?, pos: Int, data: MImage?) {
  41.                 if (holder!=null) {
  42.                     Glide.with(applicationContext).load(data?.imageUrl).into(holder.img_item_image)
  43.                 }
  44.             }
  45.  
  46.             override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageHolder {
  47.                 val view = LayoutInflater.from(parent.context).inflate(R.layout.item_image, parent, false)
  48.                 return ImageHolder(view)
  49.             }
  50.         }
  51.        
  52.         adapter.notifyDataSetChanged()
  53.         rv_image.adapter = adapter
  54.     }
  55.    
  56.     inner class ImageHolder(override val containerView: View):
  57.             RecyclerView.ViewHolder(containerView), LayoutContainer{
  58.         val img_item_image = containerView.img_item_image
  59.     }
  60. }
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