Add long press option to copy content to clipboard (#135)
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.github.gotify.messages;
|
package com.github.gotify.messages;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -8,6 +10,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@@ -133,6 +136,7 @@ public class ListMessageAdapter extends RecyclerView.Adapter<ListMessageAdapter.
|
|||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
preciseDate = false;
|
preciseDate = false;
|
||||||
dateTime = null;
|
dateTime = null;
|
||||||
|
enableCopyToClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchPreciseDate() {
|
void switchPreciseDate() {
|
||||||
@@ -157,6 +161,33 @@ public class ListMessageAdapter extends RecyclerView.Adapter<ListMessageAdapter.
|
|||||||
}
|
}
|
||||||
date.setText(text);
|
date.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableCopyToClipboard() {
|
||||||
|
super.itemView.setOnLongClickListener(
|
||||||
|
view -> {
|
||||||
|
ClipboardManager clipboard =
|
||||||
|
(ClipboardManager)
|
||||||
|
view.getContext()
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip =
|
||||||
|
ClipData.newPlainText(
|
||||||
|
"GotifyMessageContent", message.getText().toString());
|
||||||
|
|
||||||
|
if (clipboard != null) {
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast toast =
|
||||||
|
Toast.makeText(
|
||||||
|
view.getContext(),
|
||||||
|
view.getContext()
|
||||||
|
.getString(
|
||||||
|
R.string.message_copied_to_clipboard),
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Delete {
|
public interface Delete {
|
||||||
|
|||||||
@@ -74,4 +74,5 @@
|
|||||||
<string name="push_title_hint">Title</string>
|
<string name="push_title_hint">Title</string>
|
||||||
<string name="push_content_hint">Content</string>
|
<string name="push_content_hint">Content</string>
|
||||||
<string name="push_priority_hint">Priority</string>
|
<string name="push_priority_hint">Priority</string>
|
||||||
|
<string name="message_copied_to_clipboard">Content copied to clipboard</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user