Guest User

Untitled

a guest
Nov 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. package com.shine.adapter;
  2.  
  3. import android.databinding.DataBindingUtil;
  4. import android.support.v7.util.DiffUtil;
  5. import android.support.v7.widget.RecyclerView;
  6. import android.view.LayoutInflater;
  7. import android.view.ViewGroup;
  8.  
  9. import com.shine.bean.recivebean.VideoSourceBeans;
  10. import com.shine.ui.VideoSourceClickListener;
  11. import com.shine.videomeeting.R;
  12. import com.shine.videomeeting.databinding.ItemPreviewOptionBinding;
  13.  
  14. import java.util.List;
  15. import java.util.Objects;
  16.  
  17. /**
  18. * author:
  19. * 时间:2017/11/17
  20. * qq:1220289215
  21. * 类描述:预览页面信源列表
  22. */
  23.  
  24. public class PreviewItemAdapter extends RecyclerView.Adapter<PreviewItemAdapter.ItemViewHolder>{
  25. List<VideoSourceBeans> mVideoSourceList;
  26. private VideoSourceClickListener mVideoSourceClickListener;
  27.  
  28. public PreviewItemAdapter(VideoSourceClickListener videoSourceClickListener) {
  29. mVideoSourceClickListener = videoSourceClickListener;
  30. }
  31.  
  32. public void setCommentList(final List<VideoSourceBeans> sourceBeans) {
  33. if (mVideoSourceList == null) {
  34. mVideoSourceList = sourceBeans;
  35. notifyItemRangeInserted(0, sourceBeans.size());
  36. } else {
  37. DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DiffUtil.Callback() {
  38. @Override
  39. public int getOldListSize() {
  40. return mVideoSourceList.size();
  41. }
  42.  
  43. @Override
  44. public int getNewListSize() {
  45. return sourceBeans.size();
  46. }
  47.  
  48. @Override
  49. public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
  50. VideoSourceBeans old = mVideoSourceList.get(oldItemPosition);
  51. VideoSourceBeans comment = sourceBeans.get(newItemPosition);
  52. return old.sourceid() == comment.sourceid();
  53. }
  54.  
  55. @Override
  56. public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
  57. VideoSourceBeans old = mVideoSourceList.get(oldItemPosition);
  58. VideoSourceBeans beans = sourceBeans.get(newItemPosition);
  59. return old.sourceid() == beans.sourceid()
  60. && old.sourcecodetype() == beans.sourcecodetype()
  61. && Objects.equals(old.sourcename(), beans.sourcename());
  62. }
  63. });
  64. mVideoSourceList = sourceBeans;
  65. diffResult.dispatchUpdatesTo(this);
  66. }
  67. }
  68. @Override
  69. public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  70. LayoutInflater inflater = LayoutInflater.from(parent.getContext());
  71. ItemPreviewOptionBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_preview_option, parent, false);
  72. binding.setOnItemClickListener(mVideoSourceClickListener);
  73. return new ItemViewHolder(binding);
  74. }
  75.  
  76. @Override
  77. public void onBindViewHolder(ItemViewHolder holder, int position) {
  78. VideoSourceBeans videoSourceBeans = mVideoSourceList.get(position);
  79. holder.mBinding.setVideoSource(videoSourceBeans);
  80. holder.mBinding.executePendingBindings();
  81.  
  82. }
  83.  
  84. @Override
  85. public int getItemCount() {
  86. return mVideoSourceList==null?0:mVideoSourceList.size();
  87. }
  88.  
  89. static class ItemViewHolder extends RecyclerView.ViewHolder{
  90.  
  91. private final ItemPreviewOptionBinding mBinding;
  92.  
  93. public ItemViewHolder(ItemPreviewOptionBinding binding) {
  94. super(binding.getRoot());
  95. mBinding = binding;
  96. }
  97.  
  98. }
  99. }
Add Comment
Please, Sign In to add comment