Added button to copy link to clipboard

pull/172/head
M66B 5 years ago
parent 5cf290f5eb
commit 3c995ec3d8

@ -27,6 +27,8 @@ import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
@ -4627,7 +4629,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Uri uri = getArguments().getParcelable("uri");
String title = getArguments().getString("title");
final String title = getArguments().getString("title");
final Uri sanitized;
if (uri.isOpaque())
@ -4652,6 +4654,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_open_link, null);
TextView tvTitle = dview.findViewById(R.id.tvTitle);
ImageButton ibCopy = dview.findViewById(R.id.ibCopy);
final EditText etLink = dview.findViewById(R.id.etLink);
TextView tvDifferent = dview.findViewById(R.id.tvDifferent);
final CheckBox cbSecure = dview.findViewById(R.id.cbSecure);
@ -4663,6 +4666,20 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final TextView tvOwner = dview.findViewById(R.id.tvOwner);
final Group grpOwner = dview.findViewById(R.id.grpOwner);
ibCopy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard =
(ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText(title, uri.toString());
clipboard.setPrimaryClip(clip);
ToastEx.makeText(getContext(), R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
}
}
});
etLink.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,18l2,1V3c0,-1.1 -0.9,-2 -2,-2H8.99C7.89,1 7,1.9 7,3h10c1.1,0 2,0.9 2,2v13zM15,5H5c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3V7c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

@ -30,6 +30,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<ImageButton
android:id="@+id/ibCopy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_clipboard_copy"
app:layout_constraintBottom_toBottomOf="@id/tvTitle"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/baseline_bookmarks_24" />
<EditText
android:id="@+id/etLink"
android:layout_width="0dp"

@ -1013,6 +1013,8 @@
<string name="title_enabled">Enabled</string>
<string name="title_executing">Executing</string>
<string name="title_completed">Completed</string>
<string name="title_clipboard_copy">Copy to clipboard</string>
<string name="title_clipboard_copied">Copied to clipboard</string>
<string name="title_ask_what">Ask what to do</string>
<string name="title_no_ask_again">Do not ask this again</string>
<string name="title_no_ask_for_again">Do not ask this again for %1$s</string>

Loading…
Cancel
Save