From 6960d725a39ad06eb1bb3ba3e8cd1b1961fb2e0e Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Thu, 1 Nov 2018 15:13:37 +0100 Subject: [PATCH] Add menu item to copy media link (#895) --- .../java/com/keylesspalace/tusky/ViewMediaActivity.kt | 8 ++++++++ app/src/main/res/menu/view_media_toolbar.xml | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt index 1498ad799..c8faab4ff 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt @@ -19,6 +19,8 @@ import android.Manifest import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.app.DownloadManager +import android.content.ClipData +import android.content.ClipboardManager import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -143,6 +145,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener R.id.action_download -> downloadMedia() R.id.action_open_status -> onOpenStatus() R.id.action_share_media -> shareMedia() + R.id.action_copy_media_link -> copyLink() } true } @@ -224,6 +227,11 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener startActivityWithSlideInAnimation(ViewThreadActivity.startIntent(this, attach.statusId, attach.statusUrl)) } + private fun copyLink() { + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + clipboard.primaryClip = ClipData.newPlainText(null, attachments!![viewPager.currentItem].attachment.url) + } + private fun shareMedia() { val directory = applicationContext.getExternalFilesDir("Tusky") if (directory == null || !(directory.exists())) { diff --git a/app/src/main/res/menu/view_media_toolbar.xml b/app/src/main/res/menu/view_media_toolbar.xml index 90d013f6b..eda21650c 100644 --- a/app/src/main/res/menu/view_media_toolbar.xml +++ b/app/src/main/res/menu/view_media_toolbar.xml @@ -11,6 +11,10 @@ android:icon="@drawable/ic_menu_share_24dp" android:title="@string/action_share" app:showAsAction="ifRoom" /> +