[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)