Skip to content

Commit

Permalink
Rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed May 29, 2020
1 parent aa656a0 commit c9ac120
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public void setContextElement(ContextElement aContextElement) {
mItems = new ArrayList<>();
final WidgetManagerDelegate widgetManager = mWidgetManager;
if (aContextElement.linkUri != null && !aContextElement.linkUri.isEmpty()) {
// Link url
mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null));
// Open link in a new window
if (mWidgetManager.canOpenNewWindow()) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_window_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
Expand All @@ -96,13 +98,15 @@ public void setContextElement(ContextElement aContextElement) {
onDismiss();
}));
}
// Open link in a new tab
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_tab_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewTab(aContextElement.linkUri);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
}
onDismiss();
}));
// Download link
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> {
DownloadJob job = DownloadJob.fromLink(aContextElement);
Expand All @@ -111,66 +115,66 @@ public void setContextElement(ContextElement aContextElement) {
onDismiss();
}));
}
// Copy link uri
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
Uri uri = Uri.parse(aContextElement.linkUri);
if (uri != null) {
String label = aContextElement.title;
if (StringUtils.isEmpty(label)) {
label = aContextElement.altText;
}
if (StringUtils.isEmpty(label)) {
label = aContextElement.altText;
}
if (StringUtils.isEmpty(label)) {
label = uri.toString();
}
ClipData clip = ClipData.newRawUri(label, uri);
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
}
}
onDismiss();
}));

} else {
// If there is no link, show src uri instead
mItems.add(new MenuWidget.MenuItem(aContextElement.srcUri, 0, null));
}
if (URLUtil.isNetworkUrl(aContextElement.srcUri)) {
@StringRes int srcText;
switch (aContextElement.type) {
case ContextElement.TYPE_IMAGE:
srcText = R.string.context_menu_download_image;
break;
case ContextElement.TYPE_VIDEO:
srcText = R.string.context_menu_download_video;
break;
case ContextElement.TYPE_AUDIO:
srcText = R.string.context_menu_download_audio;
break;
default:
srcText = R.string.context_menu_download_link;
break;

if (URLUtil.isNetworkUrl(aContextElement.srcUri) && aContextElement.type != ContextElement.TYPE_NONE) {
@StringRes int copyText = R.string.context_menu_copy_image_location;
@StringRes int srcText = R.string.context_menu_download_image;
@StringRes int viewText = R.string.context_menu_view_image;
if (aContextElement.type == ContextElement.TYPE_VIDEO) {
srcText = R.string.context_menu_download_video;
copyText = R.string.context_menu_copy_video_location;
viewText = R.string.context_menu_view_video;

} else if(aContextElement.type == ContextElement.TYPE_AUDIO) {
srcText = R.string.context_menu_download_audio;
copyText = R.string.context_menu_copy_audio_location;
viewText = R.string.context_menu_view_audio;
}
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.srcUri)) {
widgetManager.openNewTab(aContextElement.srcUri);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
}
onDismiss();
}));
if (URLUtil.isHttpUrl(aContextElement.srcUri) || URLUtil.isHttpsUrl(aContextElement.srcUri)) {
@StringRes int srcText;
switch (aContextElement.type) {
case ContextElement.TYPE_IMAGE:
srcText = R.string.context_menu_download_image;
break;
case ContextElement.TYPE_VIDEO:
srcText = R.string.context_menu_download_video;
break;
case ContextElement.TYPE_AUDIO:
srcText = R.string.context_menu_download_audio;
break;
default:
srcText = R.string.context_menu_download_link;
break;
}
mItems.add(new MenuWidget.MenuItem(getContext().getString(srcText), 0, () -> {
DownloadJob job = DownloadJob.fromSrc(aContextElement);
widgetManager.getFocusedWindow().startDownload(job, false);
// TODO Add Download from context menu Telemetry
// View src
if (aContextElement.baseUri != null && !aContextElement.baseUri.equals(aContextElement.srcUri)) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(viewText), 0, () -> {
widgetManager.getFocusedWindow().getSession().loadUri(aContextElement.srcUri);
onDismiss();
}));
}
}
if (URLUtil.isNetworkUrl(aContextElement.linkUri) || URLUtil.isNetworkUrl(aContextElement.srcUri)) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
// Download src
mItems.add(new MenuWidget.MenuItem(getContext().getString(srcText), 0, () -> {
DownloadJob job = DownloadJob.fromSrc(aContextElement);
widgetManager.getFocusedWindow().startDownload(job, false);
// TODO Add Download from context menu Telemetry
onDismiss();
}));
// Copy src uri
mItems.add(new MenuWidget.MenuItem(getContext().getString(copyText), 0, () -> {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
Uri uri;
if (aContextElement.linkUri != null) {
uri = Uri.parse(aContextElement.linkUri);

} else {
uri = Uri.parse(aContextElement.srcUri);
}
Uri uri = Uri.parse(aContextElement.srcUri);
if (uri != null) {
String label = aContextElement.title;
if (StringUtils.isEmpty(label)) {
Expand All @@ -197,4 +201,8 @@ public void setContextElement(ContextElement aContextElement) {
mWidgetPlacement.height += 10.0f; // Link separator
}

private void addClipboardClip(ContextElement aContextElement) {

}

}
18 changes: 18 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,15 @@
<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the target url in a new tab. -->
<string name="context_menu_open_link_new_tab_1">Open link in a new tab</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the image in the current window. -->
<string name="context_menu_view_image">View image</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the video in the current window. -->
<string name="context_menu_view_video">View video</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the audio in the current window. -->
<string name="context_menu_view_audio">View audio</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it triggers a linked element download. -->
<string name="context_menu_download_link">Download Link</string>

Expand All @@ -1278,6 +1287,15 @@
<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the target to the clipboard -->
<string name="context_menu_copy_link">Copy link</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the image uri to the clipboard -->
<string name="context_menu_copy_image_location">Copy image location</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the video uri to the clipboard -->
<string name="context_menu_copy_video_location">Copy video location</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the audio uri to the clipboard -->
<string name="context_menu_copy_audio_location">Copy audio location</string>

<!-- This string is shown in the context menu after a longpress on a text. When clicked it cuts the selected text and can be pasted later. -->
<string name="context_menu_cut_text">Cut</string>

Expand Down

0 comments on commit c9ac120

Please sign in to comment.