| package com.doumee.lib_coremodel.base; | 
|   | 
| import android.content.Context; | 
|   | 
| import androidx.recyclerview.widget.RecyclerView; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
| public abstract class RcvBaseAdapter<D extends Object,T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> { | 
|     public interface DeletItemListener{ | 
|         void delet(int position); | 
|     } | 
|   | 
|     public interface ItemLongClickListener{ | 
|         void onLongClick(int position); | 
|     } | 
|   | 
|     public interface ItemClickListener{ | 
|         void onClick(int position); | 
|     } | 
|   | 
|     protected ItemClickListener clickListener; | 
|     protected Context context; | 
|     protected List<D> datas=new ArrayList<>(); | 
|   | 
|     public RcvBaseAdapter(Context context) { | 
|         this.context = context; | 
|     } | 
|   | 
|     public ItemClickListener getClickListener() { | 
|         return clickListener; | 
|     } | 
|   | 
|     public void setClickListener(ItemClickListener clickListener) { | 
|         this.clickListener = clickListener; | 
|     } | 
|   | 
|     public void addData(List<D> data1) { | 
|         try { | 
|             if (data1 != null) { | 
|                 int s=datas.size(); | 
|                 datas.addAll(data1); | 
|                 if(s==0){ | 
|                     notifyDataSetChanged(); | 
|                 }else { | 
|                     notifyItemRangeInserted(s,data1.size()); | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|   | 
|         } | 
|   | 
|     } | 
|   | 
|     public void refrenshData(List<D> data1) { | 
|         if (data1 != null ) { | 
|             datas.clear(); | 
|             addData(data1); | 
|         } | 
|     } | 
|   | 
|     public void removeDataByPosition(int position) { | 
|         if (position >= 0 && position < datas.size()) { | 
|             datas.remove(position); | 
|             notifyItemRemoved(position); | 
|         } | 
|     } | 
|   | 
|     public D getDataByPosition(int position) { | 
|         if (position >= 0 && position < datas.size()) { | 
|             return datas.get(position); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     public void clearData(){ | 
|         datas.clear(); | 
|         notifyDataSetChanged(); | 
|         //Phoenix.clearCaches(); | 
|     } | 
|   | 
|     public List<D> getDatas() { | 
|         return datas; | 
|     } | 
|   | 
|     @Override | 
|     public int getItemCount() { | 
|         return datas.size(); | 
|     } | 
|   | 
|   | 
| } |