Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override public int getItemViewType(int position) {
- int index = 0;
- if (0 == position) { // 0
- return ITEM_TYPE_HEADER;
- }
- for (int i = 0; i < data.size(); i++) {
- if (i > 0) {
- index++;
- if (index == position) {
- return ITEM_TYPE_HEADER;
- }
- }
- for (int j = 0; j < data.get(i).getTransactions().size(); j++) {
- index++; // 1, 2 // 5, 6,
- if (index == position) {
- return ITEM_TYPE_TRN;
- }
- }
- index++; // 3 // 7
- if (index == position) {
- return ITEM_TYPE_FOOTER;
- }
- }
- return super.getItemViewType(position);
- }
- @SuppressWarnings("ConstantConditions") @Override
- public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
- int index = 0;
- if (0 == position) { // 0
- ((HeaderViewHolder) holder).bind(data.get(0));
- }
- for (int i = 0; i < data.size(); i++) {
- if (i > 0) {
- index++;
- if (index == position) {
- ((HeaderViewHolder) holder).bind(data.get(i));
- break;
- }
- }
- for (int j = 0; j < data.get(i).getTransactions().size(); j++) {
- index++; // 1, 2 // 5, 6,
- if (index == position) {
- ((TransactionViewHolder) holder).bind(data.get(i).getTransactions().get(j), context,
- currency, isInstallments);
- break;
- }
- }
- index++; // 3 // 7
- if (index == position) {
- ((FooterViewHolder) holder).bind(data.get(i), currency, context);
- break;
- }
- }
- }
- @Override public int getItemCount() {
- int itemCount = data.size() * 2; // headers + footers
- for (CCTransactionGroup group : data) {
- itemCount += group.getTransactions().size(); // items
- }
- return itemCount;
- }
Add Comment
Please, Sign In to add comment