package com.samourai.wallet.home.adapters;

import android.support.v7.util.DiffUtil;

import com.samourai.wallet.api.Tx;

import java.util.List;

public class TxDiffUtil extends DiffUtil.Callback {

    private List<Tx> oldTxes;
    private List<Tx> newTxes;


    TxDiffUtil(List<Tx> txes, List<Tx> txs) {
        this.newTxes = txes;
        this.oldTxes = txs;
    }

    @Override
    public int getOldListSize() {
        return oldTxes.size();
    }

    @Override
    public int getNewListSize() {
        return newTxes.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return oldTxes.get(oldItemPosition).getTS() == newTxes.get(newItemPosition).getTS();
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        Tx oldItem = oldTxes.get(oldItemPosition);
        Tx newItem = oldTxes.get(newItemPosition);
        if (oldItem.section != null || newItem.section != null) {
            return true;
        }
        boolean reRender = false;
        if (oldItem.getConfirmations() != newItem.getConfirmations()) {
            reRender = true;
        }
        if (!oldItem.getHash().equals(newItem.getHash())) {
            reRender = true;
        }
        return reRender;
    }
}

@@ -836,16 +836,71 @@
      Tx 
+oldItem;%0A        Tx newItem;%0A        try %7B%0A            
 oldItem 
@@ -931,34 +931,35 @@
 ition);%0A        
-Tx
+   
  newItem = oldTx
@@ -975,32 +975,140 @@
 wItemPosition);%0A
+        %7D catch(Exception e) %7B%0A            // IndexOutOfBoundsException%0A            return false;%0A        %7D%0A
         if (oldI

fix IndexOutOfBoundsException