diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 36e7a206c44..fff689930cd 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -479,7 +479,6 @@ public boolean onLongClick(final View v) { case R.id.detail_controls_download: NavigationHelper.openDownloads(getActivity()); break; - case R.id.detail_uploader_root_layout: if (TextUtils.isEmpty(currentInfo.getSubChannelUrl())) { Log.w(TAG, @@ -488,6 +487,9 @@ public boolean onLongClick(final View v) { openChannel(currentInfo.getUploaderUrl(), currentInfo.getUploaderName()); } break; + case R.id.detail_title_root_layout: + ShareUtils.copyToClipboard(getContext(), videoTitleTextView.getText().toString()); + break; } return true; @@ -583,6 +585,7 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) { protected void initListeners() { super.initListeners(); + videoTitleRoot.setOnLongClickListener(this); uploaderRootLayout.setOnClickListener(this); uploaderRootLayout.setOnLongClickListener(this); videoTitleRoot.setOnClickListener(this); diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index 69f08f340dc..863273a88e8 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -1,15 +1,11 @@ package org.schabi.newpipe.info_list.holder; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; import android.text.TextUtils; import android.text.method.LinkMovementMethod; import android.text.style.URLSpan; import android.text.util.Linkify; import android.view.ViewGroup; import android.widget.TextView; -import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -24,6 +20,7 @@ import org.schabi.newpipe.util.ImageDisplayConstants; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; +import org.schabi.newpipe.util.ShareUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -129,14 +126,10 @@ public void updateFromItem(final InfoItem infoItem, itemView.setOnLongClickListener(view -> { - if (!AndroidTvUtils.isTv(itemBuilder.getContext())) { - ClipboardManager clipboardManager = (ClipboardManager) itemBuilder.getContext() - .getSystemService(Context.CLIPBOARD_SERVICE); - clipboardManager.setPrimaryClip(ClipData.newPlainText(null, commentText)); - Toast.makeText(itemBuilder.getContext(), R.string.msg_copied, Toast.LENGTH_SHORT) - .show(); - } else { + if (AndroidTvUtils.isTv(itemBuilder.getContext())) { openCommentAuthor(item); + } else { + ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText); } return true; }); diff --git a/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java b/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java index 0bf731a989b..0ec2d571db9 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java @@ -1,10 +1,13 @@ package org.schabi.newpipe.util; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; +import android.widget.Toast; import org.schabi.newpipe.R; @@ -78,4 +81,27 @@ public static void shareUrl(final Context context, final String subject, final S context.startActivity(Intent.createChooser( intent, context.getString(R.string.share_dialog_title))); } + + /** + * Copy the text to clipboard, and indicate to the user whether the operation was completed + * successfully using a Toast. + * + * @param context the context to use + * @param text the text to copy + */ + public static void copyToClipboard(final Context context, final String text) { + final ClipboardManager clipboardManager = + (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + + if (clipboardManager == null) { + Toast.makeText(context, + R.string.permission_denied, + Toast.LENGTH_LONG).show(); + return; + } + + clipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); + Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT) + .show(); + } }