From af411a61ae62b37565117957fdecdfdbc855b07d Mon Sep 17 00:00:00 2001 From: Harshal Lele Date: Tue, 4 Feb 2020 16:40:57 +0530 Subject: [PATCH] added ability to copy comments on long press --- .../holder/CommentsMiniInfoItemHolder.java | 29 ++++++++++++++++++- app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/content_settings.xml | 6 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) 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 4d94ec392..4b1d1bdae 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,9 +1,16 @@ package org.schabi.newpipe.info_list.holder; -import androidx.appcompat.app.AppCompatActivity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.preference.PreferenceManager; import android.text.util.Linkify; +import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; import org.jsoup.helper.StringUtil; import org.schabi.newpipe.R; @@ -120,6 +127,26 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { itemBuilder.getOnCommentsSelectedListener().selected(item); } }); + + boolean copyCommentOnLongPress = PreferenceManager.getDefaultSharedPreferences( + itemBuilder.getContext()).getBoolean(itemBuilder.getContext().getString(R.string.copy_comment_long_press), + false); + + if(copyCommentOnLongPress){ + + itemView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + + ClipboardManager clipboardManager = (ClipboardManager) itemBuilder.getContext().getSystemService(Context.CLIPBOARD_SERVICE); + clipboardManager.setPrimaryClip(ClipData.newPlainText(null,itemContentView.getText())); + Toast.makeText(itemBuilder.getContext(), R.string.msg_copied, Toast.LENGTH_SHORT).show(); + return true; + + } + }); + + } } private void ellipsize() { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 1a7d61dae..90edd0ef8 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -159,6 +159,7 @@ show_play_with_kodi show_next_video show_comments + copy_comment_long_press stream_info_selected_tab show_hold_to_append en diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dab9bde10..ca5a7527f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,6 +76,7 @@ Load thumbnails Show comments Disable to stop showing comments + Copy comment on long press Turn off to prevent loading thumbnails, saving data and memory usage. Changes clear both in-memory and on-disk image cache. Image cache wiped Wipe cached metadata diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 197c14487..d1080bb4d 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -65,6 +65,12 @@ android:title="@string/show_comments_title" android:summary="@string/show_comments_summary"/> + +