Merge pull request #3772 from adinilfeld/copy-video-title

Copy video title
This commit is contained in:
Tobias Groza 2020-06-13 16:38:14 +02:00 committed by GitHub
commit 9ef7688f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 12 deletions

View File

@ -479,7 +479,6 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo>
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 class VideoDetailFragment extends BaseStateFragment<StreamInfo>
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 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo>
protected void initListeners() {
super.initListeners();
videoTitleRoot.setOnLongClickListener(this);
uploaderRootLayout.setOnClickListener(this);
uploaderRootLayout.setOnLongClickListener(this);
videoTitleRoot.setOnClickListener(this);

View File

@ -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.CommentTextOnTouchListener;
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 class CommentsMiniInfoItemHolder extends InfoItemHolder {
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;
});

View File

@ -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 final class ShareUtils {
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();
}
}