Skip to content

Commit

Permalink
[bookmarks] Replace #setTextColor with a text style set in XML
Browse files Browse the repository at this point in the history
Bug: 1424445
Change-Id: I96597100e03d22b896753ffdb7ec981aa99c7266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4337762
Reviewed-by: Sky Malice <skym@chromium.org>
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1123702}
  • Loading branch information
Brandon Wylie authored and Chromium LUCI CQ committed Mar 29, 2023
1 parent 1eabd93 commit 501d2da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions chrome/android/java/res/layout/compact_price_drop_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary" />
<TextView
android:id="@+id/price_drop_primary_text"
android:id="@+id/price_drop_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary"
android:textAppearance="@style/TextAppearance.ShoppingPriceDropText"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/price_drop_secondary_text"
android:id="@+id/original_price_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary" />
Expand Down
5 changes: 5 additions & 0 deletions chrome/android/java/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,9 @@ found in the LICENSE file.
<style name="NotificationBlockedDialogContent" parent="AlertDialogContent">
<item name="android:paddingBottom">12dp</item>
</style>

<!-- Bookmark styles -->
<style name="TextAppearance.ShoppingPriceDropText" parent="TextAppearance.TextMedium.Secondary">
<item name="android:textColor">@color/price_drop_annotation_text_green</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ public class PowerBookmarkShoppingItemRow extends BookmarkItemRow {
// Allows subclasses to add special views below the description (e.g. the price for shopping).
protected FrameLayout mCustomTextContainer;
private ImageView mPriceTrackingButton;
// Used for when there's no price drop.
private TextView mNormalPriceText;
private TextView mPriceDropPrimaryText;
private TextView mPriceDropSecondaryText;
// Used for the new price when there's a price drop.
private TextView mPriceDropText;
// Used for the original price when there's a price drop.
private TextView mOriginalPriceText;

// Dependencies.
private ImageFetcher mImageFetcher;
Expand Down Expand Up @@ -93,8 +96,8 @@ protected void onFinishInflate() {
LayoutInflater.from(getContext())
.inflate(R.layout.compact_price_drop_view, mCustomTextContainer);
mNormalPriceText = findViewById(R.id.normal_price_text);
mPriceDropPrimaryText = findViewById(R.id.price_drop_primary_text);
mPriceDropSecondaryText = findViewById(R.id.price_drop_secondary_text);
mPriceDropText = findViewById(R.id.price_drop_text);
mOriginalPriceText = findViewById(R.id.original_price_text);
}

/**
Expand Down Expand Up @@ -178,22 +181,21 @@ private void setPriceInfoChip(long originalPrice, long currentPrice) {
if (originalPrice <= currentPrice) {
mNormalPriceText.setText(formattedCurrentPrice);
mNormalPriceText.setVisibility(View.VISIBLE);
mPriceDropPrimaryText.setVisibility(View.GONE);
mPriceDropSecondaryText.setVisibility(View.GONE);
mPriceDropText.setVisibility(View.GONE);
mOriginalPriceText.setVisibility(View.GONE);
} else {
assignPriceDropProperties(mPriceDropPrimaryText, mPriceDropSecondaryText,
assignPriceDropProperties(mPriceDropText, mOriginalPriceText,
getFormattedCurrencyStringForPrice(originalPrice), formattedCurrentPrice);
mNormalPriceText.setVisibility(View.GONE);
mPriceDropPrimaryText.setVisibility(View.VISIBLE);
mPriceDropSecondaryText.setVisibility(View.VISIBLE);
mPriceDropText.setVisibility(View.VISIBLE);
mOriginalPriceText.setVisibility(View.VISIBLE);
}
}

private void assignPriceDropProperties(TextView primaryText, TextView secondaryText,
String formattedOriginalPrice, String formattedCurrentPrice) {
// Primary text displays the current price.
primaryText.setText(formattedCurrentPrice);
primaryText.setTextColor(getContext().getColor(R.color.price_drop_annotation_text_green));

// Secondary text displays the original price with a strikethrough.
secondaryText.setText(formattedOriginalPrice);
Expand Down

0 comments on commit 501d2da

Please sign in to comment.