Search in sources :

Example 1 with PoolViewModel

use of com.samourai.wallet.whirlpool.models.PoolViewModel in project samourai-wallet-android by Samourai-Wallet.

the class PoolsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final PoolViewModel poolViewModel = pools.get(position);
    holder.poolAmount.setText(getBTCDecimalFormat(poolViewModel.getDenomination(), 2).concat(" BTC Pool"));
    holder.poolFees.setText(mContext.getString(R.string.pool_fee).concat("    ").concat(getBTCDecimalFormat(poolViewModel.getFeeValue())).concat(" BTC"));
    holder.totalFees.setText(mContext.getString(R.string.total_fees).concat("  ").concat(getBTCDecimalFormat(poolViewModel.getTotalFee())).concat(" BTC").concat(" (").concat(String.valueOf(poolViewModel.getTotalEstimatedBytes())).concat(" bytes)"));
    holder.minorFees.setText(mContext.getString(R.string.miner_fee).concat("  ").concat(getBTCDecimalFormat(poolViewModel.getMinerFee())).concat(" BTC"));
    holder.checkBox.setOnCheckedChangeListener(null);
    holder.checkBox.setChecked(poolViewModel.isSelected());
    if (poolViewModel.isSelected()) {
        holder.feesGroup.setVisibility(View.VISIBLE);
    }
    if (!poolViewModel.isDisabled())
        holder.itemView.setOnClickListener(view -> {
            holder.feesGroup.setVisibility(holder.feesGroup.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
        });
    if (!poolViewModel.isDisabled())
        holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> {
            onItemsSelected.onItemsSelected(position);
        });
    if (poolViewModel.isDisabled()) {
        holder.layout.setAlpha(0.4f);
        holder.layout.setClickable(false);
    } else {
        holder.layout.setAlpha(1f);
        holder.layout.setClickable(true);
    }
    holder.checkBox.setEnabled(!poolViewModel.isDisabled());
}
Also used : Context(android.content.Context) PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel) LayoutInflater(android.view.LayoutInflater) DecimalFormat(java.text.DecimalFormat) FormatsUtil.getBTCDecimalFormat(com.samourai.wallet.util.FormatsUtil.getBTCDecimalFormat) R(com.samourai.wallet.R) Group(android.support.constraint.Group) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) View(android.view.View) LogUtil(com.samourai.wallet.util.LogUtil) PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel)

Example 2 with PoolViewModel

use of com.samourai.wallet.whirlpool.models.PoolViewModel in project samourai-wallet-android by Samourai-Wallet.

the class SelectPoolFragment method loadPools.

private void loadPools() {
    poolViewModels.clear();
    this.tx0Amount = NewPoolActivity.getCycleTotalAmount(coins);
    Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
    if (!whirlpoolWalletOpt.isPresent()) {
        return;
    }
    if (poolsAdapter == null) {
        poolsAdapter = new PoolsAdapter(getContext(), poolViewModels);
    }
    WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
    Disposable disposable = Single.fromCallable(whirlpoolWallet::getPools).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((whirlpoolPools) -> {
        for (com.samourai.whirlpool.client.whirlpool.beans.Pool whirlpoolPool : whirlpoolPools) {
            PoolViewModel poolViewModel = new PoolViewModel(whirlpoolPool);
            Long fee = fees.get(1);
            ;
            switch(this.poolCyclePriority) {
                case HIGH:
                    fee = fees.get(2);
                    break;
                case NORMAL:
                    fee = fees.get(1);
                    break;
                case LOW:
                    {
                        fee = fees.get(0);
                        break;
                    }
            }
            poolViewModel.setMinerFee(fee, this.coins);
            poolViewModels.add(poolViewModel);
            if (poolViewModel.getDenomination() + poolViewModel.getFeeValue() + poolViewModel.getMinerFee() > this.tx0Amount) {
                poolViewModel.setDisabled(true);
            } else {
                poolViewModel.setDisabled(false);
            }
        }
        poolsAdapter.notifyDataSetChanged();
    }, Throwable::printStackTrace);
    compositeDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) PoolsAdapter(com.samourai.wallet.whirlpool.adapters.PoolsAdapter)

Example 3 with PoolViewModel

use of com.samourai.wallet.whirlpool.models.PoolViewModel in project samourai-wallet-android by Samourai-Wallet.

the class PoolsAdapter method selectItem.

private void selectItem(ViewHolder holder, int position) {
    PoolViewModel poolViewModel = pools.get(position);
    pools.get(position).setSelected(!poolViewModel.isSelected());
    holder.checkBox.setChecked(poolViewModel.isSelected());
}
Also used : PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel)

Example 4 with PoolViewModel

use of com.samourai.wallet.whirlpool.models.PoolViewModel in project samourai-wallet-android by Samourai-Wallet.

the class NewPoolActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_whirlpool_cycle);
    Toolbar toolbar = findViewById(R.id.toolbar_new_whirlpool);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    cycleTotalAmount = findViewById(R.id.cycle_total_amount);
    cycleTotalAmount.setText(MonetaryUtil.getInstance().getBTCFormat().format(((double) getCycleTotalAmount(new ArrayList<UTXOCoin>())) / 1e8) + " BTC");
    fees.add(FeeUtil.getInstance().getLowFee().getDefaultPerKB().longValue() / 1000L);
    fees.add(FeeUtil.getInstance().getNormalFee().getDefaultPerKB().longValue() / 1000L);
    fees.add(FeeUtil.getInstance().getHighFee().getDefaultPerKB().longValue() / 1000L);
    String preselectId = null;
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("preselected")) {
        preselectId = getIntent().getExtras().getString("preselected");
    }
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        account = getIntent().getExtras().getInt("_account");
    }
    chooseUTXOsFragment = ChooseUTXOsFragment.newInstance(preselectId);
    selectPoolFragment = new SelectPoolFragment();
    reviewPoolFragment = new ReviewPoolFragment();
    selectPoolFragment.setFees(this.fees);
    tx0Progress = findViewById(R.id.new_pool_tx0_progress);
    newPoolViewPager = findViewById(R.id.new_pool_viewpager);
    setUpStepper();
    newPoolViewPager.setAdapter(new NewPoolStepsPager(getSupportFragmentManager()));
    newPoolViewPager.enableSwipe(false);
    confirmButton = findViewById(R.id.utxo_selection_confirm_btn);
    confirmButton.setVisibility(View.VISIBLE);
    enableConfirmButton(false);
    // Disable selection from fragment since post mix utxo's are populated by the activity
    if (account != WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix())
        chooseUTXOsFragment.setOnUTXOSelectionListener(this::onUTXOSelected);
    selectPoolFragment.setOnPoolSelectionComplete((poolViewModel, priority) -> {
        selectedPoolViewModel = poolViewModel;
        selectedPoolPriority = priority;
        if (tx0 != null && poolViewModel != null) {
            tx0.setPool(poolViewModel.getDenomination());
        }
        enableConfirmButton(selectedPoolViewModel != null);
    });
    confirmButton.setOnClickListener(view -> {
        switch(newPoolViewPager.getCurrentItem()) {
            case 0:
                {
                    newPoolViewPager.setCurrentItem(1);
                    initUTXOReviewButton(selectedCoins);
                    enableConfirmButton(selectedPoolViewModel != null);
                    break;
                }
            case 1:
                {
                    try {
                        tx0.make();
                    } catch (Exception ex) {
                        Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
                        return;
                    }
                    calculateTx0(selectedPoolViewModel.getDenomination(), selectedPoolViewModel.getMinerFee() / 1000L);
                    newPoolViewPager.setCurrentItem(2);
                    confirmButton.setText(getString(R.string.begin_cycle));
                    confirmButton.setBackgroundResource(R.drawable.button_green);
                    reviewPoolFragment.setTx0(tx0);
                    break;
                }
            case 2:
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage(R.string.block_tx0_change).setCancelable(false);
                    AlertDialog alert = builder.create();
                    alert.setTitle(R.string.doxxic_change_warning);
                    alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), (dialog, id) -> {
                        dialog.dismiss();
                        blockChangeOutput = true;
                        processWhirlPool();
                    });
                    alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                            blockChangeOutput = false;
                            processWhirlPool();
                        }
                    });
                    if (!isFinishing()) {
                        alert.show();
                    }
                    break;
                }
        }
    });
    setUpViewPager();
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        if (account == WhirlpoolMeta.getInstance(getApplication()).getWhirlpoolPostmix()) {
            selectedCoins.clear();
            List<UTXOCoin> coinList = PreSelectUtil.getInstance().getPreSelected(preselectId);
            try {
                onUTXOSelected(coinList);
                newPoolViewPager.setCurrentItem(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) MonetaryUtil(com.samourai.wallet.util.MonetaryUtil) PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Spannable(android.text.Spannable) Completable(io.reactivex.Completable) ImageView(android.widget.ImageView) UnspentOutputWithKey(com.samourai.whirlpool.client.tx0.UnspentOutputWithKey) Optional(java8.util.Optional) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) WhirlpoolMeta(com.samourai.wallet.whirlpool.WhirlpoolMeta) SelectPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.SelectPoolFragment) Tx0(com.samourai.whirlpool.client.tx0.Tx0) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) ReviewPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.ReviewPoolFragment) Schedulers(io.reactivex.schedulers.Schedulers) UTXOUtil(com.samourai.wallet.utxos.UTXOUtil) Log(android.util.Log) BOLD(android.graphics.Typeface.BOLD) PreSelectUtil(com.samourai.wallet.utxos.PreSelectUtil) FeeUtil(com.samourai.wallet.send.FeeUtil) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService) Collection(java.util.Collection) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) ChooseUTXOsFragment(com.samourai.wallet.whirlpool.newPool.fragments.ChooseUTXOsFragment) AppCompatActivity(android.support.v7.app.AppCompatActivity) ECKey(org.bitcoinj.core.ECKey) AlertDialog(android.app.AlertDialog) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Tx0FeeTarget(com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget) WhirlpoolTx0(com.samourai.wallet.whirlpool.WhirlpoolTx0) Snackbar(android.support.design.widget.Snackbar) WhirlpoolWalletAccount(com.samourai.whirlpool.client.wallet.beans.WhirlpoolWalletAccount) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) UnspentResponse(com.samourai.wallet.api.backend.beans.UnspentResponse) MenuItem(android.view.MenuItem) Hex(org.bouncycastle.util.encoders.Hex) ArrayList(java.util.ArrayList) SendFactory(com.samourai.wallet.send.SendFactory) PoolCyclePriority(com.samourai.wallet.whirlpool.models.PoolCyclePriority) Toast(android.widget.Toast) DialogInterface(android.content.DialogInterface) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) SpannableString(android.text.SpannableString) Tx0Config(com.samourai.whirlpool.client.tx0.Tx0Config) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) R(com.samourai.wallet.R) ViewPager(com.samourai.wallet.widgets.ViewPager) FragmentManager(android.support.v4.app.FragmentManager) Toolbar(android.support.v7.widget.Toolbar) WhirlpoolNotificationService(com.samourai.wallet.whirlpool.service.WhirlpoolNotificationService) Activity(android.app.Activity) LogUtil(com.samourai.wallet.util.LogUtil) DialogInterface(android.content.DialogInterface) ReviewPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.ReviewPoolFragment) SpannableString(android.text.SpannableString) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) SelectPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.SelectPoolFragment) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

PoolViewModel (com.samourai.wallet.whirlpool.models.PoolViewModel)4 View (android.view.View)2 TextView (android.widget.TextView)2 R (com.samourai.wallet.R)2 LogUtil (com.samourai.wallet.util.LogUtil)2 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 BOLD (android.graphics.Typeface.BOLD)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Group (android.support.constraint.Group)1 Snackbar (android.support.design.widget.Snackbar)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1