Open zakirhussain49 opened 3 years ago
Share your code so i can check it
Hi, this is the code with notifyItemChanged
of your InstagramRecyclerAdapter
class
package app.videoplayerinsiderecyclerview.views.instagramScreen
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import app.videoplayerinsiderecyclerview.R
import app.videoplayerinsiderecyclerview.databinding.InstagramTimelineItemRecyclerBinding
import app.videoplayerinsiderecyclerview.models.MediaObject
import app.videoplayerinsiderecyclerview.utils.PlayerStateCallback
import app.videoplayerinsiderecyclerview.utils.PlayerViewAdapter
import com.google.android.exoplayer2.Player
import java.util.*
/**
* A custom adapter to use with the RecyclerView widget.
*/
class InstagramRecyclerAdapter(
private val mContext: Context,
private var modelList: ArrayList<MediaObject>) : RecyclerView.Adapter<RecyclerView.ViewHolder>(),
PlayerStateCallback {
private var mItemClickListener: OnItemClickListener? = null
fun updateList(modelList: ArrayList<MediaObject>) {
this.modelList = modelList
notifyDataSetChanged()
}
override fun onCreateViewHolder(
viewGroup: ViewGroup,
viewType: Int
): VideoPlayerViewHolder {
val binding: InstagramTimelineItemRecyclerBinding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.context)
, R.layout.instagram_timeline_item_recycler, viewGroup, false)
return VideoPlayerViewHolder(binding)
}
override fun onBindViewHolder(
holder: RecyclerView.ViewHolder,
position: Int
) {
//Here you can fill your row view
if (holder is VideoPlayerViewHolder) {
val model = getItem(position)
val genericViewHolder = holder
// send data to view holder
genericViewHolder.onBind(model)
}
}
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
val position = holder.adapterPosition
PlayerViewAdapter.releaseRecycledPlayers(position)
super.onViewRecycled(holder)
}
override fun getItemCount(): Int {
return modelList.size
}
private fun getItem(position: Int): MediaObject {
return modelList[position]
}
fun SetOnItemClickListener(mItemClickListener: OnItemClickListener?) {
this.mItemClickListener = mItemClickListener
}
interface OnItemClickListener {
fun onItemClick(
view: View?,
position: Int,
model: MediaObject?
)
}
inner class VideoPlayerViewHolder(private val binding: InstagramTimelineItemRecyclerBinding) : RecyclerView.ViewHolder(binding.root) {
fun onBind(model: MediaObject) {
// handel on item click
binding.root.setOnClickListener {
//TODO : Added this line
model.isMute = !model.isMute
notifyItemChanged(adapterPosition)
mItemClickListener!!.onItemClick(
it,
adapterPosition,
model
)
}
binding.apply {
dataModel = model
callback = this@InstagramRecyclerAdapter
index = adapterPosition
executePendingBindings()
}
}
}
override fun onVideoDurationRetrieved(duration: Long, player: Player) {
}
override fun onVideoBuffering(player: Player) {
}
override fun onStartedPlaying(player: Player) {
}
override fun onFinishedPlaying(player: Player) {
}
}
Is there any update on this. I am facing similar issue exo player become black after notify data set change.
i am using kohii library
@Krutika-chotara @Faiyyazauxy @MostafaAnter any update on above issue ? I am also facing the same issue when I call "notifyItemCahnged(adapterPosition)".
When I add data in recycleview and try to scroll on particular index , player not working .
mBinding.recyclerView.scrollToPosition(scrollPosition);
Please help me how i achieve the task