Commit 22cb4a0c authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[SharingHub] Show different copy options for link, text, and link+text.

Bug: 1129670, 1120093
Change-Id: I8b48d2c3ff9fda7fc347219f40deed60b9dd206d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426481
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811839}
parent fc68ec09
......@@ -106,6 +106,7 @@ class ChromeProvidedSharingOptionsProvider {
*/
private static class FirstPartyOption {
final Collection<Integer> mContentTypes;
final Collection<Integer> mContentTypesToDisableFor;
final PropertyModel mPropertyModel;
final boolean mDisableForMultiWindow;
......@@ -115,12 +116,14 @@ class ChromeProvidedSharingOptionsProvider {
*
* @param model Property model for the first party option.
* @param contentTypes Content types to trigger for.
* @param contentTypesToDisableFor Content types to disable for.
* @param disableForMultiWindow If the feature should be disabled if in multi-window mode.
*/
FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes,
boolean disableForMultiWindow) {
Collection<Integer> contentTypesToDisableFor, boolean disableForMultiWindow) {
mPropertyModel = model;
mContentTypes = contentTypes;
mContentTypesToDisableFor = contentTypesToDisableFor;
mDisableForMultiWindow = disableForMultiWindow;
}
}
......@@ -131,10 +134,12 @@ class ChromeProvidedSharingOptionsProvider {
private String mFeatureNameForMetrics;
private Callback<View> mOnClickCallback;
private boolean mDisableForMultiWindow;
private Integer[] mContentTypesToDisableFor;
private final Integer[] mContentTypesInBuilder;
FirstPartyOptionBuilder(Integer... contentTypes) {
mContentTypesInBuilder = contentTypes;
mContentTypesToDisableFor = new Integer[] {};
}
FirstPartyOptionBuilder setIcon(int icon, int iconLabel) {
......@@ -153,6 +158,11 @@ class ChromeProvidedSharingOptionsProvider {
return this;
}
FirstPartyOptionBuilder setContentTypesToDisableFor(Integer... contentTypesToDisableFor) {
mContentTypesToDisableFor = contentTypesToDisableFor;
return this;
}
FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) {
mDisableForMultiWindow = disableForMultiWindow;
return this;
......@@ -167,8 +177,8 @@ class ChromeProvidedSharingOptionsProvider {
mBottomSheetController.hideContent(mBottomSheetContent, true);
mOnClickCallback.onResult(view);
});
return new FirstPartyOption(
model, Arrays.asList(mContentTypesInBuilder), mDisableForMultiWindow);
return new FirstPartyOption(model, Arrays.asList(mContentTypesInBuilder),
Arrays.asList(mContentTypesToDisableFor), mDisableForMultiWindow);
}
}
......@@ -184,6 +194,8 @@ class ChromeProvidedSharingOptionsProvider {
List<PropertyModel> propertyModels = new ArrayList<>();
for (FirstPartyOption firstPartyOption : mOrderedFirstPartyOptions) {
if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)
&& Collections.disjoint(
contentTypes, firstPartyOption.mContentTypesToDisableFor)
&& !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) {
propertyModels.add(firstPartyOption.mPropertyModel);
}
......@@ -202,8 +214,7 @@ class ChromeProvidedSharingOptionsProvider {
mOrderedFirstPartyOptions.add(createCopyLinkFirstPartyOption());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) {
mOrderedFirstPartyOptions.add(createCopyImageFirstPartyOption());
}
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) {
mOrderedFirstPartyOptions.add(createCopyFirstPartyOption());
mOrderedFirstPartyOptions.add(createCopyTextFirstPartyOption());
}
mOrderedFirstPartyOptions.add(createSendTabToSelfFirstPartyOption());
......@@ -252,12 +263,14 @@ class ChromeProvidedSharingOptionsProvider {
return new FirstPartyOption(propertyModel,
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT,
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE),
/*contentTypesToDisableFor=*/Collections.emptySet(),
/*disableForMultiWindow=*/true);
}
private FirstPartyOption createCopyLinkFirstPartyOption() {
return new FirstPartyOptionBuilder(
ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE)
.setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_url)
.setFeatureNameForMetrics("SharingHubAndroid.CopyURLSelected")
.setOnClickCallback((view) -> {
......@@ -283,8 +296,23 @@ class ChromeProvidedSharingOptionsProvider {
.build();
}
private FirstPartyOption createCopyFirstPartyOption() {
return new FirstPartyOptionBuilder(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy)
.setFeatureNameForMetrics("SharingHubAndroid.CopySelected")
.setOnClickCallback((view) -> {
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(
Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(
mShareParams.getTitle(), mShareParams.getTextAndUrl()));
Toast.makeText(mActivity, R.string.sharing_copied, Toast.LENGTH_SHORT).show();
})
.build();
}
private FirstPartyOption createCopyTextFirstPartyOption() {
return new FirstPartyOptionBuilder(ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT)
.setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_text)
.setFeatureNameForMetrics("SharingHubAndroid.CopyTextSelected")
.setOnClickCallback((view) -> {
......
......@@ -45,15 +45,17 @@ import java.util.Set;
// TODO(crbug/1022172): Should be package-protected once modularization is complete.
public class ShareSheetPropertyModelBuilder {
@IntDef({ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT,
ContentType.IMAGE, ContentType.HIGHLIGHTED_TEXT, ContentType.OTHER_FILE_TYPE})
ContentType.HIGHLIGHTED_TEXT, ContentType.LINK_AND_TEXT, ContentType.IMAGE,
ContentType.OTHER_FILE_TYPE})
@Retention(RetentionPolicy.SOURCE)
@interface ContentType {
int LINK_PAGE_VISIBLE = 0;
int LINK_PAGE_NOT_VISIBLE = 1;
int TEXT = 2;
int IMAGE = 3;
int HIGHLIGHTED_TEXT = 4;
int OTHER_FILE_TYPE = 5;
int HIGHLIGHTED_TEXT = 3;
int LINK_AND_TEXT = 4;
int IMAGE = 5;
int OTHER_FILE_TYPE = 6;
}
private static final int MAX_NUM_APPS = 7;
......@@ -61,9 +63,10 @@ public class ShareSheetPropertyModelBuilder {
// Variations parameter name for the comma-separated list of third-party activity names.
private static final String PARAM_SHARING_HUB_THIRD_PARTY_APPS = "sharing-hub-third-party-apps";
static final HashSet<Integer> ALL_CONTENT_TYPES = new HashSet<>(Arrays.asList(
ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT,
ContentType.IMAGE, ContentType.HIGHLIGHTED_TEXT, ContentType.OTHER_FILE_TYPE));
static final HashSet<Integer> ALL_CONTENT_TYPES = new HashSet<>(
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE,
ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT, ContentType.LINK_AND_TEXT,
ContentType.IMAGE, ContentType.OTHER_FILE_TYPE));
private static final ArrayList<String> FALLBACK_ACTIVITIES =
new ArrayList<>(Arrays.asList("com.whatsapp.ContactPicker",
"com.facebook.composer.shareintent.ImplicitShareIntentHandlerDefaultAlias",
......@@ -126,6 +129,9 @@ public class ShareSheetPropertyModelBuilder {
contentTypes.add(ContentType.TEXT);
}
}
if (!TextUtils.isEmpty(params.getUrl()) && !TextUtils.isEmpty(params.getText())) {
contentTypes.add(ContentType.LINK_AND_TEXT);
}
if (params.getFileUris() != null) {
if (!TextUtils.isEmpty(params.getFileContentType())
&& params.getFileContentType().startsWith(IMAGE_TYPE)) {
......
......@@ -246,7 +246,7 @@ public final class ShareSheetPropertyModelBuilderTest {
assertEquals("Should contain correct content types.",
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.OTHER_FILE_TYPE,
ContentType.TEXT),
ContentType.TEXT, ContentType.LINK_AND_TEXT),
ShareSheetPropertyModelBuilder.getContentTypes(shareParams, shareExtras));
}
......
......@@ -3978,6 +3978,10 @@ In Incognito, your activity might still be visible to websites that you visit, y
More
</message>
<message name="IDS_SHARING_COPY" desc="Label for the Copy button in the sharing hub.">
Copy
</message>
<message name="IDS_SHARING_COPY_URL" desc="Label for the Copy URL button in the sharing hub.">
Copy link
</message>
......@@ -3998,6 +4002,10 @@ In Incognito, your activity might still be visible to websites that you visit, y
Link to text
</message>
<message name="IDS_SHARING_COPIED" desc="Text shown in the toast notification when Copy is selected in the sharing hub.">
Copied
</message>
<message name="IDS_TEXT_COPIED" desc="Text shown in the toast notification when Copy Text is selected in the sharing hub.">
Text Copied
</message>
......
ab18934f0393bc4dfa4f5af5efcd9e5ac764b925
\ No newline at end of file
3a225761ad2cb4bc0b102138b69946d67ec6671d
\ 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