Search in sources :

Example 1 with UTXOCoinSegment

use of com.samourai.wallet.utxos.models.UTXOCoinSegment in project samourai-wallet-android by Samourai-Wallet.

the class UTXOSActivity method applyFilters.

private void applyFilters() {
    // ArrayList will store UTXOs that or filtered based on spending status
    ArrayList<UTXOCoin> filteredStatus = new ArrayList<>();
    for (UTXOCoin model : unFilteredUTXOS) {
        if (statusUnSpendable) {
            if (model.doNotSpend) {
                if (!filteredStatus.contains(model)) {
                    filteredStatus.add(model);
                }
            }
        }
        if (statusSpendable) {
            if (!model.doNotSpend) {
                if (!filteredStatus.contains(model)) {
                    filteredStatus.add(model);
                }
            }
        }
    }
    // ArrayList will store UTXOs that or filtered based on Address types
    // types includes SEGWIT_NATIVE,SEGWIT_COMPAT,LEGACY
    List<UTXOCoin> filteredAddress = new ArrayList<>(filteredStatus);
    // counters to check spendables and unspendables
    // sections will be added based on this counters
    int unspendables = 0;
    int spendables = 0;
    for (UTXOCoin model : filteredStatus) {
        if (model.doNotSpend) {
            unspendables = unspendables + 1;
        } else {
            spendables = spendables + 1;
        }
        UTXOUtil.AddressTypes type = UTXOUtil.getAddressType(model.address);
        switch(type) {
            case LEGACY:
                if (!addressFilterLegacy) {
                    filteredAddress.remove(model);
                }
                break;
            case SEGWIT_COMPAT:
                {
                    if (!addressFilterSegwitCompat) {
                        filteredAddress.remove(model);
                    }
                    break;
                }
            case SEGWIT_NATIVE:
                {
                    if (!addressFilterSegwitNat) {
                        filteredAddress.remove(model);
                    }
                    break;
                }
        }
    }
    if (utxoSortOrder) {
        // Ascending order sorting based on the UTXO amount
        Collections.sort(filteredAddress, (model, t1) -> Long.compare(model.amount, t1.amount));
    } else {
        // Descending  order sorting based on the UTXO amount
        Collections.sort(filteredAddress, (model, t1) -> Long.compare(t1.amount, model.amount));
    }
    // Sectioned dataset for RecyclerView adapter
    // here array will split based on spending status
    List<UTXOCoin> sectioned = new ArrayList<>();
    if (spendables > 0) {
        UTXOCoinSegment active = new UTXOCoinSegment(null, null);
        active.id = 0;
        active.isActive = true;
        sectioned.add(active);
    }
    for (UTXOCoin models : filteredAddress) {
        if (!models.doNotSpend) {
            models.id = filteredAddress.indexOf(models) + 1;
            sectioned.add(models);
        }
    }
    if (unspendables > 0) {
        UTXOCoinSegment doNotSpend = new UTXOCoinSegment(null, null);
        doNotSpend.id = filteredAddress.size() + 1;
        doNotSpend.isActive = false;
        doNotSpend.hash = "not_active";
        sectioned.add(doNotSpend);
    }
    for (UTXOCoin models : filteredAddress) {
        if (models.doNotSpend) {
            models.id = filteredAddress.indexOf(models) + 1;
            sectioned.add(models);
        }
    }
    this.adapter.updateList(sectioned);
}
Also used : UTXOCoinSegment(com.samourai.wallet.utxos.models.UTXOCoinSegment) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint)

Aggregations

MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)1 UTXOCoin (com.samourai.wallet.utxos.models.UTXOCoin)1 UTXOCoinSegment (com.samourai.wallet.utxos.models.UTXOCoinSegment)1 ArrayList (java.util.ArrayList)1