Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.util.ArrayList;
import java.util.function.Predicate;
Expand Down Expand Up @@ -88,22 +87,26 @@ 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_new_window_1), 0, () -> {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_window_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewWindow(aContextElement.linkUri);
}
onDismiss();
}));
}
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> {
// 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 @@ -112,42 +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;
}
// 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();
}));
}
// 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();
}));
}
if (URLUtil.isNetworkUrl(aContextElement.linkUri) || URLUtil.isNetworkUrl(aContextElement.srcUri)) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
// 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 @@ -174,4 +201,8 @@ public void setContextElement(ContextElement aContextElement) {
mWidgetPlacement.height += 10.0f; // Link separator
}

private void addClipboardClip(ContextElement aContextElement) {

}

}
24 changes: 24 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,21 @@
<!-- 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_new_tab_1">Open in a new tab</string>

<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the target url in a new window. -->
<string name="context_menu_open_link_new_window_1">Open link in a new window</string>

<!-- 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 @@ -1272,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