Commit ca43517b authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[SharingHub] Apply standard tint to 1P sharing features

Apply the standard mode tint to first party sharing features in the
sharing hub. This ensures they display correctly in dark mode.

Bug: 1009124
Change-Id: I9e3fd8f8fc59853ce0d46ebc512d85d5cfdf6f64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020404
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736078}
parent dc4d746b
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.share;
import android.content.Context;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
......@@ -15,6 +16,8 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.ui.modelutil.MVCListAdapter.ListItem;
......@@ -91,6 +94,12 @@ public class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemC
view.setText(model.get(ShareSheetItemViewProperties.LABEL));
} else if (ShareSheetItemViewProperties.CLICK_LISTENER.equals(propertyKey)) {
parent.setOnClickListener(model.get(ShareSheetItemViewProperties.CLICK_LISTENER));
} else if (ShareSheetItemViewProperties.IS_FIRST_PARTY.equals(propertyKey)) {
if (!model.get(ShareSheetItemViewProperties.IS_FIRST_PARTY)) return;
ImageView view = (ImageView) parent.findViewById(R.id.icon);
ApiCompatibilityUtils.setImageTintList(view,
AppCompatResources.getColorStateList(
ContextUtils.getApplicationContext(), R.color.standard_mode_tint));
}
}
......
......@@ -77,12 +77,14 @@ public class ShareSheetCoordinator {
PropertyModel qrcodePropertyModel = mPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(activity, R.drawable.qr_code),
activity.getResources().getString(R.string.qr_code_share_icon_label),
(currentActivity) -> {
(currentActivity)
-> {
mBottomSheetController.hideContent(bottomSheet, true);
QrCodeCoordinator qrCodeCoordinator =
new QrCodeCoordinator(activity, this::createNewTab);
qrCodeCoordinator.show();
});
},
/*isFirstParty=*/true);
models.add(qrcodePropertyModel);
// Send Tab To Self
......@@ -92,7 +94,8 @@ public class ShareSheetCoordinator {
AppCompatResources.getDrawable(activity, R.drawable.send_tab),
activity.getResources().getString(
R.string.send_tab_to_self_share_activity_title),
(shareParams) -> {
(shareParams)
-> {
mBottomSheetController.hideContent(bottomSheet, true);
SendTabToSelfShareActivity.actionHandler(activity,
mActivityTabProvider.get()
......@@ -100,7 +103,8 @@ public class ShareSheetCoordinator {
.getNavigationController()
.getVisibleEntry(),
mBottomSheetController);
});
},
/*isFirstParty=*/true);
models.add(sttsPropertyModel);
// Copy URL
......@@ -118,26 +122,23 @@ public class ShareSheetCoordinator {
Toast toast =
Toast.makeText(activity, R.string.link_copied, Toast.LENGTH_SHORT);
toast.show();
});
}, /*isFirstParty=*/true);
models.add(copyPropertyModel);
// ScreenShot
PropertyModel screenshotPropertyModel = null;
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_SCREENSHOT)) {
screenshotPropertyModel =
new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS)
.with(ShareSheetItemViewProperties.ICON,
AppCompatResources.getDrawable(activity, R.drawable.screenshot))
.with(ShareSheetItemViewProperties.LABEL,
activity.getResources().getString(R.string.sharing_screenshot))
.with(ShareSheetItemViewProperties.CLICK_LISTENER,
(shareParams) -> {
mBottomSheetController.hideContent(bottomSheet, true);
ScreenshotCoordinator screenshotCoordinator =
new ScreenshotCoordinator(activity);
screenshotCoordinator.takeScreenshot();
})
.build();
screenshotPropertyModel = mPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(activity, R.drawable.screenshot),
activity.getResources().getString(R.string.sharing_screenshot),
(shareParams)
-> {
mBottomSheetController.hideContent(bottomSheet, true);
ScreenshotCoordinator screenshotCoordinator =
new ScreenshotCoordinator(activity);
screenshotCoordinator.takeScreenshot();
},
/*isFirstParty=*/true);
models.add(screenshotPropertyModel);
}
......@@ -153,10 +154,12 @@ public class ShareSheetCoordinator {
PropertyModel morePropertyModel = mPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(activity, R.drawable.sharing_more),
activity.getResources().getString(R.string.sharing_more_icon_label),
(shareParams) -> {
(shareParams)
-> {
mBottomSheetController.hideContent(bottomSheet, true);
ShareHelper.showDefaultShareUi(params);
});
},
/*isFirstParty=*/true);
models.add(morePropertyModel);
return models;
......
......@@ -22,5 +22,9 @@ final class ShareSheetItemViewProperties {
public static final WritableObjectPropertyKey<OnClickListener> CLICK_LISTENER =
new WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_KEYS = {ICON, LABEL, CLICK_LISTENER};
/** True if this share sheet item is provided by Chrome. **/
public static final WritableObjectPropertyKey<Boolean> IS_FIRST_PARTY =
new WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_KEYS = {ICON, LABEL, CLICK_LISTENER, IS_FIRST_PARTY};
}
......@@ -65,19 +65,20 @@ class ShareSheetPropertyModelBuilder {
}
mBottomSheetController.hideContent(bottomSheet, true);
ShareHelper.makeIntentAndShare(params, component);
});
}, /*isFirstParty=*/false);
models.add(propertyModel);
}
return models;
}
protected PropertyModel createPropertyModel(
Drawable icon, String label, OnClickListener listener) {
Drawable icon, String label, OnClickListener listener, boolean isFirstParty) {
PropertyModel propertyModel =
new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS)
.with(ShareSheetItemViewProperties.ICON, icon)
.with(ShareSheetItemViewProperties.LABEL, label)
.with(ShareSheetItemViewProperties.CLICK_LISTENER, listener)
.with(ShareSheetItemViewProperties.IS_FIRST_PARTY, isFirstParty)
.build();
return propertyModel;
}
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.share;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import android.app.Activity;
import android.support.test.filters.MediumTest;
......@@ -55,18 +56,20 @@ public final class ShareSheetCoordinatorTest {
.with(ShareSheetItemViewProperties.ICON, null)
.with(ShareSheetItemViewProperties.LABEL, "testModel1")
.with(ShareSheetItemViewProperties.CLICK_LISTENER, null)
.with(ShareSheetItemViewProperties.IS_FIRST_PARTY, false)
.build();
PropertyModel testModel2 = new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS)
.with(ShareSheetItemViewProperties.ICON, null)
.with(ShareSheetItemViewProperties.LABEL, "testModel2")
.with(ShareSheetItemViewProperties.CLICK_LISTENER, null)
.with(ShareSheetItemViewProperties.IS_FIRST_PARTY, false)
.build();
mThirdPartyPropertyModels =
new ArrayList<PropertyModel>(Arrays.asList(testModel1, testModel2));
Mockito.when(mPropertyModelBuilder.selectThirdPartyApps(any(), any(), any()))
.thenReturn(mThirdPartyPropertyModels);
Mockito.when(mPropertyModelBuilder.createPropertyModel(any(), any(), any()))
Mockito.when(mPropertyModelBuilder.createPropertyModel(any(), any(), any(), anyBoolean()))
.thenCallRealMethod();
}
......@@ -86,12 +89,18 @@ public final class ShareSheetCoordinatorTest {
Assert.assertEquals("First property model isn't QR Code.",
activity.getResources().getString(R.string.qr_code_share_icon_label),
propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("First property model isn't marked as first party.", true,
propertyModels.get(0).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Second property model isn't SendTabToSelf.",
activity.getResources().getString(R.string.send_tab_to_self_share_activity_title),
propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Second property model isn't marked as first party.", true,
propertyModels.get(1).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Third property model isn't Copy URL.",
activity.getResources().getString(R.string.sharing_copy_url),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Third property model isn't marked as first party.", true,
propertyModels.get(2).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
}
@Test
......@@ -109,15 +118,23 @@ public final class ShareSheetCoordinatorTest {
Assert.assertEquals("First property model isn't QR Code.",
activity.getResources().getString(R.string.qr_code_share_icon_label),
propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("First property model isn't marked as first party.", true,
propertyModels.get(0).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Second property model isn't SendTabToSelf.",
activity.getResources().getString(R.string.send_tab_to_self_share_activity_title),
propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Second property model isn't marked as first party.", true,
propertyModels.get(1).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Third property model isn't Copy URL.",
activity.getResources().getString(R.string.sharing_copy_url),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Third property model isn't marked as first party.", true,
propertyModels.get(2).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Fourth property model isn't Screenshotz.",
activity.getResources().getString(R.string.sharing_screenshot),
propertyModels.get(3).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Fourth property model isn't marked as first party.", true,
propertyModels.get(3).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
}
@Test
......@@ -133,10 +150,16 @@ public final class ShareSheetCoordinatorTest {
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
Assert.assertEquals("First property model isn't testModel1.", "testModel1",
propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("First property model is marked as first party.", false,
propertyModels.get(0).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Second property model isn't testModel2.", "testModel2",
propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Second property model is marked as first party.", false,
propertyModels.get(1).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
Assert.assertEquals("Third property model isn't More.",
activity.getResources().getString(R.string.sharing_more_icon_label),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
Assert.assertEquals("Thired property model isn't marked as first party.", true,
propertyModels.get(2).get(ShareSheetItemViewProperties.IS_FIRST_PARTY));
}
}
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