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);
}
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);
});
}
Aggregations