Skip to content

Commit

Permalink
Revert "[PriceTracking] Add PriceAlertsMessageCard component"
Browse files Browse the repository at this point in the history
This reverts commit 7204f8d.

Reason for revert: crbug.com/1194433

Original change's description:
> [PriceTracking] Add PriceAlertsMessageCard component
>
> This change adds a new PriceMessageType PRICE_ALERTS.
> When PriceWelcomeMessageCard (i.e. Price drop spotted card) is
> available, it takes priority over this PriceAlertsMessageCard.
>
> Bug: 1166702
> Change-Id: I7ed8324583d0a7fb578182487f5f7fddf3ee131b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2764707
> Reviewed-by: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
> Reviewed-by: Xing Liu <xingliu@chromium.org>
> Reviewed-by: Mei Liang <meiliang@chromium.org>
> Reviewed-by: Yue Zhang <yuezhanggg@chromium.org>
> Commit-Queue: Zhiyuan Cai <zhiyuancai@google.com>
> Cr-Commit-Position: refs/heads/master@{#867286}

Bug: 1166702, 1194433
Change-Id: I193137336589fcb4d9ce894a1ae3fe5ff945d8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2794948
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Benoit L <lizeb@chromium.org>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Owners-Override: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#868047}
  • Loading branch information
Benoit L authored and Chromium LUCI CQ committed Mar 31, 2021
1 parent 821d0f5 commit 2f881c8
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 577 deletions.
1 change: 0 additions & 1 deletion chrome/android/features/tab_ui/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ include_rules = [
"+chrome/browser/ui/android/theme/java",
"+chrome/browser/ui/android/toolbar/java",
"+chrome/browser/ui/messages/android/java",
"+components/browser_ui/notifications/android",
"+components/browser_ui/styles/android",
"+components/browser_ui/widget/android",
"+components/feature_engagement/public/android/java/src/org/chromium/components/feature_engagement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import static org.chromium.chrome.browser.tasks.tab_management.TabListModel.CardProperties.ModelType.MESSAGE;

import android.content.Context;
import android.graphics.drawable.Drawable;

import androidx.appcompat.content.res.AppCompatResources;

import org.chromium.chrome.browser.price_tracking.PriceDropNotificationManager;
import org.chromium.chrome.browser.tasks.tab_management.PriceMessageService.PriceMessageType;
import org.chromium.chrome.tab_ui.R;
import org.chromium.ui.modelutil.PropertyModel;
Expand All @@ -33,9 +29,9 @@ public static PropertyModel create(Context context,
MessageCardView.DismissActionProvider uiDismissActionProvider,
PriceMessageService.PriceMessageData data) {
boolean isIconVisible = data.getType() == PriceMessageType.PRICE_WELCOME ? false : true;
String titleText = getTitle(context, data.getType());
String descriptionText = getDescription(context, data.getType());
String actionText = getActionText(context, data.getType());
String titleText = context.getString(R.string.price_drop_spotted_title);
String descriptionText = context.getString(R.string.price_drop_spotted_content);
String actionText = context.getString(R.string.price_drop_spotted_show_me);
String dismissButtonContextDescription =
context.getString(R.string.accessibility_tab_suggestion_dismiss_button);

Expand All @@ -57,52 +53,8 @@ public static PropertyModel create(Context context,
.with(MessageCardViewProperties.IS_INCOGNITO, false)
.with(MessageCardViewProperties.TITLE_TEXT, titleText)
.with(MessageCardViewProperties.PRICE_DROP, data.getPriceDrop())
.with(MessageCardViewProperties.ICON_PROVIDER,
() -> getIconDrawable(context, data.getType()))
.with(CARD_TYPE, MESSAGE)
.with(CARD_ALPHA, 1f)
.build();
}

private static String getTitle(Context context, @PriceMessageType int type) {
if (type == PriceMessageType.PRICE_WELCOME) {
return context.getString(R.string.price_drop_spotted_title);
} else if (type == PriceMessageType.PRICE_ALERTS) {
return context.getString(R.string.price_drop_alerts_card_title);
}
return null;
}

private static String getDescription(Context context, @PriceMessageType int type) {
if (type == PriceMessageType.PRICE_WELCOME) {
return context.getString(R.string.price_drop_spotted_content);
} else if (type == PriceMessageType.PRICE_ALERTS) {
if ((new PriceDropNotificationManager()).areAppNotificationsEnabled()) {
return context.getString(R.string.price_drop_alerts_card_get_notified_content);
} else {
return context.getString(R.string.price_drop_alerts_card_go_to_settings_content);
}
}
return null;
}

private static String getActionText(Context context, @PriceMessageType int type) {
if (type == PriceMessageType.PRICE_WELCOME) {
return context.getString(R.string.price_drop_spotted_show_me);
} else if (type == PriceMessageType.PRICE_ALERTS) {
if ((new PriceDropNotificationManager()).areAppNotificationsEnabled()) {
return context.getString(R.string.price_drop_alerts_card_get_notified);
} else {
return context.getString(R.string.price_drop_alerts_card_go_to_settings);
}
}
return null;
}

private static Drawable getIconDrawable(Context context, @PriceMessageType int type) {
if (type == PriceMessageType.PRICE_ALERTS) {
return AppCompatResources.getDrawable(context, R.drawable.ic_add_alert_blue);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.chromium.chrome.browser.price_tracking.PriceDropNotificationManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.state.ShoppingPersistedTabData;

Expand All @@ -19,15 +18,10 @@
* One of the concrete {@link MessageService} that only serves {@link MessageType#PRICE_MESSAGE}.
*/
public class PriceMessageService extends MessageService {
// PRICE_WELCOME and PRICE_ALERTS are added to {@link TabListModel} at a different time and the
// insertion positions are different as well. Right now PRICE_WELCOME is added via {@link
// TabSwitcherCoordinator#appendNextMessage}, while PRICE_ALERTS is added via {@link
// TabSwitcherCoordinator#appendMessagesTo}.
@IntDef({PriceMessageType.PRICE_WELCOME, PriceMessageType.PRICE_ALERTS})
@IntDef({PriceMessageType.PRICE_WELCOME})
@Retention(RetentionPolicy.SOURCE)
public @interface PriceMessageType {
int PRICE_WELCOME = 0;
int PRICE_ALERTS = 1;
}

/**
Expand Down Expand Up @@ -153,46 +147,32 @@ MessageCardView.DismissActionProvider getDismissActionProvider() {

private final PriceWelcomeMessageProvider mPriceWelcomeMessageProvider;
private final PriceWelcomeMessageReviewActionProvider mPriceWelcomeMessageReviewActionProvider;
private final PriceDropNotificationManager mNotificationManager;

private PriceTabData mPriceTabData;

PriceMessageService(PriceWelcomeMessageProvider priceWelcomeMessageProvider,
PriceWelcomeMessageReviewActionProvider priceWelcomeMessageReviewActionProvider,
PriceDropNotificationManager notificationManager) {
PriceWelcomeMessageReviewActionProvider priceWelcomeMessageReviewActionProvider) {
super(MessageType.PRICE_MESSAGE);
mPriceTabData = null;
mPriceWelcomeMessageProvider = priceWelcomeMessageProvider;
mPriceWelcomeMessageReviewActionProvider = priceWelcomeMessageReviewActionProvider;
mNotificationManager = notificationManager;
}

void preparePriceMessage(@PriceMessageType int type, @Nullable PriceTabData priceTabData) {
assert (type == PriceMessageType.PRICE_WELCOME
&& PriceTrackingUtilities.isPriceWelcomeMessageCardEnabled())
|| (type == PriceMessageType.PRICE_ALERTS
&& PriceTrackingUtilities.isPriceAlertsMessageCardEnabled());
assert type == PriceMessageType.PRICE_WELCOME
&& PriceTrackingUtilities.isPriceWelcomeMessageCardEnabled();
// To avoid the confusion of different-type stale messages, invalidateMessage every time
// before preparing new messages.
invalidateMessage();
mPriceTabData = priceTabData;
sendAvailabilityNotification(new PriceMessageData(
type, mPriceTabData, () -> review(type), (int messageType) -> dismiss(type)));
if (type == PriceMessageType.PRICE_WELCOME) {
// When PriceWelcomeMessageCard is available, it takes priority over
// PriceAlertsMessageCard.
PriceTrackingUtilities.decreasePriceAlertsMessageCardShowCount();
PriceTrackingUtilities.increasePriceWelcomeMessageCardShowCount();
if (PriceTrackingUtilities.getPriceWelcomeMessageCardShowCount()
>= MAX_PRICE_MESSAGE_SHOW_COUNT * PREPARE_MESSAGE_TIMES_ENTERING_TAB_SWITCHER) {
PriceTrackingUtilities.disablePriceWelcomeMessageCard();
}
} else if (type == PriceMessageType.PRICE_ALERTS) {
PriceTrackingUtilities.increasePriceAlertsMessageCardShowCount();
if (PriceTrackingUtilities.getPriceAlertsMessageCardShowCount()
>= MAX_PRICE_MESSAGE_SHOW_COUNT * PREPARE_MESSAGE_TIMES_ENTERING_TAB_SWITCHER) {
PriceTrackingUtilities.disablePriceAlertsMessageCard();
}
}
}

Expand All @@ -216,13 +196,6 @@ public void review(@PriceMessageType int type) {
mPriceWelcomeMessageProvider.showPriceDropTooltip(bindingTabIndex);
PriceTrackingUtilities.disablePriceWelcomeMessageCard();
mPriceTabData = null;
} else if (type == PriceMessageType.PRICE_ALERTS) {
if (mNotificationManager.areAppNotificationsEnabled()) {
mNotificationManager.createNotificationChannel();
} else {
mNotificationManager.launchNotificationSettings();
}
PriceTrackingUtilities.disablePriceAlertsMessageCard();
}
}

Expand All @@ -231,8 +204,6 @@ public void dismiss(@PriceMessageType int type) {
if (type == PriceMessageType.PRICE_WELCOME) {
PriceTrackingUtilities.disablePriceWelcomeMessageCard();
mPriceTabData = null;
} else if (type == PriceMessageType.PRICE_ALERTS) {
PriceTrackingUtilities.disablePriceAlertsMessageCard();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.price_tracking.PriceDropNotificationManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.services.UnifiedConsentServiceBridge;
Expand All @@ -31,12 +30,6 @@ public class PriceTrackingUtilities {
@VisibleForTesting
public static final String PRICE_WELCOME_MESSAGE_CARD_SHOW_COUNT =
ChromePreferenceKeys.PRICE_TRACKING_PRICE_WELCOME_MESSAGE_CARD_SHOW_COUNT;
@VisibleForTesting
public static final String PRICE_ALERTS_MESSAGE_CARD =
ChromePreferenceKeys.PRICE_TRACKING_PRICE_ALERTS_MESSAGE_CARD;
@VisibleForTesting
public static final String PRICE_ALERTS_MESSAGE_CARD_SHOW_COUNT =
ChromePreferenceKeys.PRICE_TRACKING_PRICE_ALERTS_MESSAGE_CARD_SHOW_COUNT;

@VisibleForTesting
public static final SharedPreferencesManager SHARED_PREFERENCES_MANAGER =
Expand Down Expand Up @@ -107,49 +100,6 @@ public static int getPriceWelcomeMessageCardShowCount() {
return SHARED_PREFERENCES_MANAGER.readInt(PRICE_WELCOME_MESSAGE_CARD_SHOW_COUNT, 0);
}

/**
* Forbid showing the PriceAlertsMessageCard any more.
*/
public static void disablePriceAlertsMessageCard() {
SHARED_PREFERENCES_MANAGER.writeBoolean(PRICE_ALERTS_MESSAGE_CARD, false);
}

/**
* @return Whether the PriceAlertsMessageCard is enabled. We don't show this message card if
* user can already receive price drop notifications, see {@link
* PriceDropNotificationManager#canPostNotification()}.
*/
public static boolean isPriceAlertsMessageCardEnabled() {
return isPriceTrackingEligible()
&& SHARED_PREFERENCES_MANAGER.readBoolean(
PRICE_ALERTS_MESSAGE_CARD, TabUiFeatureUtilities.isPriceTrackingEnabled())
&& (!(new PriceDropNotificationManager()).canPostNotification());
}

/**
* Increase the show count of PriceAlertsMessageCard every time it shows in the tab switcher.
*/
public static void increasePriceAlertsMessageCardShowCount() {
SHARED_PREFERENCES_MANAGER.writeInt(
PRICE_ALERTS_MESSAGE_CARD_SHOW_COUNT, getPriceAlertsMessageCardShowCount() + 1);
}

/**
* Decrease the show count of PriceAlertsMessageCard. Right now it is used to correct the show
* count when PriceAlertsMessageCard is deprioritized by PriceWelcomeMessageCard.
*/
public static void decreasePriceAlertsMessageCardShowCount() {
SHARED_PREFERENCES_MANAGER.writeInt(
PRICE_ALERTS_MESSAGE_CARD_SHOW_COUNT, getPriceAlertsMessageCardShowCount() - 1);
}

/**
* @return The show count of PriceAlertsMessageCard.
*/
public static int getPriceAlertsMessageCardShowCount() {
return SHARED_PREFERENCES_MANAGER.readInt(PRICE_ALERTS_MESSAGE_CARD_SHOW_COUNT, 0);
}

private static boolean isSignedIn() {
return IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ public void initWithNative(Context context, TabContentManager tabContentManager,
new PriceDropNotificationManager();
mPriceTrackingDialogCoordinator = new PriceTrackingDialogCoordinator(
context, modalDialogManager, this, mTabModelSelector, notificationManager);
mPriceMessageService = new PriceMessageService(
mTabListCoordinator, mMediator, notificationManager);
mPriceMessageService = new PriceMessageService(mTabListCoordinator, mMediator);
mMessageCardProviderCoordinator.subscribeMessageService(mPriceMessageService);
mMediator.setPriceMessageService(mPriceMessageService);
}
Expand Down Expand Up @@ -481,10 +480,6 @@ public boolean resetWithTabs(
}

if (tabs != null && tabs.size() > 0) {
if (mPriceMessageService != null
&& PriceTrackingUtilities.isPriceAlertsMessageCardEnabled()) {
mPriceMessageService.preparePriceMessage(PriceMessageType.PRICE_ALERTS, null);
}
appendMessagesTo(cardsCount);
}

Expand Down Expand Up @@ -546,13 +541,9 @@ private void appendMessagesTo(int index) {
List<MessageCardProviderMediator.Message> messages =
mMessageCardProviderCoordinator.getMessageItems();
for (int i = 0; i < messages.size(); i++) {
if (messages.get(i).type == MessageService.MessageType.PRICE_MESSAGE) {
mTabListCoordinator.addSpecialListItem(
index, TabProperties.UiType.LARGE_MESSAGE, messages.get(i).model);
} else {
mTabListCoordinator.addSpecialListItem(
index, TabProperties.UiType.MESSAGE, messages.get(i).model);
}
if (messages.get(i).type == MessageService.MessageType.PRICE_MESSAGE) continue;
mTabListCoordinator.addSpecialListItem(
index, TabProperties.UiType.MESSAGE, messages.get(i).model);
index++;
}
if (messages.size() > 0) sAppendedMessagesForTesting = true;
Expand Down

0 comments on commit 2f881c8

Please sign in to comment.