Adds list for buy/send on Android
This commit is contained in:
+1
@@ -137,6 +137,7 @@ public class BraveWalletActivity
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {
|
||||
mKeyringController = null;
|
||||
mErcTokenRegistry = null;
|
||||
InitKeyringController();
|
||||
InitErcTokenRegistry();
|
||||
}
|
||||
|
||||
+48
-1
@@ -18,13 +18,20 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.ErcTokenRegistry;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.ERCTokenRegistryFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.fragments.EditVisibleAssetsBottomSheetDialogFragment;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
public class BuySendSwapActivity
|
||||
extends AsyncInitializationActivity implements ConnectionErrorHandler {
|
||||
public enum ActivityType {
|
||||
BUY(0),
|
||||
SEND(1),
|
||||
@@ -52,6 +59,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private ErcTokenRegistry mErcTokenRegistry;
|
||||
private ActivityType mActivityType;
|
||||
|
||||
@Override
|
||||
@@ -105,6 +113,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
onInitialLayoutInflationComplete();
|
||||
|
||||
adjustControls();
|
||||
InitErcTokenRegistry();
|
||||
}
|
||||
|
||||
private void adjustControls() {
|
||||
@@ -117,6 +126,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
Button btnBuySendSwap = findViewById(R.id.btn_buy_send_swap);
|
||||
TextView currencySign = findViewById(R.id.currency_sign);
|
||||
TextView toEstimateText = findViewById(R.id.to_estimate_text);
|
||||
TextView assetDropDown = findViewById(R.id.from_asset_text);
|
||||
if (mActivityType == ActivityType.BUY) {
|
||||
TextView fromBuyText = findViewById(R.id.from_buy_text);
|
||||
fromBuyText.setText(getText(R.string.buy_wallet));
|
||||
@@ -130,6 +140,13 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
btnBuySendSwap.setText(getText(R.string.buy_wallet));
|
||||
RadioGroup radioPerPercent = findViewById(R.id.per_percent_radiogroup);
|
||||
radioPerPercent.setVisibility(View.GONE);
|
||||
assetDropDown.setOnClickListener(v -> {
|
||||
EditVisibleAssetsBottomSheetDialogFragment bottomSheetDialogFragment =
|
||||
EditVisibleAssetsBottomSheetDialogFragment.newInstance(
|
||||
WalletCoinAdapter.AdapterType.BUY_ASSETS_LIST);
|
||||
bottomSheetDialogFragment.show(getSupportFragmentManager(),
|
||||
EditVisibleAssetsBottomSheetDialogFragment.TAG_FRAGMENT);
|
||||
});
|
||||
} else if (mActivityType == ActivityType.SEND) {
|
||||
currencySign.setVisibility(View.GONE);
|
||||
toEstimateText.setText(getText(R.string.to_address));
|
||||
@@ -141,6 +158,13 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
btnBuySendSwap.setText(getText(R.string.send));
|
||||
LinearLayout toBalanceSection = findViewById(R.id.to_balance_section);
|
||||
toBalanceSection.setVisibility(View.GONE);
|
||||
assetDropDown.setOnClickListener(v -> {
|
||||
EditVisibleAssetsBottomSheetDialogFragment bottomSheetDialogFragment =
|
||||
EditVisibleAssetsBottomSheetDialogFragment.newInstance(
|
||||
WalletCoinAdapter.AdapterType.SEND_ASSETS_LIST);
|
||||
bottomSheetDialogFragment.show(getSupportFragmentManager(),
|
||||
EditVisibleAssetsBottomSheetDialogFragment.TAG_FRAGMENT);
|
||||
});
|
||||
} else if (mActivityType == ActivityType.SWAP) {
|
||||
currencySign.setVisibility(View.GONE);
|
||||
toValueText.setText("");
|
||||
@@ -180,6 +204,29 @@ public class BuySendSwapActivity extends AsyncInitializationActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBuySendAsset(String asset) {
|
||||
TextView assetDropDown = findViewById(R.id.from_asset_text);
|
||||
assetDropDown.setText(asset);
|
||||
}
|
||||
|
||||
public ErcTokenRegistry getErcTokenRegistry() {
|
||||
return mErcTokenRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {
|
||||
mErcTokenRegistry = null;
|
||||
InitErcTokenRegistry();
|
||||
}
|
||||
|
||||
private void InitErcTokenRegistry() {
|
||||
if (mErcTokenRegistry != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mErcTokenRegistry = ERCTokenRegistryFactory.getInstance().getERCTokenRegistry(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
+41
-21
@@ -13,6 +13,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -31,7 +32,9 @@ public class WalletCoinAdapter extends RecyclerView.Adapter<WalletCoinAdapter.Vi
|
||||
public enum AdapterType {
|
||||
VISIBLE_ASSETS_LIST,
|
||||
EDIT_VISIBLE_ASSETS_LIST,
|
||||
ACCOUNTS_LIST;
|
||||
ACCOUNTS_LIST,
|
||||
BUY_ASSETS_LIST,
|
||||
SEND_ASSETS_LIST;
|
||||
}
|
||||
|
||||
private Context context;
|
||||
@@ -75,34 +78,50 @@ public class WalletCoinAdapter extends RecyclerView.Adapter<WalletCoinAdapter.Vi
|
||||
if (walletListItemType == Utils.TRANSACTION_ITEM) {
|
||||
onWalletListItemClick.onTransactionClick();
|
||||
} else if (walletListItemType == Utils.ASSET_ITEM) {
|
||||
onWalletListItemClick.onAssetClick();
|
||||
if (mType == AdapterType.BUY_ASSETS_LIST || mType == AdapterType.SEND_ASSETS_LIST) {
|
||||
for (int i = 0; i < walletListItemModelListCopy.size(); i++) {
|
||||
WalletListItemModel item = walletListItemModelListCopy.get(i);
|
||||
if (item.getTitle().contains(holder.titleText.getText())
|
||||
|| item.getSubTitle().contains(holder.subTitleText.getText())) {
|
||||
mCheckedPositions.add((Integer) i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mType != AdapterType.EDIT_VISIBLE_ASSETS_LIST) {
|
||||
onWalletListItemClick.onAssetClick();
|
||||
}
|
||||
} else {
|
||||
onWalletListItemClick.onAccountClick();
|
||||
}
|
||||
});
|
||||
if (mType == AdapterType.EDIT_VISIBLE_ASSETS_LIST) {
|
||||
if (mType == AdapterType.EDIT_VISIBLE_ASSETS_LIST || mType == AdapterType.BUY_ASSETS_LIST
|
||||
|| mType == AdapterType.SEND_ASSETS_LIST) {
|
||||
holder.text1Text.setVisibility(View.GONE);
|
||||
holder.text2Text.setVisibility(View.GONE);
|
||||
holder.assetCheck.setVisibility(View.VISIBLE);
|
||||
holder.assetCheck.setOnCheckedChangeListener(
|
||||
new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
for (int i = 0; i <= walletListItemModelListCopy.size(); i++) {
|
||||
WalletListItemModel item = walletListItemModelListCopy.get(i);
|
||||
if (item.getTitle().contains(holder.titleText.getText())
|
||||
|| item.getSubTitle().contains(
|
||||
holder.subTitleText.getText())) {
|
||||
if (isChecked) {
|
||||
mCheckedPositions.add((Integer) i);
|
||||
} else {
|
||||
mCheckedPositions.remove((Integer) i);
|
||||
if (mType == AdapterType.EDIT_VISIBLE_ASSETS_LIST) {
|
||||
holder.assetCheck.setVisibility(View.VISIBLE);
|
||||
holder.assetCheck.setOnCheckedChangeListener(
|
||||
new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(
|
||||
CompoundButton buttonView, boolean isChecked) {
|
||||
for (int i = 0; i < walletListItemModelListCopy.size(); i++) {
|
||||
WalletListItemModel item = walletListItemModelListCopy.get(i);
|
||||
if (item.getTitle().contains(holder.titleText.getText())
|
||||
|| item.getSubTitle().contains(
|
||||
holder.subTitleText.getText())) {
|
||||
if (isChecked) {
|
||||
mCheckedPositions.add((Integer) i);
|
||||
} else {
|
||||
mCheckedPositions.remove((Integer) i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +132,8 @@ public class WalletCoinAdapter extends RecyclerView.Adapter<WalletCoinAdapter.Vi
|
||||
|
||||
public void setWalletListItemModelList(List<WalletListItemModel> walletListItemModelList) {
|
||||
this.walletListItemModelList = walletListItemModelList;
|
||||
if (mType == AdapterType.EDIT_VISIBLE_ASSETS_LIST) {
|
||||
if (mType == AdapterType.EDIT_VISIBLE_ASSETS_LIST || mType == AdapterType.BUY_ASSETS_LIST
|
||||
|| mType == AdapterType.SEND_ASSETS_LIST) {
|
||||
walletListItemModelListCopy.addAll(walletListItemModelList);
|
||||
mCheckedPositions.clear();
|
||||
}
|
||||
|
||||
+65
-39
@@ -36,6 +36,7 @@ import org.chromium.brave_wallet.mojom.ErcToken;
|
||||
import org.chromium.brave_wallet.mojom.ErcTokenRegistry;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
|
||||
@@ -49,15 +50,23 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
public static final String TAG_FRAGMENT =
|
||||
EditVisibleAssetsBottomSheetDialogFragment.class.getName();
|
||||
private WalletCoinAdapter walletCoinAdapter;
|
||||
private WalletCoinAdapter.AdapterType mType;
|
||||
|
||||
public static EditVisibleAssetsBottomSheetDialogFragment newInstance() {
|
||||
return new EditVisibleAssetsBottomSheetDialogFragment();
|
||||
public static EditVisibleAssetsBottomSheetDialogFragment newInstance(
|
||||
WalletCoinAdapter.AdapterType type) {
|
||||
return new EditVisibleAssetsBottomSheetDialogFragment(type);
|
||||
}
|
||||
|
||||
private EditVisibleAssetsBottomSheetDialogFragment(WalletCoinAdapter.AdapterType type) {
|
||||
mType = type;
|
||||
}
|
||||
|
||||
private ErcTokenRegistry getErcTokenRegistry() {
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof BraveWalletActivity) {
|
||||
return ((BraveWalletActivity) activity).getErcTokenRegistry();
|
||||
} else if (activity instanceof BuySendSwapActivity) {
|
||||
return ((BuySendSwapActivity) activity).getErcTokenRegistry();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -126,51 +135,34 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
ViewParent parent = view.getParent();
|
||||
((View) parent).getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
Button saveAssets = view.findViewById(R.id.saveAssets);
|
||||
saveAssets.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View clickView) {
|
||||
if (walletCoinAdapter != null) {
|
||||
// TODO(sergz): Save selected assets walletCoinAdapter.getCheckedAssets()
|
||||
if (mType == WalletCoinAdapter.AdapterType.EDIT_VISIBLE_ASSETS_LIST) {
|
||||
saveAssets.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View clickView) {
|
||||
if (walletCoinAdapter != null) {
|
||||
// TODO(sergz): Save selected assets walletCoinAdapter.getCheckedAssets()
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
saveAssets.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ErcTokenRegistry ercTokenRegistry = getErcTokenRegistry();
|
||||
if (ercTokenRegistry != null) {
|
||||
ercTokenRegistry.getAllTokens(tokens -> {
|
||||
setUpAssetsList(view, tokens);
|
||||
SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
|
||||
searchView.setQueryHint(getText(R.string.search_tokens));
|
||||
searchView.setIconified(false);
|
||||
searchView.clearFocus();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.filter(query);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.filter(newText);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (mType == WalletCoinAdapter.AdapterType.EDIT_VISIBLE_ASSETS_LIST
|
||||
|| mType == WalletCoinAdapter.AdapterType.SEND_ASSETS_LIST) {
|
||||
ercTokenRegistry.getAllTokens(tokens -> { setUpAssetsList(view, tokens); });
|
||||
} else if (mType == WalletCoinAdapter.AdapterType.BUY_ASSETS_LIST) {
|
||||
ercTokenRegistry.getBuyTokens(tokens -> { setUpAssetsList(view, tokens); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpAssetsList(View view, ErcToken[] tokens) {
|
||||
RecyclerView rvAssets = view.findViewById(R.id.rvAssets);
|
||||
walletCoinAdapter =
|
||||
new WalletCoinAdapter(WalletCoinAdapter.AdapterType.EDIT_VISIBLE_ASSETS_LIST);
|
||||
walletCoinAdapter = new WalletCoinAdapter(mType);
|
||||
List<WalletListItemModel> walletListItemModelList = new ArrayList<>();
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
walletListItemModelList.add(new WalletListItemModel(
|
||||
@@ -181,6 +173,29 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
walletCoinAdapter.setWalletListItemType(Utils.ASSET_ITEM);
|
||||
rvAssets.setAdapter(walletCoinAdapter);
|
||||
rvAssets.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
|
||||
searchView.setQueryHint(getText(R.string.search_tokens));
|
||||
searchView.setIconified(false);
|
||||
searchView.clearFocus();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.filter(query);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.filter(newText);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,5 +204,16 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssetClick() {}
|
||||
public void onAssetClick() {
|
||||
if (mType == WalletCoinAdapter.AdapterType.SEND_ASSETS_LIST
|
||||
|| mType == WalletCoinAdapter.AdapterType.BUY_ASSETS_LIST) {
|
||||
List<WalletListItemModel> checkedAssets = walletCoinAdapter.getCheckedAssets();
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof BuySendSwapActivity && checkedAssets.size() > 0) {
|
||||
((BuySendSwapActivity) activity)
|
||||
.updateBuySendAsset(checkedAssets.get(0).getSubTitle());
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -81,7 +81,8 @@ public class PortfolioFragment extends Fragment implements OnWalletListItemClick
|
||||
Button editVisibleAssets = view.findViewById(R.id.edit_visible_assets);
|
||||
editVisibleAssets.setOnClickListener(v -> {
|
||||
EditVisibleAssetsBottomSheetDialogFragment bottomSheetDialogFragment =
|
||||
EditVisibleAssetsBottomSheetDialogFragment.newInstance();
|
||||
EditVisibleAssetsBottomSheetDialogFragment.newInstance(
|
||||
WalletCoinAdapter.AdapterType.EDIT_VISIBLE_ASSETS_LIST);
|
||||
bottomSheetDialogFragment.show(
|
||||
getFragmentManager(), EditVisibleAssetsBottomSheetDialogFragment.TAG_FRAGMENT);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user