Merge pull request #10830 from brave/a_w_portfolio_ui_fixes
Show Android portfolio balance percentage trend
This commit is contained in:
+5
-13
@@ -196,8 +196,10 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
assert mChainId != null && !mChainId.isEmpty();
|
||||
|
||||
braveWalletService.getUserAssets(mChainId, (userAssets) -> {
|
||||
ercTokenRegistry.getAllTokens(
|
||||
tokens -> { setUpAssetsList(view, tokens, userAssets); });
|
||||
ercTokenRegistry.getAllTokens(tokens -> {
|
||||
tokens = Utils.fixupTokensRegistry(tokens, mChainId);
|
||||
setUpAssetsList(view, tokens, userAssets);
|
||||
});
|
||||
});
|
||||
} else if (mType == WalletCoinAdapter.AdapterType.SEND_ASSETS_LIST
|
||||
|| mType == WalletCoinAdapter.AdapterType.SWAP_ASSETS_LIST) {
|
||||
@@ -210,16 +212,6 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
}
|
||||
}
|
||||
|
||||
private ErcToken createEthereumErcToken() {
|
||||
ErcToken eth = new ErcToken();
|
||||
eth.name = "Ethereum";
|
||||
eth.symbol = "ETH";
|
||||
eth.contractAddress = "";
|
||||
eth.logo = "eth.png";
|
||||
eth.decimals = 18;
|
||||
return eth;
|
||||
}
|
||||
|
||||
private void setUpAssetsList(View view, ErcToken[] tokens, ErcToken[] userSelectedTokens) {
|
||||
HashSet<String> selectedTokensSymbols = new HashSet<String>();
|
||||
for (ErcToken userSelectedToken : userSelectedTokens) {
|
||||
@@ -230,7 +222,7 @@ public class EditVisibleAssetsBottomSheetDialogFragment
|
||||
walletCoinAdapter = new WalletCoinAdapter(mType);
|
||||
List<WalletListItemModel> walletListItemModelList = new ArrayList<>();
|
||||
// Add ETH as a first item always
|
||||
ErcToken eth = createEthereumErcToken();
|
||||
ErcToken eth = Utils.createEthereumErcToken();
|
||||
WalletListItemModel itemModelEth =
|
||||
new WalletListItemModel(R.drawable.ic_eth, eth.name, eth.symbol, "", "");
|
||||
itemModelEth.setIsUserSelected(
|
||||
|
||||
+35
@@ -320,6 +320,39 @@ public class PortfolioFragment extends Fragment
|
||||
return null;
|
||||
}
|
||||
|
||||
private void AdjustTrendControls() {
|
||||
TextView trendTimeframe = getView().findViewById(R.id.trend_timeframe);
|
||||
TextView trendPercentage = getView().findViewById(R.id.trend_percentage);
|
||||
|
||||
if (mPortfolioHelper.isFiatHistoryEmpty()) {
|
||||
trendTimeframe.setVisibility(View.GONE);
|
||||
trendPercentage.setVisibility(View.GONE);
|
||||
} else {
|
||||
trendTimeframe.setText(Utils.getTimeframeString(mCurrentTimeframeType));
|
||||
|
||||
Double currentFiatSum = mPortfolioHelper.getTotalFiatSum();
|
||||
Double mostPreviousFiatSum = mPortfolioHelper.getMostPreviousFiatSum();
|
||||
|
||||
Double percents = ((currentFiatSum - mostPreviousFiatSum) / mostPreviousFiatSum) * 100;
|
||||
trendPercentage.setText(
|
||||
String.format(Locale.getDefault(), "%.2f%%", Math.abs(percents)));
|
||||
if (mostPreviousFiatSum > currentFiatSum) {
|
||||
trendPercentage.setTextColor(
|
||||
getResources().getColor(R.color.wallet_negative_trend_color));
|
||||
trendPercentage.setCompoundDrawablesWithIntrinsicBounds(
|
||||
R.drawable.ic_down_icon, 0, 0, 0);
|
||||
} else {
|
||||
trendPercentage.setTextColor(
|
||||
getResources().getColor(R.color.wallet_positive_trend_color));
|
||||
trendPercentage.setCompoundDrawablesWithIntrinsicBounds(
|
||||
R.drawable.ic_up_icon, 0, 0, 0);
|
||||
}
|
||||
|
||||
trendTimeframe.setVisibility(View.VISIBLE);
|
||||
trendPercentage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePortfolioGraph() {
|
||||
AssetPriceTimeframe.validate(mCurrentTimeframeType);
|
||||
|
||||
@@ -334,6 +367,8 @@ public class PortfolioFragment extends Fragment
|
||||
SmoothLineChartEquallySpaced chartES = getView().findViewById(R.id.line_chart);
|
||||
chartES.setColors(new int[] {0xFFF73A1C, 0xFFBF14A2, 0xFF6F4CD2});
|
||||
chartES.setData(mPortfolioHelper.getFiatHistory());
|
||||
|
||||
AdjustTrendControls();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,6 +81,27 @@ public class PortfolioHelper {
|
||||
return mFiatHistory;
|
||||
}
|
||||
|
||||
public boolean isFiatHistoryEmpty() {
|
||||
if (mFiatHistory == null || mFiatHistory.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (AssetTimePrice assetTimePrice : mFiatHistory) {
|
||||
if (Double.valueOf(assetTimePrice.price) > 0.001d) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Double getMostPreviousFiatSum() {
|
||||
if (mFiatHistory == null || mFiatHistory.length == 0) {
|
||||
return 0.0d;
|
||||
}
|
||||
return Double.valueOf(mFiatHistory[mFiatHistory.length - 1].price);
|
||||
}
|
||||
|
||||
public void calculateBalances(Runnable runWhenDone) {
|
||||
resetResultData();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
@@ -37,6 +38,7 @@ import org.chromium.base.Log;
|
||||
import org.chromium.base.Predicate;
|
||||
import org.chromium.brave_wallet.mojom.AssetPriceTimeframe;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletConstants;
|
||||
import org.chromium.brave_wallet.mojom.ErcToken;
|
||||
import org.chromium.brave_wallet.mojom.TxData;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.AccountDetailActivity;
|
||||
@@ -678,4 +680,47 @@ public class Utils {
|
||||
return AssetPriceTimeframe.ALL;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTimeframeString(int assetPriceTimeframe) {
|
||||
Resources resources = ContextUtils.getApplicationContext().getResources();
|
||||
assert resources != null;
|
||||
|
||||
switch (assetPriceTimeframe) {
|
||||
case AssetPriceTimeframe.LIVE:
|
||||
return resources.getString(R.string.trend_1h_text);
|
||||
case AssetPriceTimeframe.ONE_DAY:
|
||||
return resources.getString(R.string.trend_1d_text);
|
||||
case AssetPriceTimeframe.ONE_WEEK:
|
||||
return resources.getString(R.string.trend_1w_text);
|
||||
case AssetPriceTimeframe.ONE_MONTH:
|
||||
return resources.getString(R.string.trend_1m_text);
|
||||
case AssetPriceTimeframe.THREE_MONTHS:
|
||||
return resources.getString(R.string.trend_3m_text);
|
||||
case AssetPriceTimeframe.ONE_YEAR:
|
||||
return resources.getString(R.string.trend_1y_text);
|
||||
case AssetPriceTimeframe.ALL:
|
||||
return resources.getString(R.string.trend_all_text);
|
||||
default:
|
||||
assert false;
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
public static ErcToken createEthereumErcToken() {
|
||||
ErcToken eth = new ErcToken();
|
||||
eth.name = "Ethereum";
|
||||
eth.symbol = "ETH";
|
||||
eth.contractAddress = "";
|
||||
eth.logo = "eth.png";
|
||||
eth.decimals = 18;
|
||||
return eth;
|
||||
}
|
||||
|
||||
public static ErcToken[] fixupTokensRegistry(ErcToken[] tokens, String chainId) {
|
||||
for (ErcToken token : tokens) {
|
||||
token.contractAddress =
|
||||
getContractAddress(chainId, token.symbol, token.contractAddress);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="8dp"
|
||||
android:height="6dp"
|
||||
android:viewportWidth="8"
|
||||
android:viewportHeight="6">
|
||||
<path
|
||||
android:pathData="M4,6L7.46,0H0.54L4,6Z"
|
||||
android:fillColor="#CF5159"/>
|
||||
</vector>
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_show_private_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_add"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_buy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -257,7 +257,7 @@
|
||||
android:textColor="@android:color/white"
|
||||
style="?android:attr/borderlessButtonStyle"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -275,7 +275,7 @@
|
||||
android:textColor="@android:color/white"
|
||||
style="?android:attr/borderlessButtonStyle"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_swap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -429,7 +429,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_buy_send_swap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -449,4 +449,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/reject"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -118,7 +118,7 @@
|
||||
android:textColor="@android:color/white"
|
||||
style="?android:attr/borderlessButtonStyle"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/approve"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -142,4 +142,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -69,7 +69,7 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -89,7 +89,7 @@
|
||||
android:textColor="@android:color/white"
|
||||
style="?android:attr/borderlessButtonStyle"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/ok"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -110,5 +110,5 @@
|
||||
style="?android:attr/borderlessButtonStyle"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
android:layout_weight = "9.8"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/saveAssets"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
android:layout_marginBottom="40dp"/>
|
||||
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_backup_wallet_continue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -105,4 +105,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
@@ -59,21 +59,18 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/trend_percentage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1.3%"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:drawablePadding="4dp"
|
||||
android:textColor="@color/wallet_positive_trend_color"
|
||||
android:textSize="14sp"
|
||||
app:drawableStartCompat="@drawable/ic_up_icon"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/trend_timeframe"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/today"
|
||||
android:textColor="@color/wallet_secondary_layout_text_color"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -255,7 +252,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/edit_visible_assets"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_recovery_phrase_continue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
android:textColorHint="@color/wallet_edittext_outline_color" />
|
||||
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_restore_wallet"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
android:textColorHint="@color/wallet_edittext_outline_color" />
|
||||
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_secure_crypto_continue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -116,4 +116,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
android:textColor="@color/wallet_secondary_text_color"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_setup_crypto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
android:textColor="@color/wallet_text_color"
|
||||
android:textColorHint="@color/wallet_edittext_outline_color" />
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_unlock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
android:layout_marginEnd="40dp"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<Button
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btn_verify_recovery_phrase_continue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -94,4 +94,4 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
</ScrollView>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
|
||||
<color name="shield_toggle_button_tint">#5E6175</color>
|
||||
<color name="shield_toggle_bg_color">#F8F9FA</color>
|
||||
|
||||
|
||||
<color name="shield_secondary_color">#868E96</color>
|
||||
<color name="shield_divider_color">#c8c7cc</color>
|
||||
<color name="shield_option_text_color">#777777</color>
|
||||
@@ -154,10 +154,11 @@
|
||||
<color name="recovery_phrase_warning_text_color">#868E96</color>
|
||||
<color name="brave_action_color">#4C54D2</color>
|
||||
<color name="wallet_positive_trend_color">#51CF66</color>
|
||||
<color name="wallet_negative_trend_color">#CF5159</color>
|
||||
<color name="wallet_asset_graph_color">#12A378</color>
|
||||
<color name="wallet_top_banner_color">#33E32444</color>
|
||||
<color name="wallet_top_banner_text_color">#FF4B6A</color>
|
||||
|
||||
|
||||
<color name="vpn_callout_bg_color">#381E85</color>
|
||||
<color name="brave_plan_bg">#27155E</color>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user