From e34f666b70f49a89f5b3b89dff84513233e519de Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Wed, 10 Jun 2020 14:11:06 -0700 Subject: [PATCH 1/6] set an OnLongClickListener --- .../newpipe/fragments/detail/VideoDetailFragment.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 36e7a206c..95d8008c6 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 class VideoDetailFragment extends BaseStateFragment 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 openChannel(currentInfo.getUploaderUrl(), currentInfo.getUploaderName()); } break; + case R.id.detail_title_root_layout: + copyTitleText(); + break; } return true; @@ -583,6 +585,9 @@ public class VideoDetailFragment extends BaseStateFragment protected void initListeners() { super.initListeners(); + videoTitleRoot.setLongClickable(true); + videoTitleRoot.setOnLongClickListener(this); + uploaderRootLayout.setOnClickListener(this); uploaderRootLayout.setOnLongClickListener(this); videoTitleRoot.setOnClickListener(this); @@ -1422,4 +1427,8 @@ public class VideoDetailFragment extends BaseStateFragment animateView(detailPositionView, false, 500); }); } + + private void copyTitleText() { + + } } From b5375396d27ec72baf448dc7733f2e5c32a2b38b Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Wed, 10 Jun 2020 14:17:43 -0700 Subject: [PATCH 2/6] allowed user to copy video title to clipboard (from detail screen) --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 95d8008c6..a8b007bf4 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 @@ -105,6 +105,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import us.shandian.giga.util.Utility; import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS; import static org.schabi.newpipe.extractor.stream.StreamExtractor.NO_AGE_LIMIT; @@ -1429,6 +1430,6 @@ public class VideoDetailFragment extends BaseStateFragment } private void copyTitleText() { - + Utility.copyToClipboard(getContext(), videoTitleTextView.getText().toString()); } } From 267e114354ba2d1ee210cfa2d3526665b5470469 Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Wed, 10 Jun 2020 15:14:08 -0700 Subject: [PATCH 3/6] added a copyToClipboard method to ShareUtils, and modified CommentsMiniInfoItemHolder and VideoDetailFragment to use the new method. --- .../fragments/detail/VideoDetailFragment.java | 7 +---- .../holder/CommentsMiniInfoItemHolder.java | 11 ++------ .../org/schabi/newpipe/util/ShareUtils.java | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) 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 a8b007bf4..44f18a4ea 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 @@ -105,7 +105,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import us.shandian.giga.util.Utility; import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS; import static org.schabi.newpipe.extractor.stream.StreamExtractor.NO_AGE_LIMIT; @@ -489,7 +488,7 @@ public class VideoDetailFragment extends BaseStateFragment } break; case R.id.detail_title_root_layout: - copyTitleText(); + ShareUtils.copyToClipboard(getContext(), videoTitleTextView.getText().toString()); break; } @@ -1428,8 +1427,4 @@ public class VideoDetailFragment extends BaseStateFragment animateView(detailPositionView, false, 500); }); } - - private void copyTitleText() { - Utility.copyToClipboard(getContext(), videoTitleTextView.getText().toString()); - } } 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 69f08f340..d94762c4d 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.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; @@ -130,11 +127,7 @@ 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(); + ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText); } else { openCommentAuthor(item); } 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 0bf731a98..1b87f4f14 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 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) { + 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(); + } } From 0d29e66092ed363266211455a78948508fc22e77 Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Thu, 11 Jun 2020 09:33:05 -0700 Subject: [PATCH 4/6] removed unnecessary setLongClickable --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 2 -- 1 file changed, 2 deletions(-) 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 44f18a4ea..fff689930 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 @@ -585,9 +585,7 @@ public class VideoDetailFragment extends BaseStateFragment protected void initListeners() { super.initListeners(); - videoTitleRoot.setLongClickable(true); videoTitleRoot.setOnLongClickListener(this); - uploaderRootLayout.setOnClickListener(this); uploaderRootLayout.setOnLongClickListener(this); videoTitleRoot.setOnClickListener(this); From 59e0c10c4299742f99bee43a478aca36393a57f1 Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Thu, 11 Jun 2020 09:36:05 -0700 Subject: [PATCH 5/6] inverted if-else statement --- .../info_list/holder/CommentsMiniInfoItemHolder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 d94762c4d..863273a88 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 @@ -126,10 +126,10 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { itemView.setOnLongClickListener(view -> { - if (!AndroidTvUtils.isTv(itemBuilder.getContext())) { - ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText); - } else { + if (AndroidTvUtils.isTv(itemBuilder.getContext())) { openCommentAuthor(item); + } else { + ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText); } return true; }); From 17d1346a8a2fc31e0d35f991194c7097fe2b0c22 Mon Sep 17 00:00:00 2001 From: adinilfeld Date: Thu, 11 Jun 2020 09:36:57 -0700 Subject: [PATCH 6/6] made ClipboardManager final --- app/src/main/java/org/schabi/newpipe/util/ShareUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1b87f4f14..0ec2d571d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/ShareUtils.java @@ -90,7 +90,7 @@ public final class ShareUtils { * @param text the text to copy */ public static void copyToClipboard(final Context context, final String text) { - ClipboardManager clipboardManager = + final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager == null) {