From fc00c36066199fd8b33de964d440f1b70b193f89 Mon Sep 17 00:00:00 2001 From: Serg Date: Fri, 29 Jul 2022 17:01:11 -0400 Subject: [PATCH] Refreshes an account list after adding an account via a wallet panel on Android --- .../activities/AccountSelectorActivity.java | 59 +++++++++++-------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/activities/AccountSelectorActivity.java b/android/java/org/chromium/chrome/browser/crypto_wallet/activities/AccountSelectorActivity.java index 421577e3041..6da415e69e3 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/activities/AccountSelectorActivity.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/activities/AccountSelectorActivity.java @@ -43,35 +43,13 @@ public class AccountSelectorActivity onInitialLayoutInflationComplete(); } - @SuppressLint("NotifyDataSetChanged") private void init() { mRVNetworkSelector = findViewById(R.id.rv_account_selector_activity); mWalletCoinAdapter = new WalletCoinAdapter(WalletCoinAdapter.AdapterType.SELECT_ACCOUNTS_LIST); mRVNetworkSelector.setAdapter(mWalletCoinAdapter); mWalletCoinAdapter.setOnWalletListItemClick(this); - mWalletCoinAdapter.setOnWalletListItemClick(this); - mKeyringModel.getAccounts(accountInfos -> { - mAccountInfos = accountInfos; - List walletListItemModelList = new ArrayList<>(); - for (AccountInfo accountInfo : mAccountInfos) { - if (!accountInfo.isImported) { - walletListItemModelList.add( - new WalletListItemModel(R.drawable.ic_eth, accountInfo.name, - accountInfo.address, null, null, accountInfo.isImported)); - } - } - - mWalletCoinAdapter.setWalletListItemModelList(walletListItemModelList); - mWalletCoinAdapter.notifyDataSetChanged(); - - mKeyringModel.mSelectedAccount.observe(this, selectedAccountInfo -> { - if (selectedAccountInfo != null) { - mWalletCoinAdapter.updateSelectedNetwork( - selectedAccountInfo.name, selectedAccountInfo.address); - } - }); - }); + initAccounts(); MaterialToolbar toolbar = findViewById(R.id.toolbar); toolbar.setOnMenuItemClickListener(item -> { @@ -92,4 +70,39 @@ public class AccountSelectorActivity } } } + + @SuppressLint("NotifyDataSetChanged") + private void initAccounts() { + mKeyringModel.mSelectedAccount.observe(this, selectedAccountInfo -> { + if (selectedAccountInfo == null) return; + + boolean callDataSetChanged = true; + if (mAccountInfos != null) { + for (AccountInfo accountInfo : mAccountInfos) { + if (selectedAccountInfo.address.equals(accountInfo.address)) { + callDataSetChanged = false; + break; + } + } + } + if (!callDataSetChanged) return; + + mKeyringModel.getAccounts(accountInfos -> { + mAccountInfos = accountInfos; + List walletListItemModelList = new ArrayList<>(); + for (AccountInfo accountInfo : mAccountInfos) { + if (!accountInfo.isImported) { + walletListItemModelList.add( + new WalletListItemModel(R.drawable.ic_eth, accountInfo.name, + accountInfo.address, null, null, accountInfo.isImported)); + } + } + + mWalletCoinAdapter.setWalletListItemModelList(walletListItemModelList); + mWalletCoinAdapter.notifyDataSetChanged(); + mWalletCoinAdapter.updateSelectedNetwork( + selectedAccountInfo.name, selectedAccountInfo.address); + }); + }); + } }