Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package net.kaunghtetlin.yabpay.adapters;
  2.  
  3. import android.content.Context;
  4. import android.support.v7.widget.RecyclerView;
  5. import android.view.LayoutInflater;
  6.  
  7. import net.kaunghtetlin.yabpay.viewholders.BaseViewHolder;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public abstract class BaseRecyclerAdapter<T extends BaseViewHolder, W>
  13. extends RecyclerView.Adapter<T> {
  14.  
  15. protected List<W> mData;
  16. protected LayoutInflater mLayoutInflator;
  17.  
  18. public BaseRecyclerAdapter(Context context) {
  19. mData = new ArrayList<>();
  20. mLayoutInflator = LayoutInflater.from(context);
  21. }
  22.  
  23. @Override
  24. public void onBindViewHolder(T holder, int position) {
  25. holder.setData(mData.get(position));
  26. }
  27.  
  28. @Override
  29. public int getItemCount() {
  30. return mData.size();
  31. }
  32.  
  33. public void setNewData(List<W> newData) {
  34. mData = newData;
  35. notifyDataSetChanged();
  36. }
  37.  
  38. public void appendNewData(List<W> newData) {
  39. mData.addAll(newData);
  40. notifyDataSetChanged();
  41. }
  42.  
  43. public W getItemAt(int position) {
  44. if (position < mData.size() - 1) return mData.get(position);
  45.  
  46. return null;
  47. }
  48.  
  49. public List<W> getItems() {
  50. if (mData == null) return new ArrayList<>();
  51.  
  52. return mData;
  53. }
  54.  
  55. public void removeData(W data) {
  56. mData.remove(data);
  57. notifyDataSetChanged();
  58. }
  59.  
  60. public void addNewData(W data) {
  61. mData.add(data);
  62. notifyDataSetChanged();
  63. }
  64.  
  65. public void clearData() {
  66. mData = new ArrayList<>();
  67. notifyDataSetChanged();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement