content: package com.example.admin.mybledemo.adapter;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import androidx.recyclerview.widget.RecyclerView;
  
  import java.util.List;
  
  public abstract class RecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerViewHolder> {
      protected Context mContext;
      protected int mLayoutId;
      protected List<T> mDatas;
      protected LayoutInflater mInflater;
  
      private OnItemClickListener<T> mOnItemClickListener;
      private OnItemLongClickListener<T> mOnItemLongClickListener;
  
      public void setOnItemClickListener(OnItemClickListener<T> onItemClickListener) {
          this.mOnItemClickListener = onItemClickListener;
      }
  
      public void setOnItemLongClickListener(OnItemLongClickListener<T> onItemLongClickListener) {
          this.mOnItemLongClickListener = onItemLongClickListener;
      }
  
      public RecyclerAdapter(Context context, int layoutId, List<T> datas) {
          mContext = context;
          mInflater = LayoutInflater.from(context);
          mLayoutId = layoutId;
          mDatas = datas;
      }
  
      @Override
      public RecyclerViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
          RecyclerViewHolder viewHolder = RecyclerViewHolder.get(mContext, null, parent, mLayoutId, -1);
          setListener(parent, viewHolder, viewType);
          return viewHolder;
      }
  
      protected int getPosition(RecyclerViewHolder viewHolder) {
          return viewHolder.getAdapterPosition();
      }
  
      protected boolean isEnabled(int viewType) {
          return true;
      }
  
  
      protected void setListener(final ViewGroup parent, final RecyclerViewHolder viewHolder, int viewType) {
          if (!isEnabled(viewType)) return;
          viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (mOnItemClickListener != null) {
                      int position = getPosition(viewHolder);
                      mOnItemClickListener.onItemClick(parent, v, mDatas.get(position), position);
                  }
              }
          });
  
  
          viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  if (mOnItemLongClickListener != null) {
                      int position = getPosition(viewHolder);
                      return mOnItemLongClickListener.onItemLongClick(parent, v, mDatas.get(position), position);
                  }
                  return false;
              }
          });
      }
  
      @Override
      public void onBindViewHolder(RecyclerViewHolder holder, int position) {
          holder.updatePosition(position);
          convert(holder, mDatas.get(position));
      }
  
      public abstract void convert(RecyclerViewHolder holder, T t);
  
      @Override
      public int getItemCount() {
          return mDatas.size() != 0 ? mDatas.size() : 0;
      }
  
  
      public interface OnItemClickListener<T> {
          void onItemClick(ViewGroup parent, View view, T t, int position);
      }
  
      public interface OnItemLongClickListener<T> {
          boolean onItemLongClick(ViewGroup parent, View view, T t, int position);
      }
  
  
  
  }