Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shine.adapter;
- import android.databinding.DataBindingUtil;
- import android.support.v7.util.DiffUtil;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.ViewGroup;
- import com.shine.bean.recivebean.VideoSourceBeans;
- import com.shine.ui.VideoSourceClickListener;
- import com.shine.videomeeting.R;
- import com.shine.videomeeting.databinding.ItemPreviewOptionBinding;
- import java.util.List;
- import java.util.Objects;
- /**
- * author:
- * 时间:2017/11/17
- * qq:1220289215
- * 类描述:预览页面信源列表
- */
- public class PreviewItemAdapter extends RecyclerView.Adapter<PreviewItemAdapter.ItemViewHolder>{
- List<VideoSourceBeans> mVideoSourceList;
- private VideoSourceClickListener mVideoSourceClickListener;
- public PreviewItemAdapter(VideoSourceClickListener videoSourceClickListener) {
- mVideoSourceClickListener = videoSourceClickListener;
- }
- public void setCommentList(final List<VideoSourceBeans> sourceBeans) {
- if (mVideoSourceList == null) {
- mVideoSourceList = sourceBeans;
- notifyItemRangeInserted(0, sourceBeans.size());
- } else {
- DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DiffUtil.Callback() {
- @Override
- public int getOldListSize() {
- return mVideoSourceList.size();
- }
- @Override
- public int getNewListSize() {
- return sourceBeans.size();
- }
- @Override
- public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
- VideoSourceBeans old = mVideoSourceList.get(oldItemPosition);
- VideoSourceBeans comment = sourceBeans.get(newItemPosition);
- return old.sourceid() == comment.sourceid();
- }
- @Override
- public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
- VideoSourceBeans old = mVideoSourceList.get(oldItemPosition);
- VideoSourceBeans beans = sourceBeans.get(newItemPosition);
- return old.sourceid() == beans.sourceid()
- && old.sourcecodetype() == beans.sourcecodetype()
- && Objects.equals(old.sourcename(), beans.sourcename());
- }
- });
- mVideoSourceList = sourceBeans;
- diffResult.dispatchUpdatesTo(this);
- }
- }
- @Override
- public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- LayoutInflater inflater = LayoutInflater.from(parent.getContext());
- ItemPreviewOptionBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_preview_option, parent, false);
- binding.setOnItemClickListener(mVideoSourceClickListener);
- return new ItemViewHolder(binding);
- }
- @Override
- public void onBindViewHolder(ItemViewHolder holder, int position) {
- VideoSourceBeans videoSourceBeans = mVideoSourceList.get(position);
- holder.mBinding.setVideoSource(videoSourceBeans);
- holder.mBinding.executePendingBindings();
- }
- @Override
- public int getItemCount() {
- return mVideoSourceList==null?0:mVideoSourceList.size();
- }
- static class ItemViewHolder extends RecyclerView.ViewHolder{
- private final ItemPreviewOptionBinding mBinding;
- public ItemViewHolder(ItemPreviewOptionBinding binding) {
- super(binding.getRoot());
- mBinding = binding;
- }
- }
- }
Add Comment
Please, Sign In to add comment