Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package is.uncommon.playbook.sortedlist.part1;
  2.  
  3. import android.support.v7.util.SortedList;
  4. import android.view.ViewGroup;
  5.  
  6. public class SortedListAdapter extends IntegerListAdapter {
  7. private SortedList<Integer> sortedList =
  8. new SortedList<>(Integer.class, new SortedList.Callback<Integer>() {
  9. @Override public int compare(Integer item1, Integer item2) {
  10. return item1.compareTo(item2);
  11. }
  12.  
  13. @Override public void onChanged(int position, int count) {
  14. SortedListAdapter.this.notifyItemRangeChanged(position, count);
  15. }
  16.  
  17. @Override public boolean areContentsTheSame(Integer oldItem, Integer newItem) {
  18. return oldItem.equals(newItem);
  19. }
  20.  
  21. @Override public boolean areItemsTheSame(Integer item1, Integer item2) {
  22. return item1.intValue() == item2.intValue();
  23. }
  24.  
  25. @Override public void onInserted(int position, int count) {
  26. SortedListAdapter.this.notifyItemRangeInserted(position, count);
  27. }
  28.  
  29. @Override public void onRemoved(int position, int count) {
  30. SortedListAdapter.this.notifyItemRangeRemoved(position, count);
  31. }
  32.  
  33. @Override public void onMoved(int fromPosition, int toPosition) {
  34. SortedListAdapter.this.notifyItemMoved(fromPosition, toPosition);
  35. }
  36. });
  37.  
  38. @Override protected void addInteger(Integer integer) {
  39. sortedList.add(integer);
  40. }
  41.  
  42. @Override protected void removeInteger(Integer integer) {
  43. sortedList.remove(integer);
  44. }
  45.  
  46. @Override public IntegerListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  47. return IntegerListItemViewHolder.create(parent);
  48. }
  49.  
  50. @Override public void onBindViewHolder(IntegerListItemViewHolder holder, int position) {
  51. holder.bindTo(sortedList.get(position));
  52. }
  53.  
  54. @Override public int getItemCount() {
  55. return sortedList.size();
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement