I want to fetch all the Video files from the Firebase Storage and display them in the RecyclerView. I have managed to get all the files, but I am not able to update the RecyclerView once I get all the files retrieved. Here is the code
recyclerViewVideoList.setHasFixedSize(true)
recyclerViewVideoList.layoutManager = LinearLayoutManager(this)
recyclerViewVideoList.adapter = VideoListRecyclerViewAdapter(applicationContext,videoList, this)
getVideos()
private fun getVideos() {
val listRef = firebaseStorage.reference.child("videos")
listRef.listAll()
.addOnSuccessListener { listResult ->
listResult.items.forEach { item ->
item.downloadUrl.addOnSuccessListener {
videoList.add(Video(item.name, it.toString(), "565656"))
}
}
recyclerViewVideoList.adapter!!.notifyDataSetChanged()
}
.addOnFailureListener {
Toast.makeText(applicationContext, "Something went wrong. Please try again", Toast.LENGTH_SHORT).show()
}
}
There is a solution here, but it calls the notifyDataSetChanged() multiple times. I want to avoid doing that.