Guest User

Untitled

a guest
May 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. @Override public int getItemViewType(int position) {
  2. int index = 0;
  3.  
  4. if (0 == position) { // 0
  5. return ITEM_TYPE_HEADER;
  6. }
  7.  
  8. for (int i = 0; i < data.size(); i++) {
  9.  
  10. if (i > 0) {
  11. index++;
  12. if (index == position) {
  13. return ITEM_TYPE_HEADER;
  14. }
  15. }
  16.  
  17. for (int j = 0; j < data.get(i).getTransactions().size(); j++) {
  18. index++; // 1, 2 // 5, 6,
  19. if (index == position) {
  20. return ITEM_TYPE_TRN;
  21. }
  22. }
  23.  
  24. index++; // 3 // 7
  25. if (index == position) {
  26. return ITEM_TYPE_FOOTER;
  27. }
  28. }
  29.  
  30. return super.getItemViewType(position);
  31. }
  32.  
  33. @SuppressWarnings("ConstantConditions") @Override
  34. public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  35. int index = 0;
  36.  
  37. if (0 == position) { // 0
  38. ((HeaderViewHolder) holder).bind(data.get(0));
  39. }
  40.  
  41. for (int i = 0; i < data.size(); i++) {
  42.  
  43. if (i > 0) {
  44. index++;
  45. if (index == position) {
  46. ((HeaderViewHolder) holder).bind(data.get(i));
  47. break;
  48. }
  49. }
  50.  
  51. for (int j = 0; j < data.get(i).getTransactions().size(); j++) {
  52. index++; // 1, 2 // 5, 6,
  53. if (index == position) {
  54. ((TransactionViewHolder) holder).bind(data.get(i).getTransactions().get(j), context,
  55. currency, isInstallments);
  56. break;
  57. }
  58. }
  59.  
  60. index++; // 3 // 7
  61. if (index == position) {
  62. ((FooterViewHolder) holder).bind(data.get(i), currency, context);
  63. break;
  64. }
  65. }
  66. }
  67.  
  68. @Override public int getItemCount() {
  69. int itemCount = data.size() * 2; // headers + footers
  70. for (CCTransactionGroup group : data) {
  71. itemCount += group.getTransactions().size(); // items
  72. }
  73. return itemCount;
  74. }
Add Comment
Please, Sign In to add comment