From 1551d4d91c5a4c16d6cf24d1190f12bab22bd783 Mon Sep 17 00:00:00 2001 From: Pavneet-Sing Date: Fri, 23 Jun 2023 15:03:02 +0530 Subject: [PATCH 1/2] add network selector in edit visible --- ...isibleAssetsBottomSheetDialogFragment.java | 44 +++++++++++++++---- .../edit_visible_assets_bottom_sheet.xml | 17 ++++--- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java index b263bfd23428..9cf759ea46b2 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java @@ -72,8 +72,11 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.stream.IntStream; + public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialogFragment - implements View.OnClickListener, OnWalletListItemClick, KeyringServiceObserverImplDelegate { + implements View.OnClickListener, OnWalletListItemClick, KeyringServiceObserverImplDelegate, + AdapterView.OnItemSelectedListener { public static final String TAG_FRAGMENT = EditVisibleAssetsBottomSheetDialogFragment.class.getName(); private WalletCoinAdapter walletCoinAdapter; @@ -89,6 +92,19 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo private List mCryptoNetworks; private UserAssetModel mUserAssetModel; private boolean isEditVisibleAssetType; + private Spinner mNetworkSp; + private NetworkSpinnerAdapter mNetworkAdapter; + private ArrayList mSpinnerNetworks; + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (mUserAssetModel == null) return; + mSelectedNetwork = mSpinnerNetworks.get(position); + mUserAssetModel.fetchAssets(mNftsOnly, mSelectedNetwork); + } + + @Override + public void onNothingSelected(AdapterView parent) {} public interface DismissListener { void onDismiss(boolean isAssetsListChanged); @@ -276,14 +292,11 @@ public void onClick(View clickView) { if (mType == WalletCoinAdapter.AdapterType.EDIT_VISIBLE_ASSETS_LIST) { assert mSelectedNetwork != null; - Button networkNameBtn = view.findViewById(R.id.edit_visible_btn_network); - AndroidUtils.show(networkNameBtn); - networkNameBtn.setText(Utils.getShortNameOfNetwork(mSelectedNetwork.chainName)); - networkNameBtn.setOnLongClickListener(v -> { - Toast.makeText(requireContext(), mSelectedNetwork.chainName, Toast.LENGTH_SHORT) - .show(); - return true; - }); + mNetworkSp = view.findViewById(R.id.edit_visible_network_spinner); + mNetworkAdapter = new NetworkSpinnerAdapter(requireContext(), Collections.emptyList()); + mNetworkSp.setAdapter(mNetworkAdapter); + AndroidUtils.show(mNetworkSp); + mNetworkSp.setOnItemSelectedListener(this); } return view; } @@ -302,6 +315,19 @@ private void setUpObservers() { mUserAssetModel.mAssetsResult.observe(getViewLifecycleOwner(), assetsResult -> { setUpAssetsList(getView(), assetsResult.tokens, assetsResult.userAssets); }); + if (mNetworkAdapter != null) { + mSpinnerNetworks = new ArrayList<>(networkInfos); + mSpinnerNetworks.add(0, NetworkUtils.getAllNetworkOption(requireContext())); + mNetworkAdapter.setNetworks(mSpinnerNetworks); + int selectedNetworkIndex = + IntStream.range(0, mSpinnerNetworks.size()) + .filter(i + -> mSpinnerNetworks.get(i).chainId.equals( + mSelectedNetwork.chainId)) + .findFirst() + .orElse(0); + mNetworkSp.setSelection(selectedNetworkIndex, false); + } }); } diff --git a/android/java/res/layout/edit_visible_assets_bottom_sheet.xml b/android/java/res/layout/edit_visible_assets_bottom_sheet.xml index 189fe8cfd2ab..d2cab8e4f85b 100644 --- a/android/java/res/layout/edit_visible_assets_bottom_sheet.xml +++ b/android/java/res/layout/edit_visible_assets_bottom_sheet.xml @@ -30,25 +30,24 @@ android:paddingVertical="8dp" android:textColor="@color/brave_text_button_color" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@id/edit_visible_btn_network" + app:layout_constraintEnd_toStartOf="@id/edit_visible_network_spinner" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toTopOf="parent" /> Date: Fri, 23 Jun 2023 16:35:10 +0530 Subject: [PATCH 2/2] clean up --- .../fragments/EditVisibleAssetsBottomSheetDialogFragment.java | 1 - android/java/res/layout/edit_visible_assets_bottom_sheet.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java index 9cf759ea46b2..35cf77b5802c 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java @@ -66,7 +66,6 @@ import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils; import org.chromium.chrome.browser.crypto_wallet.util.Utils; import org.chromium.chrome.browser.util.LiveDataUtil; -import org.chromium.ui.widget.Toast; import java.util.ArrayList; import java.util.Collections; diff --git a/android/java/res/layout/edit_visible_assets_bottom_sheet.xml b/android/java/res/layout/edit_visible_assets_bottom_sheet.xml index d2cab8e4f85b..942755a61437 100644 --- a/android/java/res/layout/edit_visible_assets_bottom_sheet.xml +++ b/android/java/res/layout/edit_visible_assets_bottom_sheet.xml @@ -41,7 +41,6 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:paddingVertical="2dp" - android:paddingTop="2dp" android:textColor="@color/brave_wallet_day_night_text_color" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent"