Skip to content

Commit f2d1f7d

Browse files
JustwengJustwengnicolas-raoul
authored
[Enhancement] Fix #5042 Add copy link button (#5080)
* Add a "copy link" button next to the share button. Add relative English and Simplified Chinese text in strings.xml. * Change the icon from copy to link * Fixed typo * Fixed case --------- Co-authored-by: Justweng <justweng19@gmail.com> Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 235e8cd commit f2d1f7d

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import fr.free.nrw.commons.CommonsApplication;
3232
import fr.free.nrw.commons.Media;
3333
import fr.free.nrw.commons.R;
34+
import fr.free.nrw.commons.Utils;
3435
import fr.free.nrw.commons.auth.SessionManager;
3536
import fr.free.nrw.commons.bookmarks.models.Bookmark;
3637
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
@@ -211,6 +212,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
211212
snackbar.show();
212213
updateBookmarkState(item);
213214
return true;
215+
case R.id.menu_copy_link:
216+
String uri = m.getPageTitle().getCanonicalUri();
217+
Utils.copy("shareLink", uri, requireContext());
218+
Timber.d("Copied share link to clipboard: %s", uri);
219+
Toast.makeText(requireContext(), getString(R.string.menu_link_copied),
220+
Toast.LENGTH_SHORT).show();
221+
return true;
214222
case R.id.menu_share_current_image:
215223
Intent shareIntent = new Intent(Intent.ACTION_SEND);
216224
shareIntent.setType("text/plain");
@@ -390,6 +398,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
390398
if (m != null) {
391399
// Enable default set of actions, then re-enable different set of actions only if it is a failed contrib
392400
menu.findItem(R.id.menu_browser_current_image).setEnabled(true).setVisible(true);
401+
menu.findItem(R.id.menu_copy_link).setEnabled(true).setVisible(true);
393402
menu.findItem(R.id.menu_share_current_image).setEnabled(true).setVisible(true);
394403
menu.findItem(R.id.menu_download_current_image).setEnabled(true).setVisible(true);
395404
menu.findItem(R.id.menu_bookmark_current_image).setEnabled(true).setVisible(true);
@@ -423,6 +432,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
423432
case Contribution.STATE_QUEUED:
424433
menu.findItem(R.id.menu_browser_current_image).setEnabled(false)
425434
.setVisible(false);
435+
menu.findItem(R.id.menu_copy_link).setEnabled(false)
436+
.setVisible(false);
426437
menu.findItem(R.id.menu_share_current_image).setEnabled(false)
427438
.setVisible(false);
428439
menu.findItem(R.id.menu_download_current_image).setEnabled(false)
@@ -440,6 +451,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
440451
} else {
441452
menu.findItem(R.id.menu_browser_current_image).setEnabled(false)
442453
.setVisible(false);
454+
menu.findItem(R.id.menu_copy_link).setEnabled(false)
455+
.setVisible(false);
443456
menu.findItem(R.id.menu_share_current_image).setEnabled(false)
444457
.setVisible(false);
445458
menu.findItem(R.id.menu_download_current_image).setEnabled(false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:height="24dp"
3+
android:viewportHeight="24"
4+
android:viewportWidth="24"
5+
android:width="24dp" >
6+
<path android:fillColor="?attr/notification_icon_text_color" android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
7+
</vector>

app/src/main/res/menu/fragment_image_detail.xml

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
android:icon="@drawable/menu_ic_round_star_border_24px"
88
android:title="@string/menu_bookmark"
99
app:showAsAction="always" />
10+
<item
11+
android:id="@+id/menu_copy_link"
12+
android:icon="@drawable/menu_ic_copy_link_24dp"
13+
android:title="@string/menu_copy_link"
14+
app:showAsAction="always" />
1015
<item
1116
android:id="@+id/menu_share_current_image"
1217
android:icon="@drawable/menu_ic_share_24dp"

app/src/main/res/values-zh-rCN/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<string name="menu_from_gallery">从图库</string>
3131
<string name="menu_from_camera">拍照</string>
3232
<string name="provider_contributions">我的上传</string>
33+
<string name="menu_copy_link">复制链接</string>
34+
<string name="menu_link_copied">链接已复制到剪贴板</string>
3335
<string name="menu_share">分享</string>
3436
<string name="menu_open_in_browser">在浏览器中查看</string>
3537
<string name="share_title_hint">标题</string>

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

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
<string name="menu_from_camera">Take photo</string>
100100
<string name="menu_nearby">Nearby</string>
101101
<string name="provider_contributions">My uploads</string>
102+
<string name="menu_copy_link">Copy link</string>
103+
<string name="menu_link_copied">The link has been copied to the clipboard</string>
102104
<string name="menu_share">Share</string>
103105
<string name="menu_view_file_page">View file page</string>
104106
<string name="share_title_hint">Caption (Required)</string>

0 commit comments

Comments
 (0)