added a copyToClipboard method to ShareUtils, and modified CommentsMiniInfoItemHolder and VideoDetailFragment to use the new method.

This commit is contained in:
adinilfeld 2020-06-10 15:14:08 -07:00
parent b5375396d2
commit 267e114354
3 changed files with 29 additions and 15 deletions

View File

@ -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<StreamInfo>
}
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<StreamInfo>
animateView(detailPositionView, false, 500);
});
}
private void copyTitleText() {
Utility.copyToClipboard(getContext(), videoTitleTextView.getText().toString());
}
}

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;
@ -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);
}

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) {
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();
}
}