[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>
This commit is contained in:
Haoyu Weng 2024-12-14 17:45:44 +08:00 committed by GitHub
parent 235e8cdba2
commit f2d1f7dbbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 0 deletions

View file

@ -31,6 +31,7 @@ import com.google.android.material.snackbar.Snackbar;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.bookmarks.models.Bookmark;
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
@ -211,6 +212,13 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
snackbar.show();
updateBookmarkState(item);
return true;
case R.id.menu_copy_link:
String uri = m.getPageTitle().getCanonicalUri();
Utils.copy("shareLink", uri, requireContext());
Timber.d("Copied share link to clipboard: %s", uri);
Toast.makeText(requireContext(), getString(R.string.menu_link_copied),
Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_share_current_image:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
@ -390,6 +398,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
if (m != null) {
// Enable default set of actions, then re-enable different set of actions only if it is a failed contrib
menu.findItem(R.id.menu_browser_current_image).setEnabled(true).setVisible(true);
menu.findItem(R.id.menu_copy_link).setEnabled(true).setVisible(true);
menu.findItem(R.id.menu_share_current_image).setEnabled(true).setVisible(true);
menu.findItem(R.id.menu_download_current_image).setEnabled(true).setVisible(true);
menu.findItem(R.id.menu_bookmark_current_image).setEnabled(true).setVisible(true);
@ -423,6 +432,8 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
case Contribution.STATE_QUEUED:
menu.findItem(R.id.menu_browser_current_image).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_copy_link).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_share_current_image).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_download_current_image).setEnabled(false)
@ -440,6 +451,8 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
} else {
menu.findItem(R.id.menu_browser_current_image).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_copy_link).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_share_current_image).setEnabled(false)
.setVisible(false);
menu.findItem(R.id.menu_download_current_image).setEnabled(false)

View file

@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp" >
<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"/>
</vector>

View file

@ -7,6 +7,11 @@
android:icon="@drawable/menu_ic_round_star_border_24px"
android:title="@string/menu_bookmark"
app:showAsAction="always" />
<item
android:id="@+id/menu_copy_link"
android:icon="@drawable/menu_ic_copy_link_24dp"
android:title="@string/menu_copy_link"
app:showAsAction="always" />
<item
android:id="@+id/menu_share_current_image"
android:icon="@drawable/menu_ic_share_24dp"

View file

@ -30,6 +30,8 @@
<string name="menu_from_gallery">从图库</string>
<string name="menu_from_camera">拍照</string>
<string name="provider_contributions">我的上传</string>
<string name="menu_copy_link">复制链接</string>
<string name="menu_link_copied">链接已复制到剪贴板</string>
<string name="menu_share">分享</string>
<string name="menu_open_in_browser">在浏览器中查看</string>
<string name="share_title_hint">标题</string>

View file

@ -99,6 +99,8 @@
<string name="menu_from_camera">Take photo</string>
<string name="menu_nearby">Nearby</string>
<string name="provider_contributions">My uploads</string>
<string name="menu_copy_link">Copy link</string>
<string name="menu_link_copied">The link has been copied to the clipboard</string>
<string name="menu_share">Share</string>
<string name="menu_view_file_page">View file page</string>
<string name="share_title_hint">Caption (Required)</string>