Search in sources :

Example 1 with PoolsAdapter

use of com.samourai.wallet.whirlpool.adapters.PoolsAdapter 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 2 with PoolsAdapter

use of com.samourai.wallet.whirlpool.adapters.PoolsAdapter in project samourai-wallet-android by Samourai-Wallet.

the class SelectPoolFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    feeNormalBtn = view.findViewById(R.id.pool_fee_normal_btn);
    feeHighBtn = view.findViewById(R.id.pool_fee_high_btn);
    feeLowBtn = view.findViewById(R.id.pool_fee_low_btn);
    recyclerView = view.findViewById(R.id.pool_recycler_view);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new SeparatorDecoration(getContext(), ContextCompat.getColor(getContext(), R.color.item_separator_grey), 1));
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    poolsAdapter = new PoolsAdapter(getContext(), poolViewModels);
    recyclerView.setAdapter(poolsAdapter);
    poolFee = view.findViewById(R.id.pool_fee_txt);
    feeLowBtn.setOnClickListener(view1 -> setPoolCyclePriority(PoolCyclePriority.LOW));
    feeHighBtn.setOnClickListener(view1 -> setPoolCyclePriority(PoolCyclePriority.HIGH));
    feeNormalBtn.setOnClickListener(view1 -> setPoolCyclePriority(PoolCyclePriority.NORMAL));
    if (fees.size() >= 2)
        poolFee.setText(String.valueOf(fees.get(1)).concat(" ").concat(getString(R.string.sat_b)));
    poolsAdapter.setOnItemsSelectListener(position -> {
        for (int i = 0; i < poolViewModels.size(); i++) {
            if (i == position) {
                boolean selected = !poolViewModels.get(position).isSelected();
                poolViewModels.get(i).setSelected(selected);
                if (selected && this.onPoolSelectionComplete != null) {
                    onPoolSelectionComplete.onSelect(poolViewModels.get(i), poolCyclePriority);
                } else {
                    if (onPoolSelectionComplete != null)
                        onPoolSelectionComplete.onSelect(null, poolCyclePriority);
                }
            } else {
                poolViewModels.get(i).setSelected(false);
            }
        }
        poolsAdapter.update(poolViewModels);
    });
}
Also used : PoolsAdapter(com.samourai.wallet.whirlpool.adapters.PoolsAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Paint(android.graphics.Paint)

Aggregations

PoolsAdapter (com.samourai.wallet.whirlpool.adapters.PoolsAdapter)2 Paint (android.graphics.Paint)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PoolViewModel (com.samourai.wallet.whirlpool.models.PoolViewModel)1 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1