Search in sources :

Example 1 with TransferTransaction

use of run.wallet.iota.model.TransferTransaction in project run-wallet-android by runplay.

the class GetFirstLoadRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    FirstTimeHolder holder = new FirstTimeHolder();
    // StopWatch stopWatch = new StopWatch();
    GetFirstLoadRequest firstLoadRequest = (GetFirstLoadRequest) request;
    Wallet wallet = null;
    List<Address> allAddresses = new ArrayList<>();
    List<Transfer> transfers = new ArrayList<>();
    long started = System.currentTimeMillis();
    if (!firstLoadRequest.getSeed().isappgenerated) {
        holders.put(firstLoadRequest.getSeed().id, holder);
        while (holder.userConfirmedBalance == null || started < System.currentTimeMillis() - 60000) {
            try {
                this.wait(1000);
            } catch (Exception e) {
            }
        }
    } else {
        holder.userConfirmedBalance = false;
        holders.put(firstLoadRequest.getSeed().id, holder);
    }
    boolean userDeclaredBalance = holder.userConfirmedBalance == null ? false : holder.userConfirmedBalance.booleanValue();
    holder.userConfirmedBalance = userDeclaredBalance ? Boolean.TRUE : Boolean.FALSE;
    // Log.e("FL","uc="+holder.userConfirmedBalance+" - ud="+userDeclaredBalance);
    if (!userDeclaredBalance || firstLoadRequest.getSeed().isappgenerated) {
        try {
            final GetNewAddressResponse gna = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, firstLoadRequest.getSeed())), firstLoadRequest.getSecurity(), 0, false, 1, false);
            for (String add : gna.getAddresses()) {
                Address newaddress = new Address(add, false, false);
                newaddress.setIndexName(1);
                allAddresses.add(newaddress);
            }
        } catch (Exception e) {
        }
        wallet = new Wallet(firstLoadRequest.getSeed().id, 0, System.currentTimeMillis());
    } else {
        long timestamp = System.currentTimeMillis();
        holder.showWaitMessage = true;
        holder.predictaddress = 0;
        Map<Integer, Address> already = new HashMap<>();
        int start = 0;
        boolean stop = false;
        List<Bundle> allbundles = new ArrayList<>();
        Map<String, Boolean> hasalready = new HashMap<>();
        wallet = new Wallet(((GetFirstLoadRequest) request).getSeed().id, 0, System.currentTimeMillis());
        List<Transfer> addInTransfers = new ArrayList<>();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final int maxAddresses = Sf.toInt(prefs.getString(Constants.PREF_FIRST_LOAD_ATTEMPTS, "" + Constants.PREF_FIRST_LOAD_ATTEMPTS_DEFAULT));
        final int stopWhenCountEmpty = Sf.toInt(prefs.getString(Constants.PREF_FIRST_LOAD_RANGE, "" + Constants.PREF_FIRST_LOAD_RANGE_DEFAULT));
        while (!stop) {
            Address alreadyAddress = already.get(start);
            Map<String, Boolean> snapshotBalanceAlreadyAddresses = new HashMap();
            boolean foundTransfers = false;
            if (alreadyAddress != null) {
                holder.countaddress++;
                alreadyAddress.setIndex(start);
                alreadyAddress.setIndexName(start + 1);
                allAddresses.add(alreadyAddress);
            } else {
                Address newaddress = null;
                long useBalance = 0L;
                try {
                    GetNewAddressResponse gnr = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, firstLoadRequest.getSeed())), firstLoadRequest.getSecurity(), start, false, 1, false);
                    String add = gnr.getAddresses().get(0);
                    // Log.e("FIRST-TIME", "CALC ADDRESS: " + add + " -- " + start+"-");
                    newaddress = new Address(add, false, false);
                    holder.countaddress++;
                    newaddress.setIndex(start);
                    newaddress.setIndexName(start + 1);
                    allAddresses.add(newaddress);
                    List<String> tmpadd = new ArrayList<>();
                    tmpadd.add(newaddress.getAddress());
                    GetBalancesResponse gbal = apiProxy.getBalances(100, tmpadd);
                    useBalance = Sf.toLong(gbal.getBalances()[0]);
                    newaddress.setValue(useBalance);
                    newaddress.setLastMilestone(gbal.getMilestoneIndex());
                    newaddress.setAttached(true);
                    Bundle[] bundles = apiProxy.bundlesFromAddresses(new String[] { newaddress.getAddress() }, true);
                    if (bundles != null && bundles.length > 0) {
                        newaddress.setAttached(true);
                        foundTransfers = true;
                        for (int i = 0; i < bundles.length; i++) {
                            String hash = bundles[i].getTransactions().get(0).getHash();
                            if (hasalready.get(hash) == null) {
                                hasalready.put(hash, true);
                                allbundles.add(bundles[i]);
                            }
                        }
                    }
                    long oldWallet = wallet.getBalance();
                    long expecting = oldWallet + useBalance;
                    holder.predictaddress = expecting;
                    transfers.clear();
                    Audit.bundlePopulateTransfers(allbundles.toArray(new Bundle[allbundles.size()]), transfers, allAddresses);
                    Audit.setTransfersToAddresses(((GetFirstLoadRequest) request).getSeed(), transfers, allAddresses, wallet, addInTransfers);
                    if (wallet.getBalance() != expecting && useBalance > 0) {
                        if (snapshotBalanceAlreadyAddresses.get(newaddress.getAddress()) == null) {
                            long theBalance = expecting - wallet.getBalance();
                            // Log.e("MK-SNAP","snap::: set-bal: "+theBalance+" - wallet:"+wallet.getBalance()+" - expect:"+expecting+" - add-bal"+useBalance+" - snap-add-tran-value:"+newaddress.getValue()+"  - on-address:"+newaddress.getAddress());
                            Transfer addInTran = new Transfer(timestamp, newaddress.getAddress(), "SNAP" + SeedRandomGenerator.generateNewSeed().substring(0, 23), true, theBalance, "Snapshot balance confirmed", "SNAP999999999999999999");
                            TransferTransaction tt = new TransferTransaction(newaddress.getAddress(), theBalance);
                            List<TransferTransaction> tmptt = new ArrayList<>();
                            tmptt.add(tt);
                            addInTran.setTransactions(tmptt);
                            addInTransfers.add(addInTran);
                            Audit.setTransfersToAddresses(((GetFirstLoadRequest) request).getSeed(), transfers, allAddresses, wallet, addInTransfers);
                        }
                    }
                    snapshotBalanceAlreadyAddresses.put(newaddress.getAddress(), true);
                    holder.counttransfers = transfers.size();
                } catch (Exception e) {
                    Log.e("ERR-FLR020", "address index: " + start + ", ex: " + e.getMessage());
                }
            }
            int lastComplete = 0;
            // boolean hasLastComplete=false;
            for (int i = 0; i < allAddresses.size(); i++) {
                Address tmpadd = allAddresses.get(i);
                if (tmpadd.getValue() != 0) {
                    lastComplete = i;
                }
            }
            // Log.e("WALLET","current value: "+wallet.getBalance()+" - "+wallet.getBalancePendingIn()+" -- "+wallet.getBalancePendingOut());
            int countempty = 0;
            if (!foundTransfers && lastComplete > 0 && allAddresses.size() >= stopWhenCountEmpty) {
                for (int i = allAddresses.size() - 1; i >= 0 && i > lastComplete; i--) {
                    countempty++;
                }
            }
            start++;
            // Log.e("COUNT_EMPTY",allAddresses.size()+" addresses, empty: "+countempty);
            if (countempty >= stopWhenCountEmpty || start > maxAddresses) {
                stop = true;
            }
        }
        for (Transfer tran : transfers) {
            if (!tran.getTransactions().isEmpty()) {
                if (tran.getTimestamp() < timestamp)
                    timestamp = tran.getTimestamp();
            }
        }
        timestamp = timestamp - 600000;
        for (Transfer addIn : addInTransfers) {
            addIn.setTimestamp(--timestamp);
        }
        allAddresses = allAddresses.subList(0, allAddresses.size() - (stopWhenCountEmpty));
        Audit.setTransfersToAddresses(((GetFirstLoadRequest) request).getSeed(), transfers, allAddresses, wallet, addInTransfers);
    }
    boolean hasTransfer = false;
    for (int i = allAddresses.size() - 1; i >= 0; i--) {
        Address address = allAddresses.get(i);
        if (address.getValue() != 0 || address.getPendingValue() != 0) {
            hasTransfer = true;
        } else if (hasTransfer) {
            address.setUsed(true);
        }
    }
    Store.setAccountData(context, ((GetFirstLoadRequest) request).getSeed(), wallet, transfers, allAddresses);
    holder.isFinished = true;
    AppService.auditAddressesWithDelay(context, ((GetFirstLoadRequest) request).getSeed());
    return new GetFirstLoadResponse();
}
Also used : GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) GetBalancesResponse(jota.dto.response.GetBalancesResponse) Address(run.wallet.iota.model.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SharedPreferences(android.content.SharedPreferences) Wallet(run.wallet.iota.model.Wallet) Bundle(jota.model.Bundle) Transfer(run.wallet.iota.model.Transfer) GetFirstLoadResponse(run.wallet.iota.api.responses.GetFirstLoadResponse) TransferTransaction(run.wallet.iota.model.TransferTransaction) GetFirstLoadRequest(run.wallet.iota.api.requests.GetFirstLoadRequest)

Example 2 with TransferTransaction

use of run.wallet.iota.model.TransferTransaction in project run-wallet-android by runplay.

the class Audit method populateTxToTransfers.

public static void populateTxToTransfers(List<Transaction> inTransactions, NodeInfoResponse nodeInfo, List<Transfer> transfers, List<Address> allAddresses) {
    long totalValueTransfer = 0;
    long timestamp = 0;
    String address = "";
    String hash = "";
    Boolean persistence = false;
    long value = 0;
    String tag = Constants.NEW_TRANSFER_TAG;
    String destinationAddress = "";
    List<TransferTransaction> transactions = new ArrayList<>();
    List<TransferTransaction> othertransactions = new ArrayList<>();
    String message = defmessage;
    for (Transaction trx : inTransactions) {
        try {
            tag = trx.getTag();
            address = trx.getAddress();
            persistence = trx.getPersistence();
            value = trx.getValue();
            Address hasAddress = Store.isAlreadyAddress(address, allAddresses);
            if (hasAddress != null) {
                hasAddress.setAttached(true);
            }
            if (value != 0 && hasAddress != null) {
                transactions.add(new TransferTransaction(hasAddress.getAddress(), value));
                totalValueTransfer += value;
            } else if (value != 0) {
                othertransactions.add(new TransferTransaction(trx.getAddress(), value));
            }
            if (trx.getCurrentIndex() == 0) {
                message = Utils.removeTrailingNines(trx.getSignatureFragments());
                timestamp = trx.getAttachmentTimestamp();
                destinationAddress = address;
                hash = trx.getHash();
            }
            if (hasAddress != null) {
                boolean isRemainder = (trx.getCurrentIndex() == trx.getLastIndex()) && trx.getLastIndex() != 0;
                if (value < 0 && !isRemainder) {
                    hasAddress.setUsed(true);
                } else {
                    // hasAddress.setUsed(false);
                    hasAddress.setAttached(true);
                }
            }
        } catch (Exception e) {
            Log.e("AUDIT", "exception: " + e.getMessage());
        }
    }
    Transfer addtransfer = new Transfer(timestamp, destinationAddress, hash, persistence, totalValueTransfer, message, tag);
    if (nodeInfo != null) {
        addtransfer.setMilestone(nodeInfo.getLatestMilestoneIndex());
        addtransfer.setMilestoneCreated(nodeInfo.getLatestMilestoneIndex());
    }
    addtransfer.setTransactions(transactions);
    addtransfer.setOtherTransactions(othertransactions);
    transfers.add(addtransfer);
}
Also used : TransferTransaction(run.wallet.iota.model.TransferTransaction) Transaction(jota.model.Transaction) Address(run.wallet.iota.model.Address) ArrayList(java.util.ArrayList) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) TransferTransaction(run.wallet.iota.model.TransferTransaction)

Example 3 with TransferTransaction

use of run.wallet.iota.model.TransferTransaction in project run-wallet-android by runplay.

the class TransferViewManager method populateViewHolder.

public static final void populateViewHolder(Context context, ViewHolder holder, Transfer transfer, boolean isAutoNudge, int adapterPosition, boolean filtered) {
    if (context != null) {
        String faddress = WalletTransfersCardAdapter.getFilterAddress();
        if (faddress != null && transfer.isCompleted()) {
            ((LinearLayout.LayoutParams) (holder.card).getLayoutParams()).setMarginStart(70);
            long value = 0;
            for (TransferTransaction t : transfer.getTransactions()) {
                if (faddress.equals(t.getAddress()))
                    value += t.getValue();
            }
            if (transfer.getTransactions().isEmpty()) {
            } else {
                IotaToText.IotaDisplayData fdata = IotaToText.getIotaDisplayData(value);
                holder.filtered.setVisibility(View.VISIBLE);
                holder.fBalance.setText((value > 0 ? "+" : "") + fdata.value);
                holder.fUnit.setText(fdata.unit);
                holder.fThird.setText(fdata.thirdDecimal);
                holder.fUnit.setTextColor(B.getColor(context, AppTheme.getPrimary()));
                if (value > 0) {
                    holder.fBalance.setTextColor(B.getColor(context, R.color.green));
                    holder.fThird.setTextColor(B.getColor(context, R.color.green));
                } else {
                    holder.fBalance.setTextColor(B.getColor(context, R.color.flatRed));
                    holder.fThird.setTextColor(B.getColor(context, R.color.flatRed));
                }
            }
        } else {
            holder.filtered.setVisibility(View.GONE);
        }
        IotaToText.IotaDisplayData data = IotaToText.getIotaDisplayData(transfer.getValue());
        holder.transfer = transfer;
        holder.balance.setText(data.value);
        holder.balanceThird.setText(data.thirdDecimal);
        holder.balanceUnit.setText(data.unit);
        holder.addressLabel.setText(transfer.getAddress());
        holder.messageLabel.setText(TextUtils.isEmpty(transfer.getMessage()) ? "" : formatMessage(context, transfer.getMessage()));
        holder.tagLabel.setText(transfer.getTag());
        holder.timeLabel.setText(Utils.timeStampToDate(transfer.getTimestamp()));
        holder.hashLabel.setText(transfer.getHash());
        holder.isCancelled = transfer.isMarkDoubleSpend();
        holder.isAddressDouble = transfer.isMarkDoubleAddress();
        holder.value = transfer.getValue();
        int persist = R.string.card_label_persistence_no;
        if (transfer.isCompleted())
            persist = R.string.card_label_persistence_yes;
        holder.persistenceLabel.setText(context.getString(persist));
        holder.isConfirmed = transfer.getPersistence() != null ? transfer.getPersistence() : false;
        holder.confirmCheck.setVisibility(View.GONE);
        holder.alternativeValueLabel.setText("");
        holder.timestatus.setVisibility(View.VISIBLE);
        holder.balance.setTextColor(B.getColor(context, R.color.grey));
        holder.balanceThird.setTextColor(B.getColor(context, R.color.grey));
        holder.balanceUnit.setTextColor(B.getColor(context, R.color.grey));
        holder.alternativeValueLabel.setTextColor(B.getColor(context, R.color.grey));
        holder.balance.setPaintFlags(0);
        if (transfer.getPersistence() != null && transfer.getPersistence().booleanValue()) {
            // holder.card.setCardBackgroundColor(B.getColor(context,R.color.cardview_light_background));
            holder.card.setAlpha(1F);
        } else {
            if ((System.currentTimeMillis() - 600000) > transfer.getTimestamp()) {
                holder.card.setAlpha(0.6F);
            } else {
                holder.card.setAlpha(0.8F);
            }
        // holder.card.setCardBackgroundColor(B.getColor(context,R.color.cardview_dark_background));
        }
        holder.mstoneCount.setVisibility(View.GONE);
        holder.getAlternativeValueTime.setText(Cal.friendlyReadDate(new Cal(transfer.getTimestamp())));
        holder.getAlternativeValueTime.setCompoundDrawables(null, null, null, null);
        if (transfer.getValue() == 0 && transfer.getTransactions().isEmpty()) {
            if (transfer.getTag().endsWith("NUDGE9")) {
                holder.alternativeValueLabel.setText(context.getString(R.string.info_nudge));
                holder.imgTran.setImageResource(R.drawable.nudge_orange);
            } else {
                holder.alternativeValueLabel.setText(context.getString(R.string.attached_address));
                holder.imgTran.setImageResource(R.drawable.tran_orange);
            }
        } else if (!transfer.isCompleted()) {
            if (isAutoNudge) {
                holder.imgTran.setImageResource(R.drawable.ic_replay_orange);
            } else {
                holder.imgTran.setImageResource(R.drawable.ic_replay_grey);
            }
            if (transfer.getValue() < 0) {
                holder.balance.setTextColor(B.getColor(context, R.color.flatRed));
                holder.balanceThird.setTextColor(B.getColor(context, R.color.flatRed));
                holder.balanceUnit.setTextColor(B.getColor(context, AppTheme.getPrimary()));
            } else if (transfer.isInternal()) {
                holder.alternativeValueLabel.setText(context.getString(R.string.card_label_internal));
                holder.imgTran.setImageResource(R.drawable.tran_green);
            }
            holder.confirmCheck.setText(transfer.getNudgeCount() + "");
            if (transfer.isMarkDoubleSpend()) {
                holder.imgTran.setImageResource(R.drawable.ic_replay_grey);
                holder.alternativeValueLabel.setText(context.getString(R.string.label_cancelled));
                holder.balance.setPaintFlags(holder.addressLabel.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            } else if (transfer.isMarkDoubleAddress()) {
                holder.imgTran.setImageResource(R.drawable.ic_replay_grey);
                holder.alternativeValueLabel.setText(context.getString(R.string.label_address_used));
                holder.balance.setPaintFlags(holder.addressLabel.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            } else {
                if (transfer.getValue() < 0) {
                    if (isAutoNudge || transfer.getNudgeCount() > 0) {
                        holder.confirmCheck.setVisibility(View.VISIBLE);
                        holder.confirmCheck.setBackgroundResource(R.drawable.ic_replay_orange_alpha);
                    }
                    holder.alternativeValueLabel.setText(context.getString(R.string.card_label_pending_out));
                } else {
                    if (isAutoNudge || transfer.getNudgeCount() > 0) {
                        holder.confirmCheck.setVisibility(View.VISIBLE);
                        holder.confirmCheck.setBackgroundResource(R.drawable.ic_replay_orange_alpha);
                    }
                    holder.alternativeValueLabel.setText(context.getString(R.string.card_label_pending_in));
                }
            }
        } else if (transfer.getValue() == 0) {
            holder.alternativeValueLabel.setText(context.getString(R.string.card_label_internal));
            holder.imgTran.setImageResource(R.drawable.tran_green);
            if (transfer.isCompleted()) {
                holder.confirmCheck.setBackgroundResource(R.drawable.check_green);
                holder.confirmCheck.setVisibility(View.VISIBLE);
            }
        } else if (transfer.getValue() > 0) {
            holder.confirmCheck.setVisibility(View.VISIBLE);
            holder.confirmCheck.setText("");
            holder.confirmCheck.setBackgroundResource(R.drawable.check_green);
            holder.alternativeValueLabel.setText(context.getString(R.string.card_label_persistence_yes));
            holder.getAlternativeValueTime.setCompoundDrawables(B.getDrawable(context, R.drawable.check_green), null, null, null);
            holder.imgTran.setImageResource(R.drawable.ic_iota_in);
            holder.balance.setTextColor(B.getColor(context, R.color.green));
            holder.balanceThird.setTextColor(B.getColor(context, R.color.green));
            holder.balanceUnit.setTextColor(B.getColor(context, AppTheme.getPrimary()));
        } else {
            holder.confirmCheck.setVisibility(View.VISIBLE);
            holder.confirmCheck.setText("");
            holder.confirmCheck.setBackgroundResource(R.drawable.check_green);
            holder.alternativeValueLabel.setText(context.getString(R.string.card_label_persistence_yes));
            holder.getAlternativeValueTime.setCompoundDrawables(B.getDrawable(context, R.drawable.check), null, null, null);
            holder.imgTran.setImageResource(R.drawable.ic_iota_out);
            holder.balance.setTextColor(B.getColor(context, R.color.flatRed));
            holder.balanceThird.setTextColor(B.getColor(context, R.color.flatRed));
            holder.balanceUnit.setTextColor(B.getColor(context, AppTheme.getPrimary()));
        }
        TransferViewManager.populateTransferTransactions(context, holder.transferTransactions, transfer.getTransactions(), false);
        if (!transfer.getOtherTransactions().isEmpty()) {
            holder.otherAddressView.setVisibility(View.VISIBLE);
            holder.otherAddressLayout.setVisibility(View.VISIBLE);
            TransferViewManager.populateTransferTransactions(context, holder.otherAddressLayout, transfer.getOtherTransactions(), true);
        } else {
            // holder.otherAddressLayout.removeAllViews();
            holder.otherAddressView.setVisibility(View.GONE);
        }
        if (adapterPosition < 0) {
        } else {
            holder.expandableLayout.setExpanded(expandState.get(adapterPosition));
            holder.expandableLayout.invalidate();
        }
    }
}
Also used : IotaToText(jota.utils.IotaToText) TransferTransaction(run.wallet.iota.model.TransferTransaction) Paint(android.graphics.Paint) Cal(run.wallet.common.Cal)

Example 4 with TransferTransaction

use of run.wallet.iota.model.TransferTransaction in project run-wallet-android by runplay.

the class PendingCancelledFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (Store.getCacheTransfer() == null) {
        getActivity().onBackPressed();
    } else {
        View v = view.findViewById(R.id.transfer_card);
        TransferViewManager.populateViewHolder(getActivity(), new TransferViewManager.ViewHolder(getActivity(), v), Store.getCacheTransfer(), false, -1, false);
        List<TransferTransaction> transactions = new ArrayList<>();
        transactions.addAll(Store.getCacheTransfer().getTransactions());
        transactions.addAll(Store.getCacheTransfer().getOtherTransactions());
        TransferViewManager.populateTransferTransactionOuts(getActivity(), breakdown, transactions, Store.getCacheTransfer());
        cancelledHash.setText(Store.getCacheTransfer().getHash());
        cancelledHash.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ActivityMan.openAndroidBrowserUrl(getActivity(), sitesHash[0] + Store.getCacheTransfer().getHash());
            }
        });
        copyClip.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Transfer transfer = Store.getCacheTransfer();
                if (transfer != null) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    StringBuilder sb = new StringBuilder();
                    sb.append("IOTA Transfer\n\n");
                    sb.append("time: " + Cal.getCal(transfer.getTimestamp()).getDatabaseDate());
                    sb.append("\nhash: " + transfer.getHash());
                    sb.append("\n\nTotal: " + transfer.getValue());
                    sb.append("\nStatus: " + (transfer.isCompleted() ? "Completed" : "Pending"));
                    sb.append("\nmilestone: " + transfer.getMilestone());
                    sb.append("\n\nAddress actions\n");
                    for (TransferTransaction tran : transfer.getTransactions()) {
                        sb.append(tran.getValue());
                        sb.append("    ");
                        sb.append(tran.getAddress());
                    }
                    for (TransferTransaction tran : transfer.getOtherTransactions()) {
                        sb.append(tran.getValue());
                        sb.append("    ");
                        sb.append(tran.getAddress());
                    }
                    sb.append("\n\nUsing run IOTA wallet, Android app http://iota.runplay.com");
                    ClipData clip = ClipData.newPlainText(getActivity().getString(R.string.seed), sb.toString());
                    clipboard.setPrimaryClip(clip);
                    Snackbar.make(getView(), getString(R.string.text_cancelled_copied), Snackbar.LENGTH_SHORT).show();
                }
            }
        });
        cancelledSites.setText(" " + sitesName[0]);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ArrayList(java.util.ArrayList) Transfer(run.wallet.iota.model.Transfer) TransferViewManager(run.wallet.iota.ui.TransferViewManager) TransferTransaction(run.wallet.iota.model.TransferTransaction) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ClipData(android.content.ClipData)

Example 5 with TransferTransaction

use of run.wallet.iota.model.TransferTransaction in project run-wallet-android by runplay.

the class TransferViewManager method populateTransferTransactionOuts.

public static void populateTransferTransactionOuts(Activity context, LinearLayout uselayout, List<TransferTransaction> transactions, Transfer transfer) {
    uselayout.removeAllViews();
    int bgcolor = B.getColor(context, AppTheme.getPrimary());
    int bglight = B.getColor(context, R.color.colorLight);
    int white = B.getColor(context, R.color.white);
    int red = B.getColor(context, R.color.flatRed);
    int green = B.getColor(context, R.color.green);
    List<Address> allAddresses = Store.getAddresses();
    main.weight = 1;
    param.setMargins(8, 4, 8, 4);
    param2.setMargins(8, 4, 8, 4);
    param3.setMargins(0, 4, 8, 4);
    for (TransferTransaction trans : transactions) {
        Address address = Store.isAlreadyAddress(trans.getAddress(), allAddresses);
        // if (address != null) {
        LinearLayout layout = new LinearLayout(context);
        layout.setBackgroundColor(bglight);
        layout.setOrientation(LinearLayout.HORIZONTAL);
        layout.setLayoutParams(mainouts);
        layout.setPadding(2, 6, 2, 6);
        layout.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
        TextView balance = new TextView(context);
        balance.setLayoutParams(param5);
        balance.setText(IotaToText.convertRawIotaAmountToDisplayText(trans.getPayFromAddressZero(), true));
        balance.setPadding(2, 2, 2, 2);
        if (address == null) {
            if (trans.getPayFromAddressZero() == 0 && trans.getValue() < 0) {
                balance.setBackgroundColor(red);
                balance.setTextColor(white);
            } else {
                balance.setTextColor(white);
            }
        } else {
            if (trans.getValue() < 0 && trans.getPayFromAddressZero() == 0) {
                balance.setBackgroundColor(red);
                balance.setTextColor(white);
            }
            if (trans.getPayFromAddressZero() > 0)
                balance.setTextColor(green);
            else
                balance.setTextColor(white);
        }
        TextView addId = new TextView(context);
        addId.setLayoutParams(param4);
        if (address != null) {
            addId.setBackgroundColor(bgcolor);
            addId.setText("a" + address.getIndexName());
        } else {
            addId.setText(" ");
        }
        addId.setPadding(2, 2, 2, 2);
        addId.setTextColor(white);
        // addId.setMa
        TextView addValue = new TextView(context);
        addValue.setLayoutParams(param3);
        addValue.setText(IotaToText.convertRawIotaAmountToDisplayText(trans.getValue(), true));
        addValue.setTextSize(20F);
        addValue.setGravity(Gravity.RIGHT);
        addValue.setTypeface(null, Typeface.BOLD);
        if (trans.getValue() < 0) {
            addValue.setTextColor(red);
        } else {
            addValue.setTextColor(green);
        }
        addValue.setPadding(5, 2, 2, 2);
        addValue.setSingleLine();
        TextView addAddress = new TextView(context);
        addAddress.setLayoutParams(param2);
        addAddress.setText(trans.getAddress());
        addAddress.setTextColor(bgcolor);
        addAddress.setTextSize(12F);
        addAddress.setPadding(5, 2, 2, 2);
        addAddress.setSingleLine();
        addAddress.setOnClickListener(new OpenClick(context, trans.getAddress()));
        layout.addView(balance);
        layout.addView(addId);
        layout.addView(addValue);
        layout.addView(addAddress);
        uselayout.addView(layout);
    // } else {
    // Log.e("NULL-ADD","Null adrress: "+trans.getAddress()+" - "+transfer.getValue()+" - hash: "+transfer.getHash());
    // }
    // uselayout.notify();
    }
}
Also used : Address(run.wallet.iota.model.Address) TextView(android.widget.TextView) TransferTransaction(run.wallet.iota.model.TransferTransaction) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Aggregations

TransferTransaction (run.wallet.iota.model.TransferTransaction)8 ArrayList (java.util.ArrayList)5 Address (run.wallet.iota.model.Address)5 Transfer (run.wallet.iota.model.Transfer)5 Paint (android.graphics.Paint)4 TextView (android.widget.TextView)3 SharedPreferences (android.content.SharedPreferences)2 LinearLayout (android.widget.LinearLayout)2 HashMap (java.util.HashMap)2 NudgeTransfer (run.wallet.iota.model.NudgeTransfer)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 CardView (android.support.v7.widget.CardView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 BindView (butterknife.BindView)1 GetBalancesResponse (jota.dto.response.GetBalancesResponse)1 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)1 Bundle (jota.model.Bundle)1 Transaction (jota.model.Transaction)1