Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit c9ac120

Browse files
committed
Rebase fixes
1 parent aa656a0 commit c9ac120

2 files changed

Lines changed: 78 additions & 52 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/ContextMenuWidget.java

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public void setContextElement(ContextElement aContextElement) {
8787
mItems = new ArrayList<>();
8888
final WidgetManagerDelegate widgetManager = mWidgetManager;
8989
if (aContextElement.linkUri != null && !aContextElement.linkUri.isEmpty()) {
90+
// Link url
9091
mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null));
92+
// Open link in a new window
9193
if (mWidgetManager.canOpenNewWindow()) {
9294
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_window_1), 0, () -> {
9395
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
@@ -96,13 +98,15 @@ public void setContextElement(ContextElement aContextElement) {
9698
onDismiss();
9799
}));
98100
}
101+
// Open link in a new tab
99102
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_tab_1), 0, () -> {
100103
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
101104
widgetManager.openNewTab(aContextElement.linkUri);
102105
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
103106
}
104107
onDismiss();
105108
}));
109+
// Download link
106110
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
107111
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> {
108112
DownloadJob job = DownloadJob.fromLink(aContextElement);
@@ -111,66 +115,66 @@ public void setContextElement(ContextElement aContextElement) {
111115
onDismiss();
112116
}));
113117
}
118+
// Copy link uri
119+
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
120+
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
121+
Uri uri = Uri.parse(aContextElement.linkUri);
122+
if (uri != null) {
123+
String label = aContextElement.title;
124+
if (StringUtils.isEmpty(label)) {
125+
label = aContextElement.altText;
126+
}
127+
if (StringUtils.isEmpty(label)) {
128+
label = aContextElement.altText;
129+
}
130+
if (StringUtils.isEmpty(label)) {
131+
label = uri.toString();
132+
}
133+
ClipData clip = ClipData.newRawUri(label, uri);
134+
if (clipboard != null) {
135+
clipboard.setPrimaryClip(clip);
136+
}
137+
}
138+
onDismiss();
139+
}));
140+
114141
} else {
142+
// If there is no link, show src uri instead
115143
mItems.add(new MenuWidget.MenuItem(aContextElement.srcUri, 0, null));
116144
}
117-
if (URLUtil.isNetworkUrl(aContextElement.srcUri)) {
118-
@StringRes int srcText;
119-
switch (aContextElement.type) {
120-
case ContextElement.TYPE_IMAGE:
121-
srcText = R.string.context_menu_download_image;
122-
break;
123-
case ContextElement.TYPE_VIDEO:
124-
srcText = R.string.context_menu_download_video;
125-
break;
126-
case ContextElement.TYPE_AUDIO:
127-
srcText = R.string.context_menu_download_audio;
128-
break;
129-
default:
130-
srcText = R.string.context_menu_download_link;
131-
break;
145+
146+
if (URLUtil.isNetworkUrl(aContextElement.srcUri) && aContextElement.type != ContextElement.TYPE_NONE) {
147+
@StringRes int copyText = R.string.context_menu_copy_image_location;
148+
@StringRes int srcText = R.string.context_menu_download_image;
149+
@StringRes int viewText = R.string.context_menu_view_image;
150+
if (aContextElement.type == ContextElement.TYPE_VIDEO) {
151+
srcText = R.string.context_menu_download_video;
152+
copyText = R.string.context_menu_copy_video_location;
153+
viewText = R.string.context_menu_view_video;
154+
155+
} else if(aContextElement.type == ContextElement.TYPE_AUDIO) {
156+
srcText = R.string.context_menu_download_audio;
157+
copyText = R.string.context_menu_copy_audio_location;
158+
viewText = R.string.context_menu_view_audio;
132159
}
133-
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> {
134-
if (!StringUtils.isEmpty(aContextElement.srcUri)) {
135-
widgetManager.openNewTab(aContextElement.srcUri);
136-
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
137-
}
138-
onDismiss();
139-
}));
140-
if (URLUtil.isHttpUrl(aContextElement.srcUri) || URLUtil.isHttpsUrl(aContextElement.srcUri)) {
141-
@StringRes int srcText;
142-
switch (aContextElement.type) {
143-
case ContextElement.TYPE_IMAGE:
144-
srcText = R.string.context_menu_download_image;
145-
break;
146-
case ContextElement.TYPE_VIDEO:
147-
srcText = R.string.context_menu_download_video;
148-
break;
149-
case ContextElement.TYPE_AUDIO:
150-
srcText = R.string.context_menu_download_audio;
151-
break;
152-
default:
153-
srcText = R.string.context_menu_download_link;
154-
break;
155-
}
156-
mItems.add(new MenuWidget.MenuItem(getContext().getString(srcText), 0, () -> {
157-
DownloadJob job = DownloadJob.fromSrc(aContextElement);
158-
widgetManager.getFocusedWindow().startDownload(job, false);
159-
// TODO Add Download from context menu Telemetry
160+
// View src
161+
if (aContextElement.baseUri != null && !aContextElement.baseUri.equals(aContextElement.srcUri)) {
162+
mItems.add(new MenuWidget.MenuItem(getContext().getString(viewText), 0, () -> {
163+
widgetManager.getFocusedWindow().getSession().loadUri(aContextElement.srcUri);
160164
onDismiss();
161165
}));
162166
}
163-
}
164-
if (URLUtil.isNetworkUrl(aContextElement.linkUri) || URLUtil.isNetworkUrl(aContextElement.srcUri)) {
165-
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
167+
// Download src
168+
mItems.add(new MenuWidget.MenuItem(getContext().getString(srcText), 0, () -> {
169+
DownloadJob job = DownloadJob.fromSrc(aContextElement);
170+
widgetManager.getFocusedWindow().startDownload(job, false);
171+
// TODO Add Download from context menu Telemetry
172+
onDismiss();
173+
}));
174+
// Copy src uri
175+
mItems.add(new MenuWidget.MenuItem(getContext().getString(copyText), 0, () -> {
166176
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
167-
Uri uri;
168-
if (aContextElement.linkUri != null) {
169-
uri = Uri.parse(aContextElement.linkUri);
170-
171-
} else {
172-
uri = Uri.parse(aContextElement.srcUri);
173-
}
177+
Uri uri = Uri.parse(aContextElement.srcUri);
174178
if (uri != null) {
175179
String label = aContextElement.title;
176180
if (StringUtils.isEmpty(label)) {
@@ -197,4 +201,8 @@ public void setContextElement(ContextElement aContextElement) {
197201
mWidgetPlacement.height += 10.0f; // Link separator
198202
}
199203

204+
private void addClipboardClip(ContextElement aContextElement) {
205+
206+
}
207+
200208
}

app/src/main/res/values/strings.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,15 @@
12631263
<!-- 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. -->
12641264
<string name="context_menu_open_link_new_tab_1">Open link in a new tab</string>
12651265

1266+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the image in the current window. -->
1267+
<string name="context_menu_view_image">View image</string>
1268+
1269+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the video in the current window. -->
1270+
<string name="context_menu_view_video">View video</string>
1271+
1272+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it opens the audio in the current window. -->
1273+
<string name="context_menu_view_audio">View audio</string>
1274+
12661275
<!-- This string is shown in the context menu after a longpress on a link. When clicked it triggers a linked element download. -->
12671276
<string name="context_menu_download_link">Download Link</string>
12681277

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

1290+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the image uri to the clipboard -->
1291+
<string name="context_menu_copy_image_location">Copy image location</string>
1292+
1293+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the video uri to the clipboard -->
1294+
<string name="context_menu_copy_video_location">Copy video location</string>
1295+
1296+
<!-- This string is shown in the context menu after a longpress on a link. When clicked it copies the audio uri to the clipboard -->
1297+
<string name="context_menu_copy_audio_location">Copy audio location</string>
1298+
12811299
<!-- 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. -->
12821300
<string name="context_menu_cut_text">Cut</string>
12831301

0 commit comments

Comments
 (0)