Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network filter in edit visible #19015

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@
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;
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;
Expand All @@ -89,6 +91,19 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo
private List<NetworkInfo> mCryptoNetworks;
private UserAssetModel mUserAssetModel;
private boolean isEditVisibleAssetType;
private Spinner mNetworkSp;
private NetworkSpinnerAdapter mNetworkAdapter;
private ArrayList<NetworkInfo> 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);
Expand Down Expand Up @@ -276,14 +291,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;
}
Expand All @@ -302,6 +314,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);
}
});
}

Expand Down
16 changes: 7 additions & 9 deletions android/java/res/layout/edit_visible_assets_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@
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" />

<android.widget.Button
android:id="@+id/edit_visible_btn_network"
style="@style/BraveWalletButtonHollow"

<Spinner
android:id="@+id/edit_visible_network_spinner"
android:layout_width="0dp"
android:background="@drawable/rounded_holo_button"
android:minHeight="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:paddingVertical="2dp"
android:textColor="@color/brave_wallet_day_night_text_color"
android:visibility="gone"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/add_custom_asset"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_min="80dp" />
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down