Code review suggestions

This commit is contained in:
Serg
2021-09-21 11:10:30 -04:00
parent 8829a4b6f4
commit b0aeb0c6db
12 changed files with 79 additions and 69 deletions
@@ -49,6 +49,7 @@ import org.chromium.mojo.system.MojoException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class BuySendSwapActivity extends AsyncInitializationActivity
@@ -229,7 +230,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
TextView fromBalanceText = findViewById(R.id.from_balance_text);
mConvertedBalance = Utils.fromHexWei(balance);
fromBalanceText.setText(getText(R.string.crypto_wallet_balance) + " "
+ String.format("%.4f", mConvertedBalance));
+ String.format(Locale.getDefault(), "%.4f", mConvertedBalance));
});
}
@@ -378,7 +379,7 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
}
TextView fromValueText = findViewById(R.id.from_value_text);
fromValueText.setText(String.format("%f", amountToGet));
fromValueText.setText(String.format(Locale.getDefault(), "%f", amountToGet));
radioPerPercent.clearCheck();
}
});
@@ -27,6 +27,7 @@ import org.chromium.chrome.browser.crypto_wallet.util.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class WalletCoinAdapter extends RecyclerView.Adapter<WalletCoinAdapter.ViewHolder> {
public enum AdapterType {
@@ -184,10 +185,10 @@ public class WalletCoinAdapter extends RecyclerView.Adapter<WalletCoinAdapter.Vi
if (text.isEmpty()) {
walletListItemModelList.addAll(walletListItemModelListCopy);
} else {
text = text.toLowerCase();
text = text.toLowerCase(Locale.getDefault());
for (WalletListItemModel item : walletListItemModelListCopy) {
if (item.getTitle().toLowerCase().contains(text)
|| item.getSubTitle().toLowerCase().contains(text)) {
if (item.getTitle().toLowerCase(Locale.getDefault()).contains(text)
|| item.getSubTitle().toLowerCase(Locale.getDefault()).contains(text)) {
walletListItemModelList.add(item);
}
}
@@ -15,7 +15,6 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -38,6 +37,8 @@ import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
import org.chromium.chrome.browser.crypto_wallet.adapters.ApproveTxFragmentPageAdapter;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
import java.util.Locale;
public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragment {
public static final String TAG_FRAGMENT = ApproveTxBottomSheetDialogFragment.class.getName();
@@ -131,16 +132,19 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
ImageView icon = (ImageView) view.findViewById(R.id.account_picture);
icon.setImageResource(mAccountPic);
TextView fromTo = view.findViewById(R.id.from_to);
fromTo.setText(
mAccountName + " -> " + Utils.stripAccountAddress(mTxInfo.txData.baseData.to));
fromTo.setText(String.format(getResources().getString(R.string.crypto_wallet_from_to),
mAccountName, Utils.stripAccountAddress(mTxInfo.txData.baseData.to)));
TextView txType = view.findViewById(R.id.tx_type);
txType.setText(mTxType);
TextView amountAsset = view.findViewById(R.id.amount_asset);
amountAsset.setText(String.format("%.4f", Utils.fromHexWei(mTxInfo.txData.baseData.value))
+ " " + mAsset);
amountAsset.setText(
String.format(getResources().getString(R.string.crypto_wallet_amount_asset),
String.format(Locale.getDefault(), "%.4f",
Utils.fromHexWei(mTxInfo.txData.baseData.value)),
mAsset));
AssetRatioController assetRatioController = getAssetRatioController();
if (assetRatioController != null) {
String[] assets = {mAsset.toLowerCase()};
String[] assets = {mAsset.toLowerCase(Locale.getDefault())};
String[] toCurr = {"usd"};
assetRatioController.getPrice(
assets, toCurr, AssetPriceTimeframe.LIVE, (success, values) -> {
@@ -151,7 +155,9 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
double price = Double.valueOf(values[0].price);
mTotalPrice = value * price;
TextView amountFiat = view.findViewById(R.id.amount_fiat);
amountFiat.setText("$" + String.format("%.2f", mTotalPrice));
amountFiat.setText(String.format(
getResources().getString(R.string.crypto_wallet_amount_fiat),
String.format(Locale.getDefault(), "%.2f", mTotalPrice)));
ViewPager viewPager = view.findViewById(R.id.navigation_view_pager);
ApproveTxFragmentPageAdapter adapter =
new ApproveTxFragmentPageAdapter(getChildFragmentManager(), mTxInfo,
@@ -175,18 +181,7 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
approve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EthTxController ethTxController = getEthTxController();
if (ethTxController == null) {
return;
}
ethTxController.approveTransaction(mTxInfo.id, success -> {
assert success;
if (!success) {
return;
}
mApproved = true;
dismiss();
});
approveTransaction();
}
});
}
@@ -205,4 +200,19 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
dismiss();
});
}
private void approveTransaction() {
EthTxController ethTxController = getEthTxController();
if (ethTxController == null) {
return;
}
ethTxController.approveTransaction(mTxInfo.id, success -> {
assert success;
if (!success) {
return;
}
mApproved = true;
dismiss();
});
}
}
@@ -5,19 +5,14 @@
package org.chromium.chrome.browser.crypto_wallet.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.chromium.brave_wallet.mojom.TransactionInfo;
import org.chromium.chrome.R;
@@ -33,11 +28,6 @@ public class TxDetailsFragment extends Fragment {
mTxInfo = txInfo;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@@ -46,14 +36,4 @@ public class TxDetailsFragment extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
@@ -5,11 +5,9 @@
package org.chromium.chrome.browser.crypto_wallet.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -17,8 +15,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.chromium.brave_wallet.mojom.AssetPriceTimeframe;
import org.chromium.brave_wallet.mojom.AssetRatioController;
@@ -29,6 +25,8 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
import java.util.Locale;
public class TxFragment extends Fragment {
private TransactionInfo mTxInfo;
private String mAsset;
@@ -66,12 +64,17 @@ public class TxFragment extends Fragment {
TextView gasFeeAmount = view.findViewById(R.id.gas_fee_amount);
gasFeeAmount.setText(
String.format("%.8f", Utils.fromHexWei(mTxInfo.txData.baseData.gasPrice)) + " ETH");
String.format(getResources().getString(R.string.crypto_wallet_gas_fee_amount),
String.format(Locale.getDefault(), "%.8f",
Utils.fromHexWei(mTxInfo.txData.baseData.gasPrice))));
TextView totalAmount = view.findViewById(R.id.total_amount);
totalAmount.setText(String.format("%.8f", Utils.fromHexWei(mTxInfo.txData.baseData.value))
+ " " + mAsset + " + "
+ String.format("%.8f", Utils.fromHexWei(mTxInfo.txData.baseData.gasPrice))
+ " ETH");
totalAmount.setText(
String.format(getResources().getString(R.string.crypto_wallet_total_amount),
String.format(Locale.getDefault(), "%.8f",
Utils.fromHexWei(mTxInfo.txData.baseData.value)),
mAsset,
String.format(Locale.getDefault(), "%.8f",
Utils.fromHexWei(mTxInfo.txData.baseData.gasPrice))));
AssetRatioController assetRatioController = getAssetRatioController();
if (assetRatioController != null) {
String[] assets = {"eth"};
@@ -85,10 +88,14 @@ public class TxFragment extends Fragment {
double price = Double.valueOf(values[0].price);
double totalPrice = value * price;
TextView gasFeeAmountFiat = view.findViewById(R.id.gas_fee_amount_fiat);
gasFeeAmountFiat.setText("$" + String.format("%.2f", totalPrice));
gasFeeAmountFiat.setText(String.format(
getResources().getString(R.string.crypto_wallet_amount_fiat),
String.format(Locale.getDefault(), "%.2f", totalPrice)));
double totalAmountPlusGas = totalPrice + mTotalPrice;
TextView totalAmountFiat = view.findViewById(R.id.total_amount_fiat);
totalAmountFiat.setText("$" + String.format("%.2f", totalAmountPlusGas));
totalAmountFiat.setText(String.format(
getResources().getString(R.string.crypto_wallet_amount_fiat),
String.format(Locale.getDefault(), "%.2f", totalAmountPlusGas)));
});
}
@@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
public class SmoothLineChartEquallySpaced extends View {
@@ -85,7 +86,7 @@ public class SmoothLineChartEquallySpaced extends View {
for (int index = 0; index < data.length; index++) {
mValues[index] = Float.parseFloat(data[index].price);
Date date = new Date(data[index].date.microseconds / 1000);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a", Locale.getDefault());
mDates[index] = dateFormat.format(date);
}
@@ -111,7 +112,7 @@ public class SmoothLineChartEquallySpaced extends View {
}
for (int index = 0; index < mValues.length; index++) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a", Locale.getDefault());
mDates[index] = dateFormat.format(date);
}
@@ -2,7 +2,7 @@
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="HardcodedText"
tools:ignore="HardcodedText,Autofill,LabelFor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/wallet_bg"
@@ -96,6 +96,7 @@
android:id="@+id/from_value_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="@color/wallet_text_color"
android:textSize="20sp"/>
@@ -246,6 +247,7 @@
android:id="@+id/to_value_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="@color/wallet_text_color"
android:textSize="20sp"/>
@@ -365,6 +367,7 @@
android:id="@+id/limit_price_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:visibility="gone"
android:hint="0"
android:textColor="@color/wallet_text_color"
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="RtlSymmetry"
tools:ignore="RtlSymmetry,NestedWeights"
android:background="@color/wallet_bg"
android:orientation="vertical"
tools:context=".ApproveTxBottomSheetDialogFragment">
@@ -40,6 +40,7 @@
android:textColor="@color/brave_blue_tint_color"
android:text="@string/edit"
android:clickable="true"
android:focusable="true"
android:textSize="14sp" />
<TextView
@@ -5,12 +5,4 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:orientation="vertical">
</LinearLayout>
</androidx.core.widget.NestedScrollView>
@@ -73,8 +73,7 @@
android:id="@+id/assetCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_centerVertical="true" />
android:visibility="gone" />
</LinearLayout>