Commit 47934344 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Remove icon for message card item if not needed

Bug: 1050443
Change-Id: I093021c8763df8d4d1978fb0bf249391d9e74aa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2092116Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarMei Liang <meiliang@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748784}
parent c245a507
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<dimen name="tab_grid_close_button_size">18dp</dimen> <dimen name="tab_grid_close_button_size">18dp</dimen>
<dimen name="tab_grid_dialog_side_margin">16dp</dimen> <dimen name="tab_grid_dialog_side_margin">16dp</dimen>
<dimen name="tab_grid_dialog_top_margin">85dp</dimen> <dimen name="tab_grid_dialog_top_margin">85dp</dimen>
<dimen name="tab_grid_iph_item_description_margin">16dp</dimen>
<dimen name="tab_grid_iph_dialog_height">430dp</dimen> <dimen name="tab_grid_iph_dialog_height">430dp</dimen>
<dimen name="tab_grid_iph_dialog_top_margin">24dp</dimen> <dimen name="tab_grid_iph_dialog_top_margin">24dp</dimen>
<dimen name="tab_grid_iph_dialog_side_margin">12dp</dimen> <dimen name="tab_grid_iph_dialog_side_margin">12dp</dimen>
......
...@@ -43,10 +43,12 @@ public class IphMessageCardViewModel { ...@@ -43,10 +43,12 @@ public class IphMessageCardViewModel {
.with(MessageCardViewProperties.MESSAGE_SERVICE_ACTION_PROVIDER, .with(MessageCardViewProperties.MESSAGE_SERVICE_ACTION_PROVIDER,
data.getReviewActionProvider()) data.getReviewActionProvider())
.with(MessageCardViewProperties.DESCRIPTION_TEXT, descriptionText) .with(MessageCardViewProperties.DESCRIPTION_TEXT, descriptionText)
.with(MessageCardViewProperties.DESCRIPTION_TEXT_TEMPLATE, null)
.with(MessageCardViewProperties.ACTION_TEXT, actionText) .with(MessageCardViewProperties.ACTION_TEXT, actionText)
.with(MessageCardViewProperties.DISMISS_BUTTON_CONTENT_DESCRIPTION, .with(MessageCardViewProperties.DISMISS_BUTTON_CONTENT_DESCRIPTION,
dismissButtonContextDescription) dismissButtonContextDescription)
.with(MessageCardViewProperties.SHOULD_KEEP_AFTER_REVIEW, true) .with(MessageCardViewProperties.SHOULD_KEEP_AFTER_REVIEW, true)
.with(MessageCardViewProperties.IS_ICON_VISIBLE, false)
.with(CARD_TYPE, MESSAGE) .with(CARD_TYPE, MESSAGE)
.with(CARD_ALPHA, 1f) .with(CARD_ALPHA, 1f)
.build(); .build();
......
...@@ -124,4 +124,24 @@ class MessageCardView extends LinearLayout { ...@@ -124,4 +124,24 @@ class MessageCardView extends LinearLayout {
void setDismissButtonOnClickListener(OnClickListener listener) { void setDismissButtonOnClickListener(OnClickListener listener) {
mCloseButton.setOnClickListener(listener); mCloseButton.setOnClickListener(listener);
} }
/**
* Modify the view based on the visibility of the icon. For messages that doesn't have an icon,
* remove the icon and update the margin of the description text field.
* @param visible Whether icon is visible.
*/
void setIconVisibility(boolean visible) {
MarginLayoutParams params = (MarginLayoutParams) mDescription.getLayoutParams();
if (visible) {
if (indexOfChild(mIcon) == -1) {
addView(mIcon, 0);
params.setMargins(0, 0, 0, 0);
}
} else {
int margin = (int) getContext().getResources().getDimension(
R.dimen.tab_grid_iph_item_description_margin);
removeView(mIcon);
params.setMargins(margin, 0, 0, 0);
}
}
} }
...@@ -59,6 +59,8 @@ class MessageCardViewBinder { ...@@ -59,6 +59,8 @@ class MessageCardViewBinder {
}); });
} else if (CARD_ALPHA == propertyKey) { } else if (CARD_ALPHA == propertyKey) {
itemView.setAlpha(model.get(CARD_ALPHA)); itemView.setAlpha(model.get(CARD_ALPHA));
} else if (MessageCardViewProperties.IS_ICON_VISIBLE == propertyKey) {
itemView.setIconVisibility(model.get(MessageCardViewProperties.IS_ICON_VISIBLE));
} }
} }
} }
...@@ -40,10 +40,12 @@ class MessageCardViewProperties { ...@@ -40,10 +40,12 @@ class MessageCardViewProperties {
new PropertyModel.WritableObjectPropertyKey<>(); new PropertyModel.WritableObjectPropertyKey<>();
public static final PropertyModel.WritableBooleanPropertyKey SHOULD_KEEP_AFTER_REVIEW = public static final PropertyModel.WritableBooleanPropertyKey SHOULD_KEEP_AFTER_REVIEW =
new PropertyModel.WritableBooleanPropertyKey(); new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_ICON_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ACTION_TEXT, DESCRIPTION_TEXT, public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ACTION_TEXT, DESCRIPTION_TEXT,
DESCRIPTION_TEXT_TEMPLATE, MESSAGE_TYPE, ICON_PROVIDER, UI_ACTION_PROVIDER, DESCRIPTION_TEXT_TEMPLATE, MESSAGE_TYPE, ICON_PROVIDER, UI_ACTION_PROVIDER,
UI_DISMISS_ACTION_PROVIDER, MESSAGE_SERVICE_ACTION_PROVIDER, UI_DISMISS_ACTION_PROVIDER, MESSAGE_SERVICE_ACTION_PROVIDER,
MESSAGE_SERVICE_DISMISS_ACTION_PROVIDER, DISMISS_BUTTON_CONTENT_DESCRIPTION, MESSAGE_SERVICE_DISMISS_ACTION_PROVIDER, DISMISS_BUTTON_CONTENT_DESCRIPTION,
SHOULD_KEEP_AFTER_REVIEW, CARD_TYPE, CARD_ALPHA}; SHOULD_KEEP_AFTER_REVIEW, IS_ICON_VISIBLE, CARD_TYPE, CARD_ALPHA};
} }
...@@ -52,6 +52,7 @@ public class TabSuggestionMessageCardViewModel { ...@@ -52,6 +52,7 @@ public class TabSuggestionMessageCardViewModel {
.with(MessageCardViewProperties.ACTION_TEXT, actionText) .with(MessageCardViewProperties.ACTION_TEXT, actionText)
.with(MessageCardViewProperties.DISMISS_BUTTON_CONTENT_DESCRIPTION, .with(MessageCardViewProperties.DISMISS_BUTTON_CONTENT_DESCRIPTION,
dismissButtonContextDescription) dismissButtonContextDescription)
.with(MessageCardViewProperties.IS_ICON_VISIBLE, true)
.with(CARD_TYPE, MESSAGE) .with(CARD_TYPE, MESSAGE)
.with(CARD_ALPHA, 1f) .with(CARD_ALPHA, 1f)
.build(); .build();
......
...@@ -143,6 +143,26 @@ public class MessageCardViewBinderTest extends DummyUiActivityTestCase { ...@@ -143,6 +143,26 @@ public class MessageCardViewBinderTest extends DummyUiActivityTestCase {
assertTrue(mMessageServiceDismissCallbackRan.get()); assertTrue(mMessageServiceDismissCallbackRan.get());
} }
@Test
@UiThreadTest
@SmallTest
public void testSetIconVisibility() {
int margin = (int) getActivity().getResources().getDimension(
R.dimen.tab_grid_iph_item_description_margin);
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams) mItemView.findViewById(R.id.description)
.getLayoutParams();
assertEquals(4, mItemView.getChildCount());
mItemViewModel.set(MessageCardViewProperties.IS_ICON_VISIBLE, false);
assertEquals(3, mItemView.getChildCount());
assertEquals(margin, params.leftMargin);
mItemViewModel.set(MessageCardViewProperties.IS_ICON_VISIBLE, true);
assertEquals(4, mItemView.getChildCount());
assertEquals(0, params.leftMargin);
}
@Override @Override
public void tearDownTest() throws Exception { public void tearDownTest() throws Exception {
mItemMCP.destroy(); mItemMCP.destroy();
......
3658acf6c513bbd6bb721e35d0e9f1ed2fd5f9a8 e158cb32f3405770a0f235c3f7ce8a8d772fa38a
\ No newline at end of file \ No newline at end of file
236e00bcc45cb47de9cca93e29a8e4d9b7475f50 d1a26778191711bc6aff75749618ed3da0f6c902
\ No newline at end of file \ No newline at end of file
5687e3199646a34e553b9c2f8c1338caaea9a515 19d8227dfe1cd90013b5a4111151fc3c0c17b3b3
\ No newline at end of file \ No newline at end of file
4b993838cf4c79cce3bf08914041d1a7bc4f3e00 2fae37606db1ebd39c323457ce734bdf58ef0bd9
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment